<?php
/**
 * @package WordPress
 * @subpackage Campoal
 */

global $post;
global $campoal_options;

$editor_style = isset($campoal_options['conikal_editor_style_field']) ? $campoal_options['conikal_editor_style_field'] : 'markdown';
$p_media_upload = isset($campoal_options['conikal_p_media_upload_field']) ? $campoal_options['conikal_p_media_upload_field'] : 1;

$citation_button_text = isset($campoal_options['conikal_citation_button_text_field']) ? $campoal_options['conikal_citation_button_text_field'] : __('Send Citation', 'campoal');
$link_preview_placeholder = conikal_lazy_load_placeholder('link-preview-placeholder');

$post_type = get_post_type($post->ID);
if ($post_type != 'petition') {
  $petition_id = get_post_meta($post->ID, $post_type . '_post_id', true);
} else {
  $petition_id = $post->ID;
} ?>

<!-- SIGN IN AND SIGN UP MODAL -->
<div class="ui small modal" id="citationModal" data-id="<?php echo esc_attr($petition_id) ?>">
    <i class="close icon"></i>
    <div class="header">
        <div class="ui right floated header opinion-labels">
        	<span class="ui small label citation-label-yes" id="opinion-selected-yes"><?php esc_html_e('Agree', 'campoal') ?></span>
        	<span class="ui small label citation-label-no display none" id="opinion-selected-no"><?php esc_html_e('Disagree', 'campoal') ?></span>
        </div>
        <?php esc_html_e('Add Citation', 'campoal') ?>
    </div>
    <div class="content">
        <div id="citation-response" class="respon-message"></div>
    	<form class="ui form citation-form" id="citation-form<?php echo esc_attr($petition_id) ?>">
            <div class="field">
                <label><?php esc_html_e('Reference link', 'campoal') ?></label>
                <div class="ui large fluid right icon input">
                    <input type="url" id="citation_reference" name="citation_reference" placeholder="<?php esc_attr_e('Enter reference link', 'campoal') ?>">
                    <i class="linkify icon"></i>
                </div>
            </div>
            <div class="field display none" id="citation-link-preview">
                <div class="ui secondary loading segment">
                    <img src="<?php echo esc_url($link_preview_placeholder) ?>">
                </div>
            </div>           
        	<div class="field required">
        		<label><?php esc_html_e('Citation title', 'campoal') ?></label>
        		<div class="ui large fluid icon input">
        			<input type="url" id="citation_title" name="citation_title" placeholder="<?php esc_attr_e('Enter citation title', 'campoal') ?>">
        		</div>
        	</div>
           	<div class="field required">
                <label><?php esc_html_e('Citation content', 'campoal') ?></label>
                <div id="isDesc">
                <?php 
                $html_content = '';
                if ($editor_style == 'classic') {
                    $settings = array(
                        'media_buttons'         => false,
                        'textarea_rows'         => 10,
                        'drag_drop_upload'      => true,
                        'quicktags'             => false,
                        'dfw'                   => true,
                        'editor_height'         => '300px',
                        );
                    wp_editor($html_content, 'citation_content', $settings);
                } else { ?>
                    <textarea id="citation_content" name="citation_content"><?php echo esc_textarea($html_content) ?></textarea>
                <?php } ?>
                </div>
            </div>
            <input type="hidden" id="citation_id" name="citation_id" value="">
            <input type="hidden" id="graph_title" name="graph_title">
            <input type="hidden" id="graph_description" name="graph_description">
            <input type="hidden" id="graph_image" name="graph_image">
            <input type="hidden" id="graph_site" name="graph_site">
        	<div class="field">
        		<a href="javascript:void(0);" class="ui fluid primary big button submitCitation" data-id="<?php echo esc_attr($petition_id) ?>" data-redirection="0"><?php echo conikal_custom_icon('citation') ?><?php echo esc_html($citation_button_text != '' ? $citation_button_text : __('Send Citation', 'campoal')) ?></a>
        	</div>
        </form>
        <?php wp_nonce_field('citation_ajax_nonce', 'securityCitation', true); ?>
        <?php wp_nonce_field('opengraph_ajax_nonce', 'securityOpenGraph', true); ?>
    </div>
</div>