<?php

function movie_review_hub_remove_customize_register() {
    global $wp_customize;
    $wp_customize->remove_section( 'film_maker_lite_social_media' );

    $wp_customize->remove_setting( 'film_maker_lite_slider_top_content' );
    $wp_customize->remove_control( 'film_maker_lite_slider_top_content' );

    $wp_customize->remove_setting( 'film_maker_lite_phone_number' );
    $wp_customize->remove_control( 'film_maker_lite_phone_number' );

    $wp_customize->remove_setting( 'film_maker_lite_book_ticket_button' );
    $wp_customize->remove_control( 'film_maker_lite_book_ticket_button' );

    $wp_customize->remove_setting( 'film_maker_lite_book_ticket_link' );
    $wp_customize->remove_control( 'film_maker_lite_book_ticket_link' );

    $wp_customize->remove_setting( 'film_maker_lite_phone_icon' );
    $wp_customize->remove_control( 'film_maker_lite_phone_icon' );

}
add_action( 'customize_register', 'movie_review_hub_remove_customize_register', 11 );

if ( ! defined( 'MOVIE_REVIEW_HUB_TEXT' ) ) {
    define( 'MOVIE_REVIEW_HUB_TEXT', __( 'Movie Review Hub Pro','movie-review-hub' ));
}
if ( ! defined( 'MOVIE_REVIEW_HUB_BUY_TEXT' ) ) {
    define( 'MOVIE_REVIEW_HUB_BUY_TEXT', __( 'Upgrade Pro','movie-review-hub' ));
}


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, 'movie_review_hub_pro', [
            'title'       => esc_html( MOVIE_REVIEW_HUB_TEXT,'movie-review-hub' ),
            'priority'    => 0,
            'button_text' => __( 'GET PREMIUM', 'movie-review-hub' ),
            'button_url'  => esc_url( FILM_MAKER_LITE_PRO_THEME_URL )
        ] )
    );

} );

function movie_review_hub_customize_register( $wp_customize ) {

    // Pro Version
    class movie_review_hub_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( MOVIE_REVIEW_HUB_BUY_TEXT,'movie-review-hub' ) .'<strong></a>';
            echo '</a>';
        }
    }

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

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

    $wp_customize->add_setting('movie_review_hub_more_videos_button',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('movie_review_hub_more_videos_button',array(
        'label' => esc_html__('Button Text ','movie-review-hub'),
        'section'   => 'film_maker_lite_topbar',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('movie_review_hub_more_videos_link',array(
        'default'   => '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('movie_review_hub_more_videos_link',array(
        'label' => esc_html__('Button URL','movie-review-hub'),
        'section'   => 'film_maker_lite_topbar',
        'type'      => 'url'
    ));

    // Post Section
    $wp_customize->add_section( 'movie_review_hub_movie_time_section' , array(
        'title'      => __( 'Latest Movies Settings', 'movie-review-hub' ),
        'priority' => 10,
        'panel' => 'film_maker_lite_panel_id'
    ) );

    $wp_customize->add_setting( 'film_maker_lite_latest_release_show_hide', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'film_maker_lite_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new Movie_Review_Hub_Toggle_Control( $wp_customize, 'film_maker_lite_latest_release_show_hide', array(
        'label'       => esc_html__( 'Show / Hide section', 'movie-review-hub' ),
        'section'     => 'movie_review_hub_movie_time_section',
        'type'        => 'toggle',
        'settings'    => 'film_maker_lite_latest_release_show_hide',
    ) ) );

    $wp_customize->add_setting( 'movie_review_hub_movie_time_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, 'movie_review_hub_movie_time_animation', array(
        'label'       => esc_html__( 'Show / Hide Section Animation', 'movie-review-hub' ),
        'section'     => 'movie_review_hub_movie_time_section',
        'type'        => 'toggle',
        'settings'    => 'movie_review_hub_movie_time_animation',
    ) ) );

    $wp_customize->add_setting('movie_review_hub_offer_section_tittle',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('movie_review_hub_offer_section_tittle',array(
        'label' => __('Section Title','movie-review-hub'),
        'section'   => 'movie_review_hub_movie_time_section',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('movie_review_hub_section_more_videos_button',array(
        'default'   => '',
        'sanitize_callback' => 'sanitize_text_field'
    ));
    $wp_customize->add_control('movie_review_hub_section_more_videos_button',array(
        'label' => esc_html__('Button Text ','movie-review-hub'),
        'section'   => 'movie_review_hub_movie_time_section',
        'type'      => 'text'
    ));

    $wp_customize->add_setting('movie_review_hub_section_more_videos_link',array(
        'default'   => '',
        'sanitize_callback' => 'esc_url_raw'
    ));
    $wp_customize->add_control('movie_review_hub_section_more_videos_link',array(
        'label' => esc_html__('Button URL','movie-review-hub'),
        'section'   => 'movie_review_hub_movie_time_section',
        'type'      => 'url'
    ));

    $categories = get_categories();
    $cats = array();
    $i = 0;
    $offer_cat[]= 'select';
    foreach($categories as $category){
        if($i==0){
            $default = $category->slug;
            $i++;
        }
        $offer_cat[$category->slug] = $category->name;
    }

    $wp_customize->add_setting('movie_review_hub_offer_section_category',array(
        'default'   => 'select',
        'sanitize_callback' => 'film_maker_lite_sanitize_choices',
    ));
    $wp_customize->add_control('movie_review_hub_offer_section_category',array(
        'type'    => 'select',
        'choices' => $offer_cat,
        'label' => __('Select Category','movie-review-hub'),
        'section' => 'movie_review_hub_movie_time_section',
    ));

    $wp_customize->add_setting( 'movie_review_hub_show_slider_content', array(
        'default'           => true,
        'transport'         => 'refresh',
        'sanitize_callback' => 'film_maker_lite_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new movie_review_hub_Toggle_Control( $wp_customize, 'movie_review_hub_show_slider_content', array(
        'label'       => esc_html__( 'Show / Hide Slider Content', 'movie-review-hub' ),
        'section'     => 'film_maker_lite_slider_section',
        'type'        => 'toggle',
        'settings'    => 'movie_review_hub_show_slider_content',
        'priority'    => 99,
    ) ) );

    // Pro Version
    $wp_customize->add_setting( 'movie_review_hub_services_pro_version_logo', array(
        'sanitize_callback' => 'movie_review_hub_sanitize_custom_control'
    ));
    $wp_customize->add_control( new movie_review_hub_Customize_Pro_Version ( $wp_customize,'movie_review_hub_services_pro_version_logo', array(
        'section'     => 'movie_review_hub_movie_time_section',
        'type'        => 'pro_options',
        'label'       => esc_html__( 'Features ', 'movie-review-hub' ),
        'description' => esc_url( FILM_MAKER_LITE_PRO_THEME_URL ),
        'priority'    => 10,
    )));

}
add_action( 'customize_register', 'movie_review_hub_customize_register' );
