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

/**
 * Frontpage Blog Options
 *
 * @package pawfect
 */

if ( ! class_exists( 'Pawfect_Options_Blog' ) ) :

    class Pawfect_Options_Blog extends pawfect_Customize_Base_Option {

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

            return array(

                'pawfect_main_blog_heading'    => array(
                    'setting' => array(),
                    'control' => array(
                        'type'    => 'heading',
                        'priority'      => 1,
                        'label'   => esc_html__( 'Blog Options', 'pawfect' ),
                        'section' => 'pawfect_theme_blog',
                    ),
                ),
                
                'pawfect_blog_enabled'            => array(
                    'setting' => array(
                        'default'           => true,
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_checkbox' ),
                    ),
                    'control' => array(
                        'type'    => 'toggle',
                        'priority' => 2,
                        'label'    => esc_html__( 'Enable Blog Section', 'pawfect' ),
                        'description' => esc_html__('Toggle ON to show this section', 'pawfect'),
                        'section'  => 'pawfect_theme_blog',
                    ),
                ),
                
                'pawfect_blog_area_title' => array(
                    'setting' => array(
                        'default' => esc_html__('Latest News', 'pawfect'),
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'text',
                        'priority' => 4,
                        'label' => esc_html__('Section Title', 'pawfect'),
                        'section' => 'pawfect_theme_blog',
                        'active_callback' => 'pawfect_blog_enabled',
                    ),
                ),

                'pawfect_blog_area_des' => array(
                    'setting' => array(
                        'default' => esc_html__('Stay updated with the latest news...', 'pawfect'),
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'textarea',
                        'priority' => 5,
                        'label' => esc_html__('Section Description', 'pawfect'),
                        'section' => 'pawfect_theme_blog',
                        'active_callback' => 'pawfect_blog_enabled',
                    ),
                ),

                'pawfect_blog_area_button' => array(
                    'setting' => array(
                        'default' => esc_html__('Show More', 'pawfect'),
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'text',
                        'priority' => 20,
                        'label' => esc_html__('Button Text', 'pawfect'),
                        'section' => 'pawfect_theme_blog',
                        'active_callback' => 'pawfect_blog_enabled',
                    ),
                ),

                'pawfect_blog_section_button_link' => array(
                    'setting' => array(
                        'default' => '',
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'url',
                        'priority' => 25,
                        'label' => esc_html__('Button Link', 'pawfect'),
                        'section' => 'pawfect_theme_blog',
                        'active_callback' => 'pawfect_blog_enabled',
                    ),
                ),

                'pawfect_blog_button_target' => array(
                    'setting' => array(
                        'default' => '_self',
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_radio'),
                    ),
                    'control' => array(
                        'type' => 'radio-switch',
                        'priority' => 26,
                        'label' => esc_html__('Button Link Target', 'pawfect'),
                        'section' => 'pawfect_theme_blog',
                        'choices' => array(
                            '_self' => esc_html__('Same Tab', 'pawfect'),
                            '_blank' => esc_html__('New Tab', 'pawfect'),
                        ),
                        'active_callback' => 'pawfect_blog_enabled',
                    ),
                ),

                'pawfect_theme_blog_category' => array(
                    'setting' => array(
                        'sanitize_callback' => 'sanitize_text_field',
                    ),
                    'control' => array(
                        'type' => 'pawfect-category',
                        'label' => esc_html__('Choose Blog Category', 'pawfect'),
                        'section' => 'pawfect_theme_blog',
                        'priority' => 15,
                        'active_callback' => 'pawfect_blog_enabled',
                    ),
                ),

                'pawfect_blog_width' => array(
                    'setting' => array(
                        'default' => 'pawfect-container',
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_radio' ),
                    ),
                    'control' => array(
                        'type' => 'radio-switch',
                        'priority' => 10,
                        'label' => esc_html__('Container Width', 'pawfect'),
                        'section' => 'pawfect_theme_blog',
                        'choices' => array(
                            'pawfect-container-narrow' => esc_html__( 'Narrow Container', 'pawfect' ),
                            'pawfect-container' => esc_html__( 'Container', 'pawfect' ),
                        ),
                        'active_callback' => 'pawfect_blog_enabled',
                    ),
                ),

                

                'pawfect_blog_card_style' => array(
                    'setting' => array(
                        'default' => 'modern',
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_radio' ),
                    ),
                    'control' => array(
                        'type' => 'radio-switch',
                        'priority' => 15,
                        'label' => esc_html__( 'Card Style', 'pawfect' ),
                        'description' => esc_html__( 'Choose between modern and classic card styles', 'pawfect' ),
                        'section' => 'pawfect_theme_blog',
                        'choices' => array(
                            'modern' => esc_html__( 'Modern', 'pawfect' ),
                            'classic' => esc_html__( 'Classic', 'pawfect' ),
                        ),
                        'active_callback' => 'pawfect_blog_enabled',
                    ),
                ),

                'pawfect_blog_classic_minimal_style' => array(
                    'setting' => array(
                        'default' => true,
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_checkbox' ),
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'toggle',
                        'priority' => 16,
                        'label' => esc_html__( 'Enable Minimal Classic Styling', 'pawfect' ),
                        'description' => esc_html__( 'Apply minimal, clean styling to classic cards (removes background, borders, shadows)', 'pawfect' ),
                        'section' => 'pawfect_theme_blog',
                        'active_callback' => 'pawfect_blog_classic_active',
                    ),
                ),

                // column layout
                'pawfect_blog_column_layout'    => array(
                    'setting'  => array(
                        'default'           => 'col-md-4',
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_radio' ),
                    ),
                    'control'  => array(
                        'type'    => 'simple-radio-image',
                        'priority' => 30,
                        'label'    => esc_html__( 'Column Layout', 'pawfect' ),
                        'section'  => 'pawfect_theme_blog',
                        'choices'  => array(
                            'col-md-6'  => PAWFECT_THEME_URL . '/assets/images/icons/column-2.png',
                            'col-md-4'  => PAWFECT_THEME_URL . '/assets/images/icons/column-3.png',
                            'col-md-3'  => PAWFECT_THEME_URL . '/assets/images/icons/column-4.png',
                        ),
                        'active_callback' => 'pawfect_blog_enabled',
                    ),
                ),

                // Blog Count For Homepage - Responsive Range Slider
                'pawfect_blog_count' => array(
                    'setting' => array(
                        'default' => json_encode(array(
                            'desktop' => 6,
                            'tablet' => 4,
                            'mobile' => 3,
                        )),
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_responsive_range' ),
                        //'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'pawfect-responsive-range',
                        'priority' => 55,
                        'label' => esc_html__( 'Blog Post Count', 'pawfect' ),
                        'description' => esc_html__( 'Set different post counts for different devices', 'pawfect' ),
                        'section' => 'pawfect_theme_blog',
                        'input_attrs' => array(
                            'min' => 1,
                            'max' => 12,
                            'step' => 1,
                        ),
                        'suffix' => '',
                        'active_callback' => 'pawfect_blog_enabled',
                    ),
                ),
            );
        }

    }

new Pawfect_Options_Blog();

endif;

/**
 * Check if blog is enabled
 */
function pawfect_blog_enabled($control)
{
    // Following main slider pattern - return true when blog is enabled
    // This makes other blog settings visible when main toggle is ON
    return true === ( $control->manager->get_setting( 'pawfect_blog_enabled' )->value() == true );
}

/**
 * Check if blog is enabled and classic card style is selected
 */
function pawfect_blog_classic_active($control)
{
    // Check if blog is enabled AND classic card style is selected
    $blog_enabled = $control->manager->get_setting( 'pawfect_blog_enabled' )->value() == true;
    $card_style = $control->manager->get_setting( 'pawfect_blog_card_style' )->value();

    return $blog_enabled && ($card_style === 'classic');
}



