<?php
/**
 * Promotional Popup Customizer Options
 *
 * @package Pawfect
 * @since 1.0.0
 */

// Exit if accessed directly.
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Class Pawfect_Options_Popup
 * 
 * Handles promotional popup customizer settings
 */
class Pawfect_Options_Popup
{
    /**
     * Add customizer options
     *
     * @param WP_Customize_Manager $wp_customize
     */
    public function pawfect_customizer_options($wp_customize)
    {
        /**
         * Panel: Promotional Popup
         */
        $wp_customize->add_panel('pawfect_popup_settings', array(
            'priority' => 25,
            'title' => esc_html__('Promotional Popup (Pro)', 'pawfect'),
            'capability' => 'edit_theme_options',
            'description' => esc_html__('Collect emails and generate leads using the Premium Promotional Popup.', 'pawfect'),
        ));

        /**
         * Section: Upsell
         */
        $wp_customize->add_section('pawfect_popup_upsell_section', array(
            'title' => esc_html__('Upgrade to Pawfect Pro', 'pawfect'),
            'panel' => 'pawfect_popup_settings',
            'priority' => 10,
        ));

        // Add a simple disabled text control as an upsell message
        $wp_customize->add_setting('pawfect_popup_upsell', array(
            'default' => esc_html__('Available in Pawfect Pro', 'pawfect'),
            'sanitize_callback' => 'sanitize_text_field',
        ));

        $wp_customize->add_control('pawfect_popup_upsell', array(
            'label' => esc_html__('Pro Feature', 'pawfect'),
            'description' => sprintf(
                /* translators: %s: Pro version link */
                esc_html__('Unlock advanced promotional popups with email collection and database integration by upgrading to %s.', 'pawfect'),
                '<a href="https://wpmatcha.com/pawfect-pro" target="_blank" rel="noopener">Pawfect Pro</a>'
            ),
            'section' => 'pawfect_popup_upsell_section',
            'type' => 'text',
            'input_attrs' => array(
             ),
            'priority' => 10,
        ));
    }
}

/**
 * Sanitization functions
 */
if (!function_exists('pawfect_sanitize_checkbox')) {
    function pawfect_sanitize_checkbox($checked)
    {
        return ((isset($checked) && true == $checked) ? true : false);
    }
}

if (!function_exists('pawfect_sanitize_select')) {
    function pawfect_sanitize_select($input, $setting)
    {
        $input = sanitize_key($input);
        $choices = $setting->manager->get_control($setting->id)->choices;
        return (array_key_exists($input, $choices) ? $input : $setting->default);
    }
}
