<?php     
    function aurora_lite_callback($theme_mod, $match_values = [], $invert = false) {

        if (!is_array($match_values)) {
            $match_values = [$match_values];
        }

        $mod_value = get_theme_mod($theme_mod);
        $result = in_array($mod_value, $match_values, true);

        return $invert ? !$result : $result;
    }

    if ( class_exists( 'WP_Customize_Control' ) ) {
        class Aurora_Lite_Upgrade_Control extends WP_Customize_Control {
            public $upgrade_text = '';
            public $upgrade_url = 'https://aurora.lystingz.com/?utm_source=aurora-lite&utm_medium=customizer&utm_campaign=upgrade';
            public function render_content() {
                ?>
                <div class="aurora-lite-upgrade-notice">
                    <h3><?php esc_html_e( 'Upgrade to Aurora Pro', 'aurora-lite' ); ?></h3>
                    <p><?php echo esc_html( $this->upgrade_text ); ?></p>
                    <a href="<?php echo esc_url( $this->upgrade_url ); ?>" target="_blank" class="aurora-lite-upgrade-btn">
                        <?php esc_html_e( 'Upgrade to Aurora Pro →', 'aurora-lite' ); ?>
                    </a>
                </div>
                <?php
            }
        }

        class Aurora_Device_Control extends WP_Customize_Control {
            public $device = '';

            public function __construct( $manager, $id, $args = [] ) {
                parent::__construct( $manager, $id, $args );
                if ( isset( $args['input_attrs']['data-device'] ) ) {
                    $this->device = $args['input_attrs']['data-device'];
                }
            }

            public function json() {
                $json = parent::json();
                $json['device_controls'] = [ $this->device ];
                return $json;
            }
        }
    }

    function aurora_lite_customize_register($wp_customize) {
        $sections = [
            'title_tagline'     => 0,
            'nav_menus'         => 60,
            'widgets'           => 70,
            'static_front_page' => 50,
        ];

        foreach ( $sections as $section_id => $priority ) {
            $section = $wp_customize->get_section( $section_id );
            if ( $section ) {
                $section->priority = $priority;
            }
        }

        $wp_customize->add_section('aurora_lite_colors_section', [
            'title' => __('Colors', 'aurora-lite'),
            'priority' => 20,
            'description' => __('Customize the colors for your site.', 'aurora-lite'),
        ]);

        $wp_customize->add_setting('aurora_lite_heading_color', [
            'default' => '#006370',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_heading_color', [
            'label' => __('Heading', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_body_text_color', [
            'default' => '#111111',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_body_text_color', [
            'label' => __('Body text', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_button_text_color', [
            'default' => '#f7f4e8',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_button_text_color', [
            'label' => __('Button text color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_button_background_color', [
            'default' => '#d38600',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_button_background_color', [
            'label' => __('Button background color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_button_text_hover_color', [
            'default' => '#541600',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_button_text_hover_color', [
            'label' => __('Button text hover color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_button_background_hover_color', [
            'default' => '#fcf4e0',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_button_background_hover_color', [
            'label' => __('Button background hover color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_link_color', [
            'default' => '#006be5',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_link_color', [
            'label' => __('Link color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_link_hover_color', [
            'default' => '#003e75',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_link_hover_color', [
            'label' => __('Link hover color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_header_background_color', [
            'default' => '#004354',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_header_background_color', [
            'label' => __('Header background color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_menu_text_color', [
            'default' => '#edede1',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_menu_text_color', [
            'label' => __('Menu text color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_menu_text_hover_color', [
            'default' => '#5bdeff',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_menu_text_hover_color', [
            'label' => __('Menu text hover color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_menu_text_active_color', [
            'default' => '',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_menu_text_active_color', [
            'label' => __('Menu text active color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_header_icon_color', [
            'default' => '',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_header_icon_color', [
            'label' => __('Header icon color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_footer_background_color', [
            'default' => '#111111',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_footer_background_color', [
            'label' => __('Footer background color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_footer_text_color', [
            'default' => '#d3d2c9',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_footer_text_color', [
            'label' => __('Footer text color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_footer_link_color', [
            'default' => '#f2b100',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_footer_link_color', [
            'label' => __('Footer link color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_sidebar_background_color', [
            'default' => '',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_sidebar_background_color', [
            'label' => __('Sidebar background color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        $wp_customize->add_setting('aurora_lite_site_background_color', [
            'default' => '#ffffff',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport' => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'aurora_lite_site_background_color', [
            'label' => __('Site background color', 'aurora-lite'),
            'section' => 'aurora_lite_colors_section',
        ]));

        function aurora_lite_get_layout_choices($directory) {
        $choices = [];
        if (is_dir($directory)) {
            $files = scandir($directory);
            foreach ($files as $file) {
                if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
                    $key = pathinfo($file, PATHINFO_FILENAME);
                    $choices[$key] = $key;
                }
            }
        }
        return $choices;
        }

        $header_layouts = aurora_lite_get_layout_choices(get_template_directory() . '/template-parts/headers');
        $footer_layouts = aurora_lite_get_layout_choices(get_template_directory() . '/template-parts/footers');
        $archive_layouts = aurora_lite_get_layout_choices(get_template_directory() . '/template-parts/layouts/archives');
        $search_result_layouts = aurora_lite_get_layout_choices(get_template_directory() . '/template-parts/layouts/search-results');
        $single_post_layouts = aurora_lite_get_layout_choices(get_template_directory() . '/template-parts/layouts/single');
        $author_page_layouts = aurora_lite_get_layout_choices(get_template_directory() . '/template-parts/layouts/authors');
        $_404_page_layouts = aurora_lite_get_layout_choices(get_template_directory() . '/template-parts/404');
        $homepage_layouts = aurora_lite_get_layout_choices(get_template_directory() . '/template-parts/homepage');


        $wp_customize->add_panel('aurora_lite_layouts_panel', [
            'title'       => __('Layouts', 'aurora-lite'),
            'description' => __('Choose layouts for headers, footers, archives, and single posts.', 'aurora-lite'),
            'priority'    => 40,
        ]);

        $wp_customize->add_section('aurora_lite_header_layout_section', [
            'title'    => __('Header Layout', 'aurora-lite'),
            'panel'    => 'aurora_lite_layouts_panel',
            'priority' => 0
        ]);

        $wp_customize->add_setting('aurora_lite_header_layout', [
            'default'           => 'Default',
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'refresh',
        ]);

        $wp_customize->add_control('aurora_lite_header_layout', [
            'label'   => __('Header Layout Style', 'aurora-lite'),
            'section' => 'aurora_lite_header_layout_section',
            'type'    => 'select',
            'choices' => $header_layouts,
        ]);

        $wp_customize->add_setting( 'aurora_lite_sticky_header', array(
            'default'           => false,
            'sanitize_callback' => 'wp_validate_boolean'
        ));

        $wp_customize->add_control( 'aurora_lite_sticky_header', array(
            'label'    => __( 'Make the header sticky', 'aurora-lite' ),
            'section'  => 'aurora_lite_header_layout_section',
            'settings' => 'aurora_lite_sticky_header',
            'type'     => 'checkbox',
        ));

        $devices = ['desktop', 'tablet', 'mobile'];

        foreach ($devices as $device) {
            $wp_customize->add_setting("aurora_lite_logo_width_{$device}", [
                'default'           => $device === 'desktop' ? 80 : ($device === 'tablet' ? 70 : 60),
                'sanitize_callback' => 'absint',
                'transport'         => 'postMessage'
            ]);

            $wp_customize->add_control(new Aurora_Device_Control($wp_customize, "aurora_lite_logo_width_{$device}", [
                'label' => sprintf( __( 'Header Logo Width (%s) (px)', 'aurora-lite' ), $device ),
                'section' => 'aurora_lite_header_layout_section',
                'type'    => 'number',
                'input_attrs' => [
                    'min'  => 40,
                    'max'  => 400,
                    'step' => 1,
                    'data-device' => $device,
                ]
            ]));
        }

        $wp_customize->add_setting( 'aurora_lite_header_btn1_text', [
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'refresh',
        ] );

        $wp_customize->add_control( 'aurora_lite_header_btn1_text', [
            'label'   => __( 'Primary Button Text', 'aurora-lite' ),
            'section' => 'aurora_lite_header_layout_section',
            'type'    => 'text',
        ] );

        $wp_customize->add_setting( 'aurora_lite_header_btn1_url', [
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
            'transport'         => 'refresh',
        ] );

        $wp_customize->add_control( 'aurora_lite_header_btn1_url', [
            'label'   => __( 'Primary Button Link', 'aurora-lite' ),
            'section' => 'aurora_lite_header_layout_section',
            'type'    => 'url',
        ] );

        $wp_customize->add_setting( 'aurora_lite_header_btn2_text', [
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'refresh',
        ] );

        $wp_customize->add_control( 'aurora_lite_header_btn2_text', [
            'label'   => __( 'Secondary Button Text', 'aurora-lite' ),
            'section' => 'aurora_lite_header_layout_section',
            'type'    => 'text',
        ] );

        $wp_customize->add_setting( 'aurora_lite_header_btn2_url', [
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
            'transport'         => 'refresh',
        ] );

        $wp_customize->add_control( 'aurora_lite_header_btn2_url', [
            'label'   => __( 'Secondary Button Link', 'aurora-lite' ),
            'section' => 'aurora_lite_header_layout_section',
            'type'    => 'url',
        ] );

        $wp_customize->add_setting( 'aurora_lite_header_upgrade_notice', [
            'sanitize_callback' => '__return_false',
        ] );

        $wp_customize->add_control( new Aurora_Lite_Upgrade_Control( $wp_customize, 'aurora_lite_header_upgrade_notice', [
            'section'      => 'aurora_lite_header_layout_section',
            'upgrade_text' => 'Upgrade to Pro to unlock 7 extra header styles (including 2 vertical headers), an option to add JavaScript to your header, and the ability to show contact details in your chosen header template. Instant switch, no demo import needed.',
        ] ) );


        $wp_customize->add_section( 'aurora_lite_socials_contacts_panel', array(
            'title'    => __( 'Socials & Contact', 'aurora-lite' ),
            'priority' => 30,
            'panel'    => 'aurora_lite_layouts_panel',
            'priority' => 35,
        ) );

        $social_networks = [
            'facebook'  => ['label' => esc_html__('Facebook',  'aurora-lite'), 'icon' => 'fa-brands fa-facebook-f'],
            'twitter'   => ['label' => esc_html__('X',   'aurora-lite'),       'icon' => 'fa-brands fa-x-twitter'],
            'tiktok'    => ['label' => esc_html__('TikTok',    'aurora-lite'), 'icon' => 'fa-brands fa-tiktok'],
            'instagram' => ['label' => esc_html__('Instagram', 'aurora-lite'), 'icon' => 'fa-brands fa-instagram'],
            'whatsapp'  => ['label' => esc_html__('WhatsApp',  'aurora-lite'), 'icon' => 'fa-brands fa-whatsapp'],
            'linkedin'  => ['label' => esc_html__('LinkedIn',  'aurora-lite'), 'icon' => 'fa-brands fa-linkedin-in'],
            'pinterest' => ['label' => esc_html__('Pinterest', 'aurora-lite'), 'icon' => 'fa-brands fa-pinterest'],
            'reddit'    => ['label' => esc_html__('Reddit',    'aurora-lite'), 'icon' => 'fa-brands fa-reddit'],
            'youtube'   => ['label' => esc_html__('YouTube',   'aurora-lite'), 'icon' => 'fa-brands fa-youtube'],
        ];

        foreach ( $social_networks as $key => $data ) {
            $wp_customize->add_setting( "aurora_lite_social_{$key}", array(
                'default'   => '',
                'transport' => 'refresh',
                'sanitize_callback' => 'esc_url_raw',
            ));

            $wp_customize->add_control( "aurora_lite_social_{$key}", array(
                /* translators: %s: social network name, e.g. "Facebook" */
                'label'   => sprintf( esc_html__( '%s URL', 'aurora-lite' ), $data['label'] ),
                'section' => 'aurora_lite_socials_contacts_panel',
                'type'    => 'url',
            ));
        }

        $wp_customize->add_setting( 'aurora_lite_social_upgrade_notice', [
            'sanitize_callback' => '__return_false',
        ] );

        $wp_customize->add_control( new Aurora_Lite_Upgrade_Control( $wp_customize, 'aurora_lite_social_upgrade_notice', [
            'section'      => 'aurora_lite_socials_contacts_panel',
            'upgrade_text' => 'Upgrade to Pro to add contact details to your header and footer while choosing to display the details using either icons or labels. You also get to show social icons in your header. Instant switch, no demo import needed.',
        ] ) );

        $wp_customize->add_section('aurora_lite_single_post_layout_section', [
            'title'    => __('Single Post Layout', 'aurora-lite'),
            'panel'    => 'aurora_lite_layouts_panel',
            'priority' => 10,
        ]);

        $wp_customize->add_setting('aurora_lite_single_post_layout', [
            'default'           => 'Default',
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'refresh',
        ]);

        $wp_customize->add_control('aurora_lite_single_post_layout', [
            'label'    => __('Single Post Layout', 'aurora-lite'),
            'section'  => 'aurora_lite_single_post_layout_section',
            'type'    => 'select',
            'choices' => $single_post_layouts,
        ]);


        $wp_customize->add_setting('aurora_lite_show_sidebar', [
            'default'   => false,
            'transport' => 'refresh',
            'sanitize_callback' => 'wp_validate_boolean',
        ]);

        $wp_customize->add_control('aurora_lite_show_sidebar', [
            'label'   => __( 'Show the sidebar in single posts', 'aurora-lite' ),
            'section' => 'aurora_lite_single_post_layout_section',
            'type'    => 'checkbox',
        ]);

        $wp_customize->add_setting('aurora_lite_dropcase_style', [
            'default'           => 'none',
            'sanitize_callback' => 'sanitize_key',
            'transport'         => 'postMessage'
        ]);

        $wp_customize->add_control('aurora_lite_dropcase_style', [
            'label'   => __('Drop Cap Style', 'aurora-lite'),
            'section' => 'aurora_lite_single_post_layout_section',
            'type'    => 'select',
            'choices' => [
                'none'   => __('None', 'aurora-lite'),
                'bold'   => __('Bold', 'aurora-lite'),
                'casual' => __('Casual', 'aurora-lite'),        
                'pretty' => __('Pretty', 'aurora-lite'),
            ]
        ]);

        $wp_customize->add_setting('aurora_lite_sharing_heading', array(
            'sanitize_callback' => 'wp_kses_post',
        ));

        $wp_customize->add_control(new WP_Customize_Control(
            $wp_customize,
            'aurora_lite_sharing_heading',
            array(
                'label'    => __('Social Sharing Settings', 'aurora-lite'),
                'type'     => 'hidden',
                'section'  => 'aurora_lite_single_post_layout_section',
                'description' => __('Select which sharing options to shows on your single posts.', 'aurora-lite'),
            )
        ));

        $socials = array(
            'facebook'  => 'Facebook',
            'twitter'   => 'X',
            'reddit'    => 'Reddit',
            'tumblr'    => 'Tumblr',
            'telegram'  => 'Telegram',
            'whatsapp'  => 'WhatsApp',
            'email'     => 'Email',
            'messenger' => 'Messenger',
            'sms'       => 'SMS',
            'copy_link' => 'Link copy',
        );

        foreach ( $socials as $key => $label ) {
            $wp_customize->add_setting( "aurora_lite_share_$key", array(
                'default'   => true,
                'transport' => 'refresh',
                'sanitize_callback' => 'wp_validate_boolean',
            ));

            $wp_customize->add_control( "aurora_lite_share_$key", array(
                'type'    => 'checkbox',
                'section' => 'aurora_lite_single_post_layout_section',
                'label'   => $label,
            ));
        }

        $wp_customize->add_setting( 'aurora_lite_posts_upgrade_notice', [
            'sanitize_callback' => '__return_false',
        ] );

        $wp_customize->add_control( new Aurora_Lite_Upgrade_Control( $wp_customize, 'aurora_lite_posts_upgrade_notice', [
            'section'      => 'aurora_lite_single_post_layout_section',
            'upgrade_text' => 'Upgrade to Pro to unlock 9 extra single post styles. Enjoy stunning and modern designs for your posts including social media fields in the author block. Instant switch, no demo import needed.',
        ] ) );

        $wp_customize->add_section('aurora_lite_archive_layout_section', [
            'title'    => __('Archive Layout', 'aurora-lite'),
            'panel'    => 'aurora_lite_layouts_panel',
            'priority' => 15,
        ]);

        $wp_customize->add_setting('aurora_lite_archive_layout', [
            'default'           => 'Default',
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'refresh',
        ]);

        $wp_customize->add_control('aurora_lite_archive_layout', [
            'label'   => __('Archive Layout Style', 'aurora-lite'),
            'section' => 'aurora_lite_archive_layout_section',
            'type'    => 'select',
            'choices' => $archive_layouts,
        ]);

        $wp_customize->add_setting('aurora_lite_archive_masonry_enabled', [
            'default'           => false,
            'sanitize_callback' => 'wp_validate_boolean',
        ]);

        $wp_customize->add_control('aurora_lite_archive_masonry_enabled', [
            'label'    => __('Enable Masonry Layout for Archives', 'aurora-lite'),
            'section'  => 'aurora_lite_archive_layout_section',
            'type'     => 'checkbox',
        ]);


        $wp_customize->add_setting('aurora_lite_posts_per_page', array(
            'default'           => 16,
            'sanitize_callback' => 'absint',
        ));

        $wp_customize->add_control('aurora_lite_posts_per_page', array(
            'label'       => __('Posts Per Page', 'aurora-lite'),
            'section'     => 'aurora_lite_archive_layout_section',
            'description' => __( 'Set the number of posts per archive page. Use "0" to display all posts.', 'aurora-lite' ),
            'type'        => 'number',
            'input_attrs' => array(
                'min'  => 0,
                'max'  => 40,
                'step' => 1,
            ),
        ));

        $wp_customize->add_setting('aurora_lite_show_more_option', array(
            'default'           => 'pagination',
            'sanitize_callback' => 'sanitize_text_field',
        ));

        $wp_customize->add_control('aurora_lite_show_more_option', array(
            'label'       => __('Show More Post Option', 'aurora-lite'),
            'section'     => 'aurora_lite_archive_layout_section',
            'type'        => 'radio',
            'choices'     => array(
                'pagination' => __('Pagination', 'aurora-lite'),
                'load_more'  => __('Load More', 'aurora-lite')
            ),
            'active_callback' => function() {
                return (int) get_theme_mod('aurora_lite_posts_per_page') !== 0;
            },
        ));

        $wp_customize->add_setting('aurora_lite_show_archive_sidebar', [
            'default'   => false,
            'transport' => 'refresh',
            'sanitize_callback' => 'wp_validate_boolean',
        ]);

        $wp_customize->add_control('aurora_lite_show_archive_sidebar', [
            'label'   => __( 'Show the sidebar in archives and search page', 'aurora-lite' ),
            'section' => 'aurora_lite_archive_layout_section',
            'type'    => 'checkbox',
        ]);

        $wp_customize->add_setting( 'aurora_lite_disable_archive_banner', [
            'default'           => false,
            'sanitize_callback' => 'wp_validate_boolean',
        ]);

        $wp_customize->add_control( 'aurora_lite_disable_archive_banner', [
            'label'    => __( 'Disable Archive Top Banner', 'aurora-lite' ),
            'section'  => 'aurora_lite_archive_layout_section',
            'type'     => 'checkbox',
        ]);

        $wp_customize->add_setting( 'aurora_lite_archive_upgrade_notice', [
            'sanitize_callback' => '__return_false',
        ] );

        $wp_customize->add_control( new Aurora_Lite_Upgrade_Control( $wp_customize, 'aurora_lite_archive_upgrade_notice', [
            'section'      => 'aurora_lite_archive_layout_section',
            'upgrade_text' => 'Upgrade to Pro to unlock 12 extra archive layout styles. 5 of these also come with masonry activation. Instant switch, no demo import needed.',
        ] ) );


        $wp_customize->add_section('aurora_lite_search_page', [
            'title'    => __('Search Results Page', 'aurora-lite'),
            'panel'    => 'aurora_lite_layouts_panel',
            'priority' => 20,
        ]);

        $wp_customize->add_setting(
            'aurora_lite_search_results_layout', [
                'default'           => 'Default',
                'sanitize_callback' => 'sanitize_text_field',
        ]);

        $wp_customize->add_control(
            'aurora_lite_search_results_layout', [
                'label'       => __( 'Search Results Layout', 'aurora-lite' ),
                'description' => __( 'Select the layout used for search results.', 'aurora-lite' ),
                'section'     => 'aurora_lite_search_page',
                'type'        => 'select',
                'choices'     => $search_result_layouts,
        ]);

        $wp_customize->add_setting(
            'aurora_lite_search_header_bg',
            [
                'default'           => '#664700',
                'sanitize_callback' => 'sanitize_hex_color',
                'transport'         => 'postMessage',
            ]
        );

        $wp_customize->add_control(
            new WP_Customize_Color_Control(
                $wp_customize,
                'aurora_lite_search_header_bg', [
                    'label'   => __( 'Search Header Background', 'aurora-lite' ),
                    'section' => 'aurora_lite_search_page',
                    'settings'=> 'aurora_lite_search_header_bg',
        ]));

        $wp_customize->add_setting(
            'aurora_lite_search_placeholder', [
                'default'           => __( 'Search posts…', 'aurora-lite' ),
                'sanitize_callback' => 'sanitize_text_field',
                'transport'         => 'postMessage',
        ]);

        $wp_customize->add_control(
            'aurora_lite_search_placeholder', [
                'label'       => __( 'Search Placeholder Text', 'aurora-lite' ),
                'section'     => 'aurora_lite_search_page',
                'type'        => 'text',
                'description' => __( 'Text shown inside the search input field.', 'aurora-lite' ),
        ]);

        $wp_customize->add_setting( 'aurora_lite_search_upgrade_notice', [
            'sanitize_callback' => '__return_false',
        ] );

        $wp_customize->add_control( new Aurora_Lite_Upgrade_Control( $wp_customize, 'aurora_lite_search_upgrade_notice', [
            'section'      => 'aurora_lite_search_page',
            'upgrade_text' => 'Upgrade to Pro to unlock 2 extra header styles for your Search page. Additionally, you unlock 12 post preview styles for your posts results. Instant switch, no demo import needed.',
        ] ) );


        $wp_customize->add_section('aurora_lite_author_page_layout_section', [
            'title'    => __('Author Page Layout', 'aurora-lite'),
            'panel'    => 'aurora_lite_layouts_panel',
            'priority' => 25,
        ]);

        $wp_customize->add_setting('aurora_lite_author_page_layout', [
            'default'           => 'Default',
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'refresh',
        ]);

        $wp_customize->add_control('aurora_lite_author_page_layout', [
            'label'   => __('Author Page Header Style', 'aurora-lite'),
            'section' => 'aurora_lite_author_page_layout_section',
            'type'    => 'select',
            'choices' => $author_page_layouts,
        ]);

        $wp_customize->add_setting('aurora_lite_author_header_bg', [
            'default'           => '#004c40',
            'sanitize_callback' => 'sanitize_hex_color',
            'transport'         => 'postMessage',
        ]);

        $wp_customize->add_control(new WP_Customize_Color_Control(
            $wp_customize,
            'aurora_lite_author_header_bg',
            [
                'label'   => __('Author Header Background', 'aurora-lite'),
                'section' => 'aurora_lite_author_page_layout_section',
                'settings'=> 'aurora_lite_author_header_bg',
            ]
        ));

        $wp_customize->add_setting( 'aurora_lite_author_upgrade_notice', [
            'sanitize_callback' => '__return_false',
        ] );

        $wp_customize->add_control( new Aurora_Lite_Upgrade_Control( $wp_customize, 'aurora_lite_author_upgrade_notice', [
            'section'      => 'aurora_lite_author_page_layout_section',
            'upgrade_text' => 'Upgrade to Pro to unlock 3 extra header styles for your Author page, including the ability to set a custom background. Additionally, you unlock 12 post preview styles for your posts results and social icons for authors. Instant switch, no demo import needed.',
        ] ) );

        $wp_customize->add_section('aurora_404_page_layout_section', [
            'title'    => __('404 page style', 'aurora-lite'),
            'panel'    => 'aurora_lite_layouts_panel',
            'priority' => 30
        ]);

        $wp_customize->add_setting('aurora_404_page_layout', [
            'default'           => 'Default',
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'refresh',
        ]);

        $wp_customize->add_control('aurora_404_page_layout', [
            'label'   => __('404 Page Style', 'aurora-lite'),
            'section' => 'aurora_404_page_layout_section',
            'type'    => 'select',
            'choices' => $_404_page_layouts,
        ]);

        $wp_customize->add_setting( 'aurora_404_page_title', [
            'default'           => __( 'Page Not Found', 'aurora-lite' ),
            'sanitize_callback' => 'sanitize_text_field',
        ] );

        $wp_customize->add_control( 'aurora_404_page_title', [
            'label'   => __( '404 Page Title', 'aurora-lite' ),
            'section' => 'aurora_404_page_layout_section', 
            'type'    => 'text',
        ] );

        $wp_customize->add_setting( 'aurora_404_page_text', [
            'default'           => __( 'Sorry, the page you are looking for does not exist or the link is incorrect.', 'aurora-lite' ),
            'sanitize_callback' => 'wp_kses_post',
        ] );

        $wp_customize->add_control( 'aurora_404_page_text', [
            'label'   => __( '404 Page Text', 'aurora-lite' ),
            'section' => 'aurora_404_page_layout_section',
            'type'    => 'textarea',
        ] );

        $wp_customize->add_setting(
            'aurora_lite_404_button_text',
            [
                'default'           => __( 'Back to Home', 'aurora-lite' ),
                'sanitize_callback' => 'sanitize_text_field',
            ]
        );

        $wp_customize->add_control(
            'aurora_lite_404_button_text',
            [
                'label'       => __( '404 Button Text', 'aurora-lite' ),
                'section'     => 'aurora_404_page_layout_section',
                'type'        => 'text',
                'description' => __( 'Text shown on the 404 page button.', 'aurora-lite' ),
            ]
        );

        $wp_customize->add_setting(
            'aurora_404_button_url',
            [
                'default'           => home_url('/'),
                'sanitize_callback' => 'esc_url_raw',
            ]
        );

        $wp_customize->add_control(
            'aurora_404_button_url',
            [
                'label'       => __( '404 Button Link', 'aurora-lite' ),
                'section'     => 'aurora_404_page_layout_section',
                'type'        => 'url',
                'description' => __( 'Leave empty to hide the button', 'aurora-lite' ),
            ]
        );

        $wp_customize->add_setting( 'aurora_404_upgrade_notice', [
            'sanitize_callback' => '__return_false',
        ] );

        $wp_customize->add_control( new Aurora_Lite_Upgrade_Control( $wp_customize, 'aurora_404_upgrade_notice', [
            'section'      => 'aurora_404_page_layout_section',
            'upgrade_text' => 'Upgrade to Pro to unlock 4 extra 404 page styles. You also get the ability to set your own 404 background images. Instant switch, no demo import needed.',
        ] ) );

        function aurora_lite_get_terms_list($taxonomy = 'category') {
            $terms = get_terms([
                'taxonomy' => $taxonomy,
                'hide_empty' => false,
            ]);

            $list = [];
            if (!is_wp_error($terms)) {
                foreach ($terms as $term) {
                    $list[$term->term_id] = $term->name;
                }
            }

            return $list;
        }

        class Aurora_Section_Control extends WP_Customize_Control {
            public $section_id = '';
            
            public function render() {
                ?>
                <li id="customize-control-<?php echo esc_attr( $this->id ); ?>" 
                    class="customize-control customize-control-<?php echo esc_attr( $this->type ); ?>" 
                    data-home-section="<?php echo esc_attr( $this->section_id ); ?>">
                    <?php $this->render_content(); ?>
                </li>
                <?php
            }
        }

        function aurora_lite_section_field_visibility( $section_id, $field_id ) {

            return function() use ( $section_id, $field_id ) {

                $source = get_theme_mod( "{$section_id}_source", 'category' );

                switch ( $field_id ) {

                    case 'source':
                        return true;

                    case 'category':
                        return $source === 'category';

                    case 'tag':
                        return $source === 'tag';

                    case 'posts':
                        return $source === 'custom_posts';

                    case 'exclude_posts':
                        return $source !== 'custom_posts' && $source !== 'none';

                    default:
                        return true;
                }
            };
        }

        $wp_customize->add_section('aurora_lite_homepage_layout_section', [
            'title'    => __('Homepage style', 'aurora-lite'),
            'panel'    => 'aurora_lite_layouts_panel',
            'priority' => 5,
        ]);

        $wp_customize->add_setting('aurora_lite_homepage_layout', [
            'default'           => 'Default',
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'refresh',
        ]);

        $wp_customize->add_control('aurora_lite_homepage_layout', [
            'label'   => __('Homepage Style', 'aurora-lite'),
            'section' => 'aurora_lite_homepage_layout_section',
            'type'    => 'select',
            'choices' => $homepage_layouts,
        ]);

        $sections = [
            'bold'      => __( 'Bold', 'aurora-lite' ),
            'overlay'   => __( 'Overlay', 'aurora-lite' ),
            'mag'       => __( 'Magazine', 'aurora-lite' ),
            'embed'     => __( 'Embed', 'aurora-lite' ),
            'plain'     => __( 'Plain', 'aurora-lite' ),
            'genteel'   => __( 'Genteel', 'aurora-lite' ),
            'poster'    => __( 'Poster', 'aurora-lite' ),
            'sweet'     => __( 'Sweet', 'aurora-lite' ),
        ];

        $fields = [
            'source' => [
                'type'    => 'select',
                'label'   => 'Post Source',
                'choices' => [
                    'category'     => __( 'Category',       'aurora-lite' ),
                    'tag'          => __( 'Tag',             'aurora-lite' ),
                    'custom_posts' => __( 'Specific Posts',  'aurora-lite' ),
                    'none'         => __( 'None',           'aurora-lite' ),
                ],
                'default' => 'category',
            ],

            'category' => [
                'type'        => 'select',
                'label'       => __( 'Category', 'aurora-lite' ),
                'choices'     => aurora_lite_get_terms_list('category'),
            ],

            'tag' => [
                'type'    => 'select',
                'label'       => __( 'Tag', 'aurora-lite' ),
                'choices' => aurora_lite_get_terms_list('post_tag'),
            ],

            'posts' => [
                'type'        => 'text',
                'label'       => __( 'Include Posts', 'aurora-lite' ),
                'description' => __( 'Comma-separated IDs of specific posts to include.', 'aurora-lite' ),
                'placeholder' => __( 'Comma-separated IDs', 'aurora-lite' ),
            ],

            'exclude_posts' => [
                'type'        => 'text',
                'label'       => __( 'Exclude Posts', 'aurora-lite' ),
            'description' => __( 'Comma-separated IDs of posts to exclude.', 'aurora-lite' ),
            'placeholder' => __( 'Comma-separated IDs', 'aurora-lite' ),
            ],
        ];

        foreach ($sections as $section_id => $section_title) {
            foreach ($fields as $field_id => $opts) {

                $setting_id = "{$section_id}_{$field_id}";

                $wp_customize->add_setting($setting_id, [
                    'default'           => $opts['default'] ?? '',
                    'sanitize_callback' => 'sanitize_text_field',
                    'transport'         => 'refresh',
                ]);

                $active_callback = aurora_lite_section_field_visibility($section_id, $field_id);

                $wp_customize->add_control(new Aurora_Section_Control($wp_customize, $setting_id, [
                    'label'           => "{$section_title}: {$opts['label']}",
                    'description'     => $opts['description'] ?? '',
                    'section'         => 'aurora_lite_homepage_layout_section',
                    'type'            => $opts['type'],
                    'choices'         => $opts['choices'] ?? [],
                    'active_callback' => $active_callback,
                    'section_id'      => $section_id,
                ]));
            }
        }

        $wp_customize->add_setting( 'aurora_lite_home_upgrade_notice', [
            'sanitize_callback' => '__return_false',
        ] );

        $wp_customize->add_control( new Aurora_Lite_Upgrade_Control( $wp_customize, 'aurora_lite_home_upgrade_notice', [
            'section'      => 'aurora_lite_homepage_layout_section',
            'upgrade_text' => 'Upgrade to Pro to unlock 4 extra homepage styles including 3 extra sections for custom content. Enjoy more features such as post carousels and fancy grids. Instant switch, no demo import needed.',
        ] ) );

        $wp_customize->add_section('aurora_lite_footer_layout_section', [
            'title'    => __('Footer Layout', 'aurora-lite'),
            'panel'    => 'aurora_lite_layouts_panel',
        ]);

        $wp_customize->add_setting('aurora_lite_footer_layout', [
            'default'           => 'Default',
            'sanitize_callback' => 'sanitize_text_field',
            'transport'         => 'refresh',
        ]);

        $wp_customize->add_control('aurora_lite_footer_layout', [
            'label'   => __('Footer Layout Style', 'aurora-lite'),
            'section' => 'aurora_lite_footer_layout_section',
            'type'    => 'select',
            'choices' => $footer_layouts,
        ]);

        $wp_customize->add_setting('aurora_lite_footer_logo', [
            'default'           => '',
            'sanitize_callback' => 'absint'
        ]);

        $wp_customize->add_control(new WP_Customize_Media_Control(
            $wp_customize,
            'aurora_lite_footer_logo_control',
            [
                'label'    => __('Custom footer logo', 'aurora-lite'),
                'section'  => 'aurora_lite_footer_layout_section',
                'settings' => 'aurora_lite_footer_logo',
                'mime_type'=> 'image'
            ]
        ));
        $devices = ['desktop', 'tablet', 'mobile'];

        foreach ($devices as $device) {
            $wp_customize->add_setting("aurora_lite_footer_logo_width_{$device}", [
                'default'           => $device === 'desktop' ? 120 : ($device === 'tablet' ? 100 : 90),
                'sanitize_callback' => 'absint',
                'transport'         => 'postMessage'
            ]);

            $wp_customize->add_control(new Aurora_Device_Control($wp_customize, "aurora_lite_footer_logo_width_{$device}", [
                'label' => sprintf( __( 'Footer Logo Width (%s) (px)', 'aurora-lite' ), $device ),
                'section' => 'aurora_lite_footer_layout_section',
                'type'    => 'number',
                'input_attrs' => [
                    'min'  => 40,
                    'max'  => 400,
                    'step' => 1,
                    'data-device' => $device,
                ]
            ]));
        }
        

        $wp_customize->add_setting('aurora_lite_show_socials_in_footer', [
            'default'   => false,
            'transport' => 'refresh',
            'sanitize_callback' => 'wp_validate_boolean',
        ]);

        $wp_customize->add_control('aurora_lite_show_socials_in_footer', [
            'label'   => __( 'Show social links in the footer', 'aurora-lite' ),
            'section' => 'aurora_lite_footer_layout_section',
            'type'    => 'checkbox',
        ]);

        $wp_customize->add_section(
            'aurora_lite_footer_columns',
            [
                'title'    => __( 'Footer Columns', 'aurora-lite' ),
                'priority' => 160,
            ]
        );

        for ( $i = 2; $i <= 4; $i++ ) {
            $wp_customize->add_setting(
                "aurora_lite_footer_col_{$i}_title",
                [
                    'default'           => '',
                    'sanitize_callback' => 'sanitize_text_field',
                    'transport'         => 'postMessage',
                ]
            );

            $wp_customize->add_control(
                "aurora_lite_footer_col_{$i}_title",
                [
                    /* translators: %d: column number, e.g. 1, 2, 3 */
                    'label'       => sprintf(__( 'Column %d Title', 'aurora-lite' ), $i ),
                    'description' => __( 'Leave blank to remove title.', 'aurora-lite' ),
                    'section'     => 'aurora_lite_footer_layout_section',
                    'type'        => 'text',
                    'input_attrs' => [ 'placeholder' => __( 'Enter column title…', 'aurora-lite' ), ],
                ]
            );
        }

        $wp_customize->add_setting('aurora_lite_footer_copyright_text', [
            'default'           => '',
            'sanitize_callback' => 'wp_kses_post',
            'transport'         => 'postMessage',
            
        ]);

        $wp_customize->add_control('aurora_lite_footer_copyright_text', [
            'type'        => 'textarea',
            'section'     => 'aurora_lite_footer_layout_section',
            'label'       => __('Copyright Text', 'aurora-lite'),
            'input_attrs' => [
                    'placeholder' => __('Enter your custom copyright text...', 'aurora-lite'),
                    'rows'        => 2,
                ],
        ]);

        $wp_customize->add_setting( 'aurora_lite_footer_upgrade_notice', [
            'sanitize_callback' => '__return_false',
        ] );

        $wp_customize->add_control( new Aurora_Lite_Upgrade_Control( $wp_customize, 'aurora_lite_footer_upgrade_notice', [
            'section'      => 'aurora_lite_footer_layout_section',
            'upgrade_text' => 'Upgrade to Pro to unlock 4 extra footer styles and a section for custom Javascript. You get to show recent posts and a bio in your footer and set the copyright text exactly as you want. Instant switch, no demo import needed.',
        ] ) );

        
        $google_fonts = file_get_contents(get_template_directory() . '/assets/fonts/google-fonts.json');
        $google_fonts_array = json_decode($google_fonts, true);

        $font_choices = ['' => __('Default', 'aurora-lite')];

        if (isset($google_fonts_array['fonts']) && is_array($google_fonts_array['fonts'])) {
            foreach ($google_fonts_array['fonts'] as $font) {
                $font_choices[$font['family']] = $font['family'];
            }
        }

        function aurora_lite_add_typography_controls($wp_customize, $section_id, $prefix, $font_choices, $args = []) {

            $active_callback = $args['active_callback'] ?? null;
            $default_weight   = $args['default_weight'] ?? '400';

            $wp_customize->add_setting( "{$prefix}_font_family", [
                'default'           => '',
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
            ] );
            $font_family_args = [
                'type'    => 'select',
                'section' => $section_id,
                'label'   => __( 'Font Family', 'aurora-lite' ),
                'choices' => $font_choices,
            ];
            if ( $active_callback ) { $font_family_args['active_callback'] = $active_callback; }
            $wp_customize->add_control( "{$prefix}_font_family", $font_family_args );

            $responsive_properties = ['font_size', 'line_height', 'letter_spacing', 'word_spacing'];
            $devices = ['desktop', 'tablet', 'mobile'];

            $property_labels = [
                'font_size'      => __('Font Size',      'aurora-lite'),
                'line_height'    => __('Line Height',    'aurora-lite'),
                'letter_spacing' => __('Letter Spacing', 'aurora-lite'),
                'word_spacing'   => __('Word Spacing',   'aurora-lite'),
            ];

            foreach ($responsive_properties as $property) {
                foreach ($devices as $device) {

                    $control_id = "{$prefix}_{$property}_{$device}";

                    $wp_customize->add_setting($control_id, [
                        'default'   => '',
                        'transport' => 'postMessage',
                        'sanitize_callback' => 'sanitize_text_field',
                    ]);

                    $control_args = [
                        'type'    => 'text',
                        'section' => $section_id,
                        'label' => sprintf( __( '%1$s (%2$s)', 'aurora-lite' ), $property_labels[ $property ], $device ),
                        'input_attrs' => [
                            'data-device'   => $device,
                            'data-property' => $property,
                            'data-prefix'   => $prefix,
                        ],
                    ];

                    if ($active_callback) {
                        $control_args['active_callback'] = $active_callback;
                    }

                    $wp_customize->add_control(new Aurora_Device_Control($wp_customize, $control_id, $control_args));
                }
            }

            $wp_customize->add_setting( "{$prefix}_text_transform", [
                'default'           => 'none',
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
            ] );
            $text_transform_args = [
                'type'    => 'select',
                'section' => $section_id,
                'label'   => __( 'Text Transform', 'aurora-lite' ),
                'choices' => [
                    'none'       => __( 'None', 'aurora-lite' ),
                    'capitalize' => __( 'Capitalize', 'aurora-lite' ),
                    'uppercase'  => __( 'Uppercase', 'aurora-lite' ),
                    'lowercase'  => __( 'Lowercase', 'aurora-lite' ),
                ],
            ];
            if ( $active_callback ) { $text_transform_args['active_callback'] = $active_callback; }
            $wp_customize->add_control( "{$prefix}_text_transform", $text_transform_args );

            $wp_customize->add_setting( "{$prefix}_font_weight", [
                'default'           => $default_weight,
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
            ] );
            $font_weight_args = [
                'type'    => 'select',
                'section' => $section_id,
                'label'   => __( 'Font Weight', 'aurora-lite' ),
                'choices' => [
                    '100' => 'Thin (100)',
                    '200' => 'Extra Light (200)',
                    '300' => 'Light (300)',
                    '400' => 'Normal (400)',
                    '500' => 'Medium (500)',
                    '600' => 'Semi Bold (600)',
                    '700' => 'Bold (700)',
                    '800' => 'Extra Bold (800)',
                    '900' => 'Black (900)',
                ],
            ];
            if ( $active_callback ) { $font_weight_args['active_callback'] = $active_callback; }
            $wp_customize->add_control( "{$prefix}_font_weight", $font_weight_args );

            $wp_customize->add_setting( "{$prefix}_font_style", [
                'default'           => 'normal',
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
            ] );
            $font_style_args = [
                'type'    => 'select',
                'section' => $section_id,
                'label'   => __( 'Font Style', 'aurora-lite' ),
                'choices' => [
                    'normal'  => __( 'Normal', 'aurora-lite' ),
                    'italic'  => __( 'Italic', 'aurora-lite' ),
                    'oblique' => __( 'Oblique', 'aurora-lite' ),
                ],
            ];
            if ( $active_callback ) { $font_style_args['active_callback'] = $active_callback; }
            $wp_customize->add_control( "{$prefix}_font_style", $font_style_args );

            $wp_customize->add_setting( "{$prefix}_text_decoration", [
                'default'           => 'none',
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
            ] );
            $text_decoration_args = [
                'type'    => 'select',
                'section' => $section_id,
                'label'   => __( 'Text Decoration', 'aurora-lite' ),
                'choices' => [
                    'none'         => __( 'None', 'aurora-lite' ),
                    'underline'    => __( 'Underline', 'aurora-lite' ),
                    'overline'     => __( 'Overline', 'aurora-lite' ),
                    'line-through' => __( 'Line Through', 'aurora-lite' ),
                ],
            ];
            if ( $active_callback ) { $text_decoration_args['active_callback'] = $active_callback; }
            $wp_customize->add_control( "{$prefix}_text_decoration", $text_decoration_args );
        }

        $wp_customize->add_panel('aurora_lite_fonts_panel', [
            'title' => __('Typography', 'aurora-lite'),
            'priority' => 30,
        ]);

        function aurora_lite_sel_heading($heading) {
            return get_theme_mod('aurora_lite_fonts_heading_selector', 'h1') === $heading;
        }

        $wp_customize->add_section('aurora_lite_fonts_headings_section', [
            'title'    => __('Headings', 'aurora-lite'),
            'priority' => 0,
            'panel'    => 'aurora_lite_fonts_panel',
        ]);

        $wp_customize->add_setting('aurora_lite_fonts_heading_selector', [
            'default'           => 'h1',
            'transport'         => 'refresh',
            'sanitize_callback' => 'sanitize_text_field',
        ]);

        $wp_customize->add_control('aurora_lite_fonts_heading_selector', [
            'type'    => 'select',
            'section' => 'aurora_lite_fonts_headings_section',
            'label'   => __('Select Heading to Edit', 'aurora-lite'),
            'choices' => [
                'h1' => __('H1', 'aurora-lite'),
                'h2' => __('H2', 'aurora-lite'),
                'h3' => __('H3', 'aurora-lite'),
                'h4' => __('H4', 'aurora-lite'),
                'h5' => __('H5', 'aurora-lite'),
                'h6' => __('H6', 'aurora-lite'),
            ],
        ]);

        $headings = ['h1','h2','h3','h4','h5','h6'];

        foreach ($headings as $heading) {
            aurora_lite_add_typography_controls(
                $wp_customize,
                'aurora_lite_fonts_headings_section',
                "aurora_lite_fonts_{$heading}",
                $font_choices,
                [
                    'active_callback' => function() use ($heading) {
                        return aurora_lite_sel_heading($heading);
                    },
                    'default_weight' => '600',
                ]
            );
        }


        $wp_customize->add_section('aurora_lite_fonts_menu_section', [
            'title' => __('Menu Font', 'aurora-lite'),
            'panel' => 'aurora_lite_fonts_panel',
            'priority' => 10
        ]);

        aurora_lite_add_typography_controls(
            $wp_customize,
            'aurora_lite_fonts_menu_section',
            'aurora_lite_fonts_menu',
            $font_choices
        );

        $wp_customize->add_section('aurora_lite_fonts_body_section', [
            'title' => __('Body Font', 'aurora-lite'),
            'panel' => 'aurora_lite_fonts_panel',
            'priority' => 5,
        ]);

        aurora_lite_add_typography_controls(
            $wp_customize,
            'aurora_lite_fonts_body_section',
            'aurora_lite_fonts_body',
            $font_choices
        );

        $wp_customize->add_section('aurora_lite_fonts_buttons_section', [
            'title' => __('Button Font', 'aurora-lite'),
            'panel' => 'aurora_lite_fonts_panel',
            'priority' => 15
        ]);

        aurora_lite_add_typography_controls(
            $wp_customize,
            'aurora_lite_fonts_buttons_section',
            'aurora_lite_fonts_buttons',
            $font_choices,
            ['default_weight' => '500']
        );

        $wp_customize->add_section('aurora_lite_general_settings', [
            'title'       => __('General Settings', 'aurora-lite'),
            'description' => __('Manage various general settings', 'aurora-lite'),
            'priority'    => 10,
        ]);

        $wp_customize->add_setting( 'aurora_lite_site_width', array(
            'default'   => 1300,
            'transport' => 'postMessage',
            'sanitize_callback' => 'absint',
        ));

        $wp_customize->add_control( 
            new WP_Customize_Control( 
                $wp_customize, 
                'aurora_lite_site_width_control', 
                array(
                    'label'    => __( 'Site Width (in px)', 'aurora-lite' ), 
                    'section'  => 'aurora_lite_general_settings',
                    'settings' => 'aurora_lite_site_width',
                    'type'     => 'number',
                    'input_attrs' => array(
                        'min'  => 800,
                        'max'  => 1920,
                        'step' => 10,
                    ),
                )
            )
        );

        $wp_customize->add_setting('aurora_lite_date_format', array(
            'default' => 'M j, Y',
            'sanitize_callback' => 'sanitize_text_field',
        ));

        $wp_customize->add_control('aurora_lite_date_format', array(
            'label' => __('Date Format', 'aurora-lite'),
            'section' => 'aurora_lite_general_settings',
            'type' => 'select',
            'choices' => array(
                'F j, Y'     => wp_date('F j, Y'),
                'Y-m-d'      => wp_date('Y-m-d'),
                'm/d/Y'      => wp_date('m/d/Y'),
                'd/m/Y'      => wp_date('d/m/Y'),
                'M j, Y'     => wp_date('M j, Y'),
                'D, M j'     => wp_date('D, M j'),
                'custom'     => __('Custom', 'aurora-lite'),
            ),
        ));

        $wp_customize->add_setting('aurora_lite_custom_date_format', array(
            'default' => 'j F Y',
            'sanitize_callback' => 'sanitize_text_field',
        ));

        $wp_customize->add_control('aurora_lite_custom_date_format', array(
            'label'       => __( 'Custom Date Format', 'aurora-lite' ),
            'section'     => 'aurora_lite_general_settings',
            'type'        => 'text',
            'description' => sprintf(
                /* translators: %1$s: example date output e.g. "1 January 2025", %2$s: URL to PHP date format documentation */
                __( 'Use PHP date() format. Example: <code>j F Y</code> = %1$s.<br><a href="%2$s" target="_blank" rel="noopener noreferrer">See supported formats</a>', 'aurora-lite' ),
                wp_date( 'j F Y' ),
                esc_url( 'https://www.php.net/manual/en/datetime.format.php' )
            ),
            'active_callback' => fn() => aurora_lite_callback( 'aurora_lite_date_format', ['custom'] ),
        ));

        $wp_customize->add_setting( 'aurora_lite_general_upgrade_notice', [
            'sanitize_callback' => '__return_false',
        ] );

        $wp_customize->add_control( new Aurora_Lite_Upgrade_Control( $wp_customize, 'aurora_lite_general_upgrade_notice', [
            'section'      => 'aurora_lite_general_settings',
            'upgrade_text' => 'Upgrade to Pro to unlock an additional content section for your site. Particularly useful for custom content or newsletter embed. Instant switch, no demo import needed.',
        ] ) );

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