<?php
///////////////// REGISTRO DE LOS CAMPOS POR EL ESCRITOR ///////////////
////////////////////////////////////////////////////////////////////////
use Carbon_Fields\Container;
use Carbon_Fields\Field;
global $wpdb;
$arr_barajas = [];
$q_barajas = $wpdb->get_results(
    $wpdb->prepare("
   ( SELECT * FROM (
       SELECT {$wpdb->terms}.term_id, {$wpdb->terms}.name
       FROM {$wpdb->terms}
       JOIN {$wpdb->term_taxonomy}
       ON {$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id
       WHERE taxonomy = %s
   ) as T
   );
   ",
   'tarokkina_free-cat'
   )
);

foreach ($q_barajas as $baraja) {
$arr_barajas [$baraja->term_id] = $baraja->name;
}
$text_default = 'Sobrescribir Texto';

if (get_option('tarokki_install_free') == 'yes') {

    $freeinstall = '';
    $Freeclose = '<div class="modalContainer"><div style="background: #4DA69B" class="modal_save"><img  style="width:265px" src="'.esc_url(plugin_dir_url(dirname( __DIR__ ) )).'img/tarokina-free.png" alt="tarokina-free"><button id="Freeclose" name="Freeclose" value="yes" type="submit" class="button btn_close">'.esc_html__('close', 'tarokina-free').'</button><img class="spinnerClass" id="spinner_free" style="display:none" src="'.esc_url(plugin_dir_url(dirname( __DIR__ ) )).'img/spinner-2x.gif" alt="spinner"></div></div>';

}else{  
    
    $freeinstall = '<button id="freeinstall" name="freeinstall" value="yes" type="submit" class="button button-primary">'.esc_html__('Install', 'tarokina-free').'</button><div class="bloqFlec"><svg id="arrowF" width="30px" xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
    <path fill-rule="evenodd" d="M7.707 14.707a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 1.414L5.414 9H17a1 1 0 110 2H5.414l2.293 2.293a1 1 0 010 1.414z" clip-rule="evenodd" />
  </svg></div><img class="spinnerClass" id="spinner_free" style="display:none" src="'.esc_url(plugin_dir_url(dirname( __DIR__ ) )).'img/spinner-2x.gif" alt="spinner">';
    $Freeclose = '';
}

if ( !in_array('Tarot Free deck', $arr_barajas) || get_option('tarokki_install_free') == 'yes') {
    $FreeOn = 0;
    update_option( 'tarokki_install_free', '');
 }else{
     $FreeOn = 1;
 }

Container::make( 'theme_options', 'tarot_free', tkna_get_menu_text_free() )
->set_page_parent( 'edit.php?post_type=tarokkina_free' )
    ->add_tab( __( 'Tarot', 'tarokina-free' ), array(
        Field::make( 'html', 'tarokki_cabecera_text_tarots' )
        ->set_html( '<div class="titleFormsBloq"><div class="titleForms">'.esc_html__( 'Tarot list','tarokina-free' ).'</div><span class="dashicons dashicons-arrow-down-alt2"></span></div>')->set_classes( 'freeCab' ),
        Field::make( 'html', 'tkna_freeinstall')->set_html('<div id="instFree"><img class="chiFree" src="'.esc_url(plugin_dir_url(dirname( __DIR__ ) )).'img/tarokina-free.png" alt="Tarokina Free"><div class="insttext"><h2>Tarokina Free</h2><p>'. esc_html__('This free version allows you to create a Tarot card reading. Click on the install button to create the tarot_free shortcode. Once the installation is complete, you can edit the 22 cards and add an image and text to each card.', 'tarokina-free').'</p>&nbsp;&nbsp;&nbsp; '.$freeinstall.$Freeclose.'</div></div>')->set_classes( 'bloq_freeinstall freeinstall_'.$FreeOn.''),
        Field::make( 'complex', 'tarokki_free_complex', '' )
        ->set_max('1')
        ->setup_labels(array( 'plural_name' => 'tarots',
        'singular_name' => 'tarot',))

->add_fields( 'tarokina-free','Tarokina', array(
    Field::make( 'hidden', 'tkta_free_id', '' )->set_default_value('88888888'),
    Field::make( 'hidden', 'tkta_free_name', ''),
    Field::make( 'html', 'tkta_free_shortcode' )->set_html( '<div class="titleShort">'.esc_html__('Shortcode', 'tarokina-free').'&nbsp;<span class="dashicons dashicons-shortcode"></span>&nbsp;</div><input type="text" class="cf-field__body short" value="[tarot name=&quot;tarot_free&quot;]" readonly="">' )->set_help_text( esc_html__('Paste this shortcode in a wordpress page to activate this tarot.', 'tarokina-free') )->set_classes( 'freeField lisoEstilos lisoEstilos_ab' ),
    Field::make( 'radio', 'tkta_free_barajas', esc_html__( 'Deck','tarokina-free' ) )
    ->set_options($arr_barajas)->set_help_text(esc_html__('Select a deck. Visit the cards in this deck to create the texts', 'tarokina-free'))->set_classes( 'blo lisoEstilos lisoEstilos_ab tarokki_barajas' ),
    Field::make( 'radio', 'tkta_free_mode', esc_html__( 'Select mode','tarokina-free' ) )->set_help_text( esc_html__('Select a mode.', 'tarokina-free'))->set_classes( 'blo lisoEstilos lisoEstilos_ab ' )
        ->add_options( array(
            'basic' => esc_html__( 'Basic', 'tarokina-free' ),
            'flip' => esc_html__( 'Basic reversed', 'tarokina-free' ),
            'expert' => esc_html__( 'Expert', 'tarokina-free' ),
            'eflip' => esc_html__( 'Expert reversed', 'tarokina-free' ),
    )),
    Field::make( 'radio', 'tkta_free_tablero', esc_html__( 'Card Selector','tarokina-free' ) )->set_help_text( esc_html__('Ways to choose the cards during a consultation.','tarokina-free'))->set_classes( 'blo colorA lisoEstilos tarokki_mode tabl' )
    ->add_options( array(
        'd1' => 'Classic Grid',
        'd2' => 'Horizontal Shuffle',
        'd3' => esc_html__( 'Click on the spread cards', 'tarokina-free' )
    )),
    Field::make( 'radio', 'tkta_free_start', esc_html__( 'Start','tarokina-free' ) )->set_help_text(esc_html__('Display a button or the card selector','tarokina-free'))->set_classes( 'freeField colorA lisoEstilos lisoEstilos_b' )->set_default_value('selector')
    ->add_options( array(
        'btn' => esc_html__( 'Push start button', 'tarokina-free' ),
        'selector' => esc_html__( 'Show the card selector', 'tarokina-free' )
    )),
    Field::make( 'html', 'tkta_free_information_text_2' )->set_html( '<div class="title_inside">'.esc_html__('SPREADS (DESIGNS) TAROKINA', 'tarokina-free').'</div>' )->set_classes( 'title_inside' ),
    Field::make( 'radio_image', 'tkta_free_spread', esc_html__( 'Spreads','tarokina-free' ) )
    ->set_options( array(
        '1cards' => plugin_dir_url(dirname( __DIR__ ) ).'img/spreads/1cards.svg',
        '0cards' => plugin_dir_url(dirname( __DIR__ ) ).'img/spreads/0cards.svg',
        '3cards' => plugin_dir_url(dirname( __DIR__ ) ).'img/spreads/3cards.svg',
        '4cards' => plugin_dir_url(dirname( __DIR__ ) ).'img/spreads/4cards.svg',
        '5cards' => plugin_dir_url(dirname( __DIR__ ) ).'img/spreads/5cards.svg',
        '6cards' => plugin_dir_url(dirname( __DIR__ ) ).'img/spreads/6cards.svg',
        '7cards' => plugin_dir_url(dirname( __DIR__ ) ).'img/spreads/7cards.svg',
        '8cards' => plugin_dir_url(dirname( __DIR__ ) ).'img/spreads/8cards.svg',
        '9cards' => plugin_dir_url(dirname( __DIR__ ) ).'img/spreads/9cards.svg',
        '10cards' => plugin_dir_url(dirname( __DIR__ ) ).'img/spreads/10cards.svg',
        ) )->set_classes( 'blo lisoEstilos lisoEstilos_a' ),
    Field::make( 'radio', 'tkta_sizecards', esc_html__( 'Card size','tarokina-pro' ) )->set_help_text( esc_html__('You can Increase the size of the cards. Specific sizes depend on the selected spread.','tarokina-pro') )->set_classes( 'blo lisoEstilos' )
            ->add_options( array(
                's' => esc_html__( 'Small', 'tarokina-pro' ),
                'm' => esc_html__( 'Medium', 'tarokina-pro' ),
                'l' => esc_html__( 'Big', 'tarokina-pro' )
            )),
    Field::make( 'media_gallery', 'tkta_free_image_backface', esc_html__( 'Back of the card','tarokina-free' ))->set_type( array( 'image' ))->set_help_text( esc_html__('Tarot Card Back.','tarokina-free') )->set_classes( 'blo colorB lisoEstilos backface' ),
    Field::make( 'radio', 'tkta_result_tabs', esc_html__( 'Tarot card reading result','tarokina-free' ) )->set_help_text(esc_html__('Opening or closing the tabs on the result.','tarokina-free'))->set_classes( 'freeField colorA lisoEstilos' )
    ->add_options( array(
        'one' => esc_html__( 'First tab opened', 'tarokina-free' ),
        'none' => esc_html__( 'All tabs closed', 'tarokina-free' ),
        'all' => esc_html__( 'All tabs open', 'tarokina-free' )
    )),
    Field::make( 'radio', 'tkta_button_position', esc_html__( 'Start button','tarokina-free' ) )->set_help_text(esc_html__('Position the start button before or after the references.','tarokina-free'))->add_options( array(
        esc_html__( 'Above the references', 'tarokina-free' ),
        esc_html__( 'Below the references', 'tarokina-free' ),
     ))->set_classes( 'blo colorA lisoEstilos lisoEstilos_b' )->set_default_value('1'),
    Field::make( 'checkbox', 'tkta_free_meanings', esc_html__('Show References','tarokina-free')  )->set_default_value('')->set_classes('blo colorC tabs_color lisoEstilos lisoEstilos_a'),
    Field::make( 'text', 'tkta_free_1st', esc_html__('1st card:', 'tarokina-free') )->set_help_text( esc_html__('Example: Past','tarokina-free') )->set_default_value( esc_html__('Past','tarokina-free'))->set_classes( 'blo lisoEstilos' ),
    Field::make( 'text', 'tkta_free_2st', esc_html__('2nd card:', 'tarokina-free') )->set_help_text( esc_html__('Example: Present','tarokina-free') )->set_default_value( esc_html__('Present','tarokina-free'))->set_classes( 'blo lisoEstilos' ),
    Field::make( 'text', 'tkta_free_3st', esc_html__('3rd card:', 'tarokina-free') )->set_help_text( esc_html__('Example: Future','tarokina-free'))->set_default_value( esc_html__('Future','tarokina-free'))->set_classes( 'blo lisoEstilos lisoEstilos_b' ),
    Field::make( 'html', 'tkta_free_style' )->set_html( '
    <div style="color:#545656" class="title_inside stile"><span class="dashicons dashicons-edit"></span>'.esc_html__('Change texts','tarokina-free').'</div>
    ' )->set_classes( 'title_inside_estilos' ),
    Field::make( 'text', 'tkta_free_title_spread', esc_html__('Title', 'tarokina-free'))->set_default_value( esc_html__('Tarot title','tarokina-free'))->set_attribute( 'placeholder', '...')->set_help_text( esc_html__('You can leave this field empty to disable it','tarokina-free') )->set_classes( 'freeField colorA lisoEstilos lisoEstilos_a' ),
    Field::make( 'text', 'tkta_free_subtitle_spread', esc_html__('Subtitle', 'tarokina-free'))->set_default_value( esc_html__('subtitle','tarokina-free'))->set_attribute( 'placeholder', '...')->set_help_text( esc_html__('You can leave this field empty to disable it','tarokina-free') )->set_classes( 'freeField colorA lisoEstilos lisoEstilos' ),
    Field::make( 'text', 'tkta_free_text_top_deck2', esc_html__('Informational Text - Final card', 'tarokina-free'))->set_attribute( 'placeholder', '...')->set_help_text( esc_html__('You can leave this field empty to disable it','tarokina-free') )->set_classes( 'freeField colorA lisoEstilos lisoEstilos' ),
    Field::make( 'text', 'tkta_free_text_button', esc_html__('Start button text', 'tarokina-free'))->set_attribute( 'placeholder', '...')->set_default_value( esc_html__( 'Click to start your reading', 'tarokina-free' ) )->set_help_text(esc_html__( "Change the button's text", 'tarokina-free' ) )->set_classes( 'freeField colorB lisoEstilos lisoEstilos' ),
    Field::make( 'text', 'tkta_free_text_button_volver', esc_html__('Get a new‌ reading text button', 'tarokina-free'))->set_attribute( 'placeholder', '...')->set_default_value( __( 'New reading', 'tarokina-free' ) )->set_help_text( esc_html__( "Change the button's text", 'tarokina-free' ) )->set_classes( 'freeField colorA lisoEstilos lisoEstilos_b' ),
    Field::make( 'html', 'tkta_style' )->set_html( '<div style="color:#545656" class="title_inside stile"><span class="dashicons dashicons-admin-appearance"></span> '.esc_html__('Appearance','tarokina-free').'</div>' )->set_classes( 'title_inside_estilos' ),
    Field::make( 'color', 'tkta_free_title_spread_color', esc_html__('Tarot color', 'tarokina-free') )
    ->set_classes( 'freeField colorB colorTitle lisoEstilos lisoEstilos_a' ),
    Field::make( 'color', 'tkta_free_texto_spread_color', esc_html__('Button Text Color', 'tarokina-free') )
    ->set_classes( 'colorB lisoEstilos lisoEstilos_b' ),
    Field::make( 'color', 'tkta_free_background_color', esc_html__('Background Color', 'tarokina-free') )
    ->set_classes( 'blo colorC lisoEstilos lisoEstilos_a' ),
    Field::make( 'media_gallery', 'tkta_free_image_background', esc_html__( 'Background image','tarokina-free' ) )->set_default_value('')->set_type('image')->set_classes( 'blo colorD lisoEstilos' ),
    Field::make( 'text', 'tkta_free_image_transparent', esc_html__( 'Mix - Color Overlay','tarokina-free' ) )->set_help_text( esc_html__('Mix between image and background-color','tarokina-free'))->set_attribute( 'type', 'range' )->set_default_value(1)->set_classes( 'blo colorD lisoEstilos lisoEstilos_b range' ),
   ) )->set_classes( 'bloq_del_tarots ' )->set_header_template('<% if (tkta_free_name) { %><%- tkta_free_name %><% } %>'),
   Field::make( 'html', 'tkta_free_add_tarot' )->set_html( '<span class="dashicons dashicons-lock"></span>&nbsp;<button id="del_tarots" class="button button-primary">'.esc_html__('Add tarot', 'tarokina-free').'</button>')->set_classes( 'blo btnAdd'),
   Field::make( 'checkbox', 'tkna_free_unistall', esc_html__('Unistall Tarokina Free','tarokina-free')  )->set_classes('tabs_color bor'),
   Field::make( 'html', 'tkta_free_text_unistall' )->set_html( '
    <span class="text_unistall">'.esc_html__('Check this if you would like to remove ALL Tarokina Free data upon plugin deletion.','tarokina-free') .'</span>
    ')->set_conditional_logic( array(
        array(
            'field' => 'tkna_free_unistall',
            'value' => true,
        )
    ) ),
    Field::make( 'checkbox', 'tkna_free_http_ssl', esc_html__('Force SSL on images','tarokina-pro') )->set_help_text( esc_html__( 'Enabling this option will force all images to load with https.', 'tarokina-free' ))->set_classes('tabs_color bor'),
));