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

/**
 * Frontpage Press Mentions Options
 *
 * @package pawfect
 */

if (!class_exists('Pawfect_Options_Press_Mentions')):

    class Pawfect_Options_Press_Mentions extends pawfect_Customize_Base_Option
    {

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

            return array(

                'pawfect_press_mention_heading' => array(
                    'setting' => array(),
                    'control' => array(
                        'type' => 'heading',
                        'priority' => 1,
                        'label' => esc_html__('Press Mentions Section', 'pawfect'),
                        'section' => 'pawfect_theme_press_mentions',
                    ),
                ),

                'pawfect_press_mentions_enabled' => array(
                    'setting' => array(
                        'default' => true,
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_checkbox'),
                    ),
                    'control' => array(
                        'type' => 'toggle',
                        'priority' => 2,
                        'label' => esc_html__('Disable Section', 'pawfect'),
                        'description' => esc_html__('Toggle ON to hide this section', 'pawfect'),
                        'section' => 'pawfect_theme_press_mentions',
                    ),
                ),

                'pawfect_press_mentions_count' => array(
                    'setting' => array(
                        'default' => 5,
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_range_value'),
                    ),
                    'control' => array(
                        'type' => 'pawfect-range-slider',
                        'priority' => 15,
                        'label' => esc_html__('Logo Count to Show', 'pawfect'),
                        'section' => 'pawfect_theme_press_mentions',
                        'input_attrs' => array(
                            'min' => 1,
                            'max' => 20,
                            'step' => 1,
                        ),
                        'active_callback' => 'pawfect_press_mentions_disabled',
                    ),
                ),

                'pawfect_press_mentions_logo_height' => array(
                    'setting' => array(
                        'default' => json_encode(array(
                            'desktop' => 32,
                            'tablet' => 28,
                            'mobile' => 24,
                        )),
                        'sanitize_callback' => array('Pawfect_Responsive_Range_Control', 'sanitize_responsive_range'),
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'pawfect-responsive-range',
                        'priority' => 20,
                        'section' => 'pawfect_theme_press_mentions',
                        'label' => esc_html__('Logo Size', 'pawfect'),
                        'description' => esc_html__('Set the logo size across different devices.', 'pawfect'),
                        'media_query' => true,
                        'suffix' => 'px',
                        'input_attrs' => array(
                            'min' => 20,
                            'max' => 200,
                            'step' => 1,
                        ),
                        'active_callback' => 'pawfect_press_mentions_disabled',
                    ),
                ),

                'pawfect_press_mentions_gap' => array(
                    'setting' => array(
                        'default' => json_encode(array(
                            'desktop' => 64,
                            'tablet' => 48,
                            'mobile' => 32,
                        )),
                        'sanitize_callback' => array('Pawfect_Responsive_Range_Control', 'sanitize_responsive_range'),
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'pawfect-responsive-range',
                        'priority' => 25,
                        'section' => 'pawfect_theme_press_mentions',
                        'label' => esc_html__('Logo Gap', 'pawfect'),
                        'description' => esc_html__('Space between logos across different devices.', 'pawfect'),
                        'media_query' => true,
                        'suffix' => 'px',
                        'input_attrs' => array(
                            'min' => 16,
                            'max' => 120,
                            'step' => 4,
                        ),
                        'active_callback' => 'pawfect_press_mentions_disabled',
                    ),
                ),

                'pawfect_press_mentions_background_color' => array(
                    'setting' => array(
                        'default' => '#313134',
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_alpha_color'),
                    ),
                    'control' => array(
                        'type' => 'color',
                        'label' => esc_html__('Background Color', 'pawfect'),
                        'section' => 'pawfect_theme_press_mentions',
                        'priority' => 42,
                        'choices' => array(
                            'alpha' => true,
                        ),
                        'active_callback' => 'pawfect_press_mentions_disabled',
                    ),
                ),

                'pawfect_press_mentions_content' => array(
                    'setting' => array(
                        'sanitize_callback' => 'pawfect_repeater_sanitize',
                        'default' => json_encode(array(
                            array(
                                'image_url' => get_template_directory_uri() . '/assets/images/brands/brand1.webp',
                                'title' => esc_html__('TechCrunch', 'pawfect'),
                                'link' => '#',
                                'open_new_tab' => 'yes',
                                'id' => 'customizer_repeater_press_001',
                            ),
                            array(
                                'image_url' => get_template_directory_uri() . '/assets/images/brands/brand2.webp',
                                'title' => esc_html__('Forbes', 'pawfect'),
                                'link' => '#',
                                'open_new_tab' => 'yes',
                                'id' => 'customizer_repeater_press_002',
                            ),
                            array(
                                'image_url' => get_template_directory_uri() . '/assets/images/brands/brand3.webp',
                                'title' => esc_html__('Wired', 'pawfect'),
                                'link' => '#',
                                'open_new_tab' => 'yes',
                                'id' => 'customizer_repeater_press_003',
                            ),
                        )),
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'repeater',
                        'label' => esc_html__('Press Mention Logos', 'pawfect'),
                        'section' => 'pawfect_theme_press_mentions',
                        'priority' => 10,
                        'add_field_label' => esc_html__('Add new logo', 'pawfect'),
                        'item_name' => esc_html__('Logo Item', 'pawfect'),
                        'customizer_repeater_image_control' => true,
                        'customizer_repeater_title_control' => true,
                        'customizer_repeater_link_control' => true,
                        'customizer_repeater_checkbox_control' => true,
                        'active_callback' => 'pawfect_press_mentions_disabled',
                    ),
                ),

                // Upgrade control for press mentions limitation
                'pawfect_press_mentions_content_upsale' => array(
                    'setting' => array(
                        'sanitize_callback' => 'sanitize_text_field',
                    ),
                    'control' => array(
                        'type' => 'pawfect-upgrade',
                        'priority' => 11,
                        'label' => esc_html__('Press Mentions Features', 'pawfect'),
                        'section' => 'pawfect_theme_press_mentions',
                        'active_callback' => 'pawfect_press_mentions_disabled',
                    ),
                ),
            );
        }
    }

    // Remove automatic instantiation - let main customizer class handle this
    // new Pawfect_Options_Press_Mentions();

endif;

/**
 * Check if press mentions section is enabled
 */

function pawfect_press_mentions_disabled($control)
{
    // Active when slider is enabled
    $enabled = get_theme_mod('pawfect_press_mentions_enabled', null);
    if ($enabled === null) {
        $enabled = ! get_theme_mod('pawfect_press_mentions_disabled', false);
    }
    return $enabled ? true : false;
}


