<?php

if ( ! defined( 'CINEMA_THEATER_TEXT' ) ) {
    define( 'CINEMA_THEATER_TEXT', __( 'Movie Studio Pro','cinema-theater' ));
}
if ( ! defined( 'CINEMA_THEATER_BUY_TEXT' ) ) {
    define( 'CINEMA_THEATER_BUY_TEXT', __( 'Upgrade Pro','cinema-theater' ));
}


add_action( 'customize_register', function( $manager ) {

// Load custom sections.
load_template( trailingslashit( get_template_directory() ) . '/inc/section-pro.php' );

    $manager->register_section_type( Film_Maker_Lite_Button::class );

    $manager->add_section(
        new Film_Maker_Lite_Button( $manager, 'cinema_theater_pro', [
            'title'       => esc_html( CINEMA_THEATER_TEXT,'cinema-theater' ),
            'priority'    => 0,
            'button_text' => __( 'GET PREMIUM', 'cinema-theater' ),
            'button_url'  => esc_url( FILM_MAKER_LITE_PRO_THEME_URL )
        ] )
    );

} );

function cinema_theater_customize_register( $wp_customize ) {

    // Pro Version
    class cinema_theater_Customize_Pro_Version extends WP_Customize_Control {
        public $type = 'pro_options';

        public function render_content() {
            echo '<span>Unlock Premium <strong>'. esc_html( $this->label ) .'</strong>? </span>';
            echo '<a href="'. esc_url($this->description) .'" target="_blank">';
                echo '<span class="dashicons dashicons-info"></span>';
                echo '<strong> '. esc_html( CINEMA_THEATER_BUY_TEXT,'cinema-theater' ) .'<strong></a>';
            echo '</a>';
        }
    }

    // Custom Controls
    function cinema_theater_sanitize_custom_control( $input ) {
        return $input;
    }

     // Register the custom control type.
    $wp_customize->register_control_type( 'Cinema_Theater_Toggle_Control' );


    $wp_customize->add_setting('film_maker_lite_email_address',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_email'
    ));
    $wp_customize->add_control('film_maker_lite_email_address',array(
        'label' => esc_html__('Add Email Address','cinema-theater'),
        'section'   => 'film_maker_lite_topbar',
        'type'      => 'text'
    ));

    // Film Category Section
    $wp_customize->add_section( 'cinema_theater_category_section' , array(
        'title'      => __( 'Featured Actor Section Settings', 'cinema-theater' ),
        'priority' => 10,
        'panel' => 'film_maker_lite_panel_id'
    ) );

    $wp_customize->add_setting( 'cinema_theater_featured_actors_enable', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'film_maker_lite_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new Cinema_Theater_Toggle_Control( $wp_customize, 'cinema_theater_featured_actors_enable', array(
        'label'       => esc_html__( 'Show / Hide section', 'cinema-theater' ),
        'section'     => 'cinema_theater_category_section',
        'type'        => 'toggle',
        'settings'    => 'cinema_theater_featured_actors_enable',
    ) ) );

    $wp_customize->add_setting( 'cinema_theater_featured_actors_sec_animation', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'film_maker_lite_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new film_maker_lite_Toggle_Control( $wp_customize, 'cinema_theater_featured_actors_sec_animation', array(
        'label'       => esc_html__( 'Show / Hide Section Animation', 'cinema-theater' ),
        'section'     => 'cinema_theater_category_section',
        'type'        => 'toggle',
        'settings'    => 'cinema_theater_featured_actors_sec_animation',
    ) ) );

    $wp_customize->add_setting('cinema_theater_featured_actors_heading',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('cinema_theater_featured_actors_heading',array(
        'label' => esc_html__('Section Title ','cinema-theater'),
        'section'   => 'cinema_theater_category_section',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('cinema_theater_featured_actors_sub_heading',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('cinema_theater_featured_actors_sub_heading',array(
        'label' => esc_html__('Section Text','cinema-theater'),
        'section'   => 'cinema_theater_category_section',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('cinema_theater_featured_actors_btn_text',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('cinema_theater_featured_actors_btn_text',array(
        'label' => esc_html__('Section Button Text','cinema-theater'),
        'section'   => 'cinema_theater_category_section',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('cinema_theater_featured_actors_btn_link',array(
        'default'   => '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('cinema_theater_featured_actors_btn_link',array(
        'label' => esc_html__('Section Button Link','cinema-theater'),
        'section'   => 'cinema_theater_category_section',
        'type'      => 'url'
    ));

    $film_maker_lite_categories = get_categories();
    $film_maker_lite_cats = array();
    $i = 0;
    $film_maker_lite_offer_cat[]= 'select';
    foreach($film_maker_lite_categories as $film_maker_lite_category){
        if($i==0){
            $default = $film_maker_lite_category->slug;
            $i++;
        }
        $film_maker_lite_offer_cat[$film_maker_lite_category->slug] = $film_maker_lite_category->name;
    }

    $wp_customize->add_setting('cinema_theater_featured_actors_section_category',array(
        'default'   => 'select',
        'sanitize_callback' => 'film_maker_lite_sanitize_choices',
    ));
    $wp_customize->add_control('cinema_theater_featured_actors_section_category',array(
        'type'    => 'select',
        'choices' => $film_maker_lite_offer_cat,
        'label' => __('Select Category','cinema-theater'),
        'section' => 'cinema_theater_category_section',
    ));

    $wp_customize->add_setting('film_maker_lite_tp_color_sec', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_hex_color'
    ));
    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'film_maker_lite_tp_color_sec', array(
        'label'       => __('Theme Second Color', 'film-maker-lite'),
        'description' => __('It will change the complete theme color in one click.', 'film-maker-lite'),
        'section'     => 'film_maker_lite_color_option',
        'settings'    => 'film_maker_lite_tp_color_sec',
    )));

    // Pro Version
    $wp_customize->add_setting( 'cinema_theater_services_pro_version_logo', array(
        'sanitize_callback' => 'cinema_theater_sanitize_custom_control'
    ));
    $wp_customize->add_control( new cinema_theater_Customize_Pro_Version ( $wp_customize,'cinema_theater_services_pro_version_logo', array(
        'section'     => 'cinema_theater_category_section',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'cinema-theater' ),
        'description' => esc_url( FILM_MAKER_LITE_PRO_THEME_URL ),
        'priority'    => 10,
    )));
}
add_action( 'customize_register', 'cinema_theater_customize_register' );
