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

global $campoal_options;
global $post;
global $current_user;

$citation_instant_add = isset($campoal_options['conikal_citation_instant_add_field']) ? $campoal_options['conikal_citation_instant_add_field'] : 'none';
$receive_update = isset($campoal_options['conikal_receive_update_field']) ? $campoal_options['conikal_receive_update_field'] : 'checked';
$sign_anonymous = isset($campoal_options['conikal_sign_anonymous_field']) ? $campoal_options['conikal_sign_anonymous_field'] : 'checked';
$fb_login = isset($campoal_options['conikal_fb_login_field']) ? $campoal_options['conikal_fb_login_field'] : 0;
$fb_app_id = isset($campoal_options['conikal_fb_id_field']) ? $campoal_options['conikal_fb_id_field'] : '';
$google_login = isset($campoal_options['conikal_google_login_field']) ? $campoal_options['conikal_google_login_field'] : 0;
$google_client_id = isset($campoal_options['conikal_google_id_field']) ? $campoal_options['conikal_google_id_field'] : '';

$facebook_connection = get_user_meta($current_user->ID, 'facebook_connection', true);
$google_connection = get_user_meta($current_user->ID, 'google_connection', true);
$account_activation = get_user_meta($current_user->ID, 'is_activated', true);

$decision_id = get_user_meta($current_user->ID, 'user_decision', true);
if ($decision_id) {
    $prefix = 'decisionmaker_';

    $decision_status        = get_post_status( $decision_id );
    $decision_title         = wp_get_post_terms( $decision_id, 'decisionmakers_title' );
    $decision_title         = ($decision_title ? $decision_title[0]->name : '');
    $decision_organization  = wp_get_post_terms($decision_id, 'decisionmakers_organization');
    $decision_organization  = ($decision_organization ? $decision_organization[0]->name : '');

    // get indentify
    $indentify_verified         = get_post_meta($decision_id, $prefix . 'indentify_verified', true);
    $indentify_type             = get_post_meta($decision_id, $prefix . 'indentify_type', true);
    $indentify_name             = get_post_meta($decision_id, $prefix . 'indentify_name', true);
    $indentify_id               = get_post_meta($decision_id, $prefix . 'indentify_id', true);
    $indentify_country_issue    = get_post_meta($decision_id, $prefix . 'indentify_country_issue', true);
    $indentify_frontside_photo  = get_post_meta($decision_id, $prefix . 'indentify_frontside_photo', true);
    $indentify_backside_photo   = get_post_meta($decision_id, $prefix . 'indentify_backside_photo', true);
    $indentify_other_photo      = get_post_meta($decision_id, $prefix . 'indentify_other_photo', true);
} else {
    $decision_status        = '';
    $decision_title         = '';
    $decision_organization  = '';
}

$decision_title_option = get_terms( 'decisionmakers_title', array(
    'hide_empty' => false,
) );

$indentify_types = array(
    'national_id'    => esc_html__( 'National ID', 'campoal' ),
    'driver_license' => esc_html__( 'Driver\'s license', 'campoal' ),
    'passport'       => esc_html__( 'Passport', 'campoal' ),
);

$tab = isset($_GET['tab']) ? $_GET['tab'] : 'profile';
$upload_tab = isset($_GET['upload']) ? $_GET['upload'] : 'front';

// get location of user by GeoIp
$geoip_info = function_exists('conikal_client_geoip_info') ? conikal_client_geoip_info() : false;
?>

<?php if ($indentify_verified) : ?>
    <div class="ui icon success message">
        <i class="check circle icon"></i>
            <div class="content">
                <div class="header">
                <?php esc_html_e('Your decision maker\'s account has been verified!', 'campoal') ?>
                </div>
            <?php esc_html_e('We have verified your submited identity documents. A verified badge will appear on your avatar.', 'campoal') ?>
        </div>
    </div>
<?php endif; ?>
<form class="ui form" id="indentifyForm">
    <div class="field required">
        <label><?php esc_html_e('Type of identification', 'campoal') ?></label>
        <select name="indentify_type" class="ui dropdown">
            <?php foreach ($indentify_types as $key => $text) { ?>
            <option value="<?php echo esc_attr($key) ?>"<?php echo esc_attr($indentify_type == $key ? ' selected' : '') ?>>
                <?php echo esc_html($text) ?>
            </option>
            <?php } ?>
        </select>
    </div>
    <div class="field required">
        <label><?php esc_html_e('Legal name', 'campoal'); ?></label>
        <div class="ui large right icon input">
            <i class="user icon"></i>
            <input type="text" id="indentify_name" name="indentify_name" value="<?php echo esc_attr($indentify_name ? $indentify_name : '') ?>" placeholder="<?php esc_attr_e('Enter a legal name', 'campoal'); ?>">
        </div>
    </div>
    <div class="field required">
        <label><?php esc_html_e('Indentify ID', 'campoal'); ?></label>
        <div class="ui large right icon input">
            <i class="barcode icon"></i>
            <input type="text" id="indentify_id" value="<?php echo esc_attr($indentify_id ? $indentify_id : '') ?>" name="indentify_id" placeholder="<?php esc_attr_e('Enter a indentify ID', 'campoal'); ?>">
        </div>
    </div>
    <div class="field required">
        <label><?php esc_html_e('Country issued', 'campoal') ?></label>
        <div class="ui fluid large search selection dropdown country-search">
            <input type="hidden" name="indentify_country_issue" value="<?php echo esc_attr($indentify_country_issue ? $indentify_country_issue : '') ?>" id="indentify_country_issue" value="<?php echo esc_attr(!empty($up_country) ? $up_country : ($geoip_info ? $geoip_info->country->isoCode : '')); ?>">
            <i class="dropdown icon"></i>
            <div class="default text"><?php esc_html_e('Select country', 'campoal') ?></div>
            <div class="menu">
                <?php echo conikal_country_list_menu_html() ?>
            </div>
        </div>
    </div>
    <div class="ui secondary menu">
        <a href="<?php echo add_query_arg( array_merge($_GET, array('upload' => 'front')), home_url( $wp->request ) ); ?>" class="item<?php echo esc_attr($upload_tab == 'front' ? ' active' : '') ?>"><?php esc_html_e('Front-side', 'campoal') ?></a>
        <a href="<?php echo add_query_arg( array_merge($_GET, array('upload' => 'back')), home_url( $wp->request ) ); ?>" class="item<?php echo esc_attr($upload_tab == 'back' ? ' active' : '') ?>"><?php esc_html_e('Back-side', 'campoal') ?></a>
        <a href="<?php echo add_query_arg( array_merge($_GET, array('upload' => 'other')), home_url( $wp->request ) ); ?>" class="item<?php echo esc_attr($upload_tab == 'other' ? ' active' : '') ?>"><?php esc_html_e('Your face photo', 'campoal') ?></a>
    </div>
    <?php get_template_part('templates/indentify-upload'); ?>
    <div class="ui basic vertical right aligned segment">
        <a href="javascript:void(0);" class="ui right large primary button updateIndentifyBtn" upload-action="0"><?php esc_html_e('Save Identification', 'campoal'); ?></a>
    </div>
</form>