<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * Frontpage Mission Options
 *
 * @package pawfect
 */

if ( ! class_exists( 'Pawfect_Options_Mission' ) ) :

    class Pawfect_Options_Mission extends pawfect_Customize_Base_Option {

        /**
         * Arguments for options.
         *
         * @return array
         */
        public function elements() {

            return array(

                'pawfect_mission_heading' => array(
                    'setting' => array(),
                    'control' => array(
                        'type' => 'heading',
                        'priority' => 1,
                        'label' => esc_html__( 'Mission Section Options', 'pawfect' ),
                        'section' => 'pawfect_mission_section',
                    ),
                ),
                
                'pawfect_mission_enabled' => array(
                    'setting' => array(
                        'default' => true,
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_checkbox' ),
                    ),
                    'control' => array(
                        'type' => 'toggle',
                        'priority' => 2,
                        'label' => esc_html__( 'Disable Mission Section', 'pawfect' ),
                        'description' => esc_html__('Toggle ON to hide this section', 'pawfect'),
                        'section' => 'pawfect_mission_section',
                    ),
                ),

                'pawfect_mission_title' => array(
                    'setting' => array(
                        'default' => esc_html__( 'Made with & Purpose', 'pawfect' ),
                        'sanitize_callback' => 'sanitize_text_field'
                    ),
                    'control' => array(
                        'type' => 'text',
                        'priority' => 3,
                        'label' => esc_html__( 'Title', 'pawfect' ),
                        'section' => 'pawfect_mission_section',
                        'active_callback' => array(
                            array( $this, 'is_control_value_active' ),
                            'pawfect_mission_enabled',
                            true
                        ),
                    ),
                ),

                'pawfect_mission_desc' => array(
                    'setting' => array(
                        'default' => esc_html__( 'Every Pawfect product is ethically crafted for pets & planet.', 'pawfect' ),
                        'sanitize_callback' => 'sanitize_textarea_field'
                    ),
                    'control' => array(
                        'type' => 'textarea',
                        'priority' => 4,
                        'label' => esc_html__( 'Description', 'pawfect' ),
                        'section' => 'pawfect_mission_section',
                        'active_callback' => array(
                            array( $this, 'is_control_value_active' ),
                            'pawfect_mission_enabled',
                            true
                        ),
                    ),
                ),

                'pawfect_mission_button_text' => array(
                    'setting' => array(
                        'default' => esc_html__( 'Learn About Our Ethics', 'pawfect' ),
                        'sanitize_callback' => 'sanitize_text_field'
                    ),
                    'control' => array(
                        'type' => 'text',
                        'priority' => 5,
                        'label' => esc_html__( 'Button Text', 'pawfect' ),
                        'section' => 'pawfect_mission_section',
                        'active_callback' => array(
                            array( $this, 'is_control_value_active' ),
                            'pawfect_mission_enabled',
                            true
                        ),
                    ),
                ),

                'pawfect_mission_button_link' => array(
                    'setting' => array(
                        'default' => '#',
                        'sanitize_callback' => 'esc_url_raw'
                    ),
                    'control' => array(
                        'type' => 'url',
                        'priority' => 6,
                        'label' => esc_html__( 'Button Link', 'pawfect' ),
                        'section' => 'pawfect_mission_section',
                        'active_callback' => array(
                            array( $this, 'is_control_value_active' ),
                            'pawfect_mission_enabled',
                            true
                        ),
                    ),
                ),

                'pawfect_mission_button_target' => array(
                    'setting' => array(
                        'default' => '_self',
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_radio'),
                    ),
                    'control' => array(
                        'type' => 'radio-switch',
                        'priority' => 7,
                        'label' => esc_html__('Button Link Target', 'pawfect'),
                        'section' => 'pawfect_mission_section',
                        'choices' => array(
                            '_self' => esc_html__('Same Tab', 'pawfect'),
                            '_blank' => esc_html__('New Tab', 'pawfect'),
                        ),
                        'active_callback' => array(
                            array( $this, 'is_control_value_active' ),
                            'pawfect_mission_enabled',
                            true
                        ),
                    ),
                ),

                'pawfect_mission_width' => array(
                    'setting' => array(
                        'default' => 'pawfect-container-full',
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_radio' ),
                    ),
                    'control' => array(
                        'type' => 'radio-switch',
                        'priority' => 7,
                        'label' => esc_html__( 'Container Width', 'pawfect' ),
                        'section' => 'pawfect_mission_section',
                        'choices' => array(
                            'pawfect-container-small' => esc_html__( 'Small Container', 'pawfect' ),
                            'pawfect-container' => esc_html__( 'Standard Container', 'pawfect' ),
                            'pawfect-container-full' => esc_html__( 'Full Width Container', 'pawfect' ),
                        ),
                        'active_callback' => array(
                            array( $this, 'is_control_value_active' ),
                            'pawfect_mission_enabled',
                            true
                        ),
                    ),
                ),

                'pawfect_mission_background_type' => array(
                    'setting' => array(
                        'default' => 'image',
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_radio' ),
                    ),
                    'control' => array(
                        'type' => 'select',
                        'is_default_type' => true,
                        'priority' => 8,
                        'label' => esc_html__( 'Background Type', 'pawfect' ),
                        'section' => 'pawfect_mission_section',
                        'choices' => array(
                            'color' => esc_html__( 'Color', 'pawfect' ),
                            'image' => esc_html__( 'Image', 'pawfect' ),
                            'video' => esc_html__( 'Video', 'pawfect' )
                        ),
                        'active_callback' => array(
                            array( $this, 'is_control_value_active' ),
                            'pawfect_mission_enabled',
                            true
                        ),
                    ),
                ),

                'pawfect_mission_background_color' => array(
                    'setting' => array(
                        'default' => '#1a202c',
                        'sanitize_callback' => 'sanitize_hex_color'
                    ),
                    'control' => array(
                        'type' => 'color',
                        'priority' => 9,
                        'label' => esc_html__( 'Background Color', 'pawfect' ),
                        'section' => 'pawfect_mission_section',
                        'active_callback' => 'pawfect_mission_background_color_active',
                    ),
                ),

                'pawfect_mission_background_image' => array(
                    'setting' => array(
                        'default' => PAWFECT_THEME_URL . '/assets/images/shop-now3.webp',
                        'sanitize_callback' => 'esc_url_raw'
                    ),
                    'control' => array(
                        'type' => 'image',
                        'priority' => 10,
                        'label' => esc_html__( 'Background Image', 'pawfect' ),
                        'section' => 'pawfect_mission_section',
                        'active_callback' => 'pawfect_mission_background_image_active',
                    ),
                ),

                'pawfect_mission_video_url' => array(
                    'setting' => array(
                        'default' => '',
                        'sanitize_callback' => 'esc_url_raw'
                    ),
                    'control' => array(
                        'type' => 'url',
                        'priority' => 11,
                        'label' => esc_html__( 'Background Video URL', 'pawfect' ),
                        'section' => 'pawfect_mission_section',
                        'active_callback' => 'pawfect_mission_background_video_active',
                    ),
                ),

            );
        }

        /**
         * Check if a control value is active
         */
        public function is_control_value_active($setting_id, $expected_value)
        {
            return get_theme_mod($setting_id, true) === $expected_value;
        }

        /**
         * Check if background type is active
         */
        public function is_background_type_active($background_type)
        {
            return get_theme_mod('pawfect_mission_enabled', true) === true &&
                   get_theme_mod('pawfect_mission_background_type', 'video') === $background_type;
        }
    }

    new Pawfect_Options_Mission();

endif;

/**
 * Active callback functions for mission section
 */
function pawfect_mission_background_color_active($control) {
    return get_theme_mod('pawfect_mission_enabled', true) === true &&
           get_theme_mod('pawfect_mission_background_type', 'video') === 'color';
}

function pawfect_mission_background_image_active($control) {
    return get_theme_mod('pawfect_mission_enabled', true) === true &&
           get_theme_mod('pawfect_mission_background_type', 'video') === 'image';
}

function pawfect_mission_background_video_active($control) {
    return get_theme_mod('pawfect_mission_enabled', true) === true &&
           get_theme_mod('pawfect_mission_background_type', 'video') === 'video';
}


