<?php
/**
 * Customizer: Footer Settings Section
 *
 * @package Paws_And_Care
 * @since 1.2.9
 */

if (!defined('ABSPATH')) {
    exit;
}

/**
 * Register Footer Settings Section
 *
 * @param WP_Customize_Manager $wp_customize Customizer object.
 */
function paws_and_care_customizer_footer($wp_customize)
{
    // ========================================
    // Footer Section (inside Theme Settings panel)
    // ========================================
    $wp_customize->add_section('paws_and_care_footer', array(
        'title' => __('Footer Settings', 'paws-and-care'),
        'panel' => 'paws_and_care_theme_settings',
        'priority' => 40,
    ));

    // Footer Widget Columns
    $wp_customize->add_setting('paws_and_care_footer_columns', array(
        'default' => '4',
        'sanitize_callback' => 'absint',
    ));
    $wp_customize->add_control('paws_and_care_footer_columns', array(
        'label' => __('Footer Widget Columns', 'paws-and-care'),
        'description' => __('Select number of widget columns in footer.', 'paws-and-care'),
        'section' => 'paws_and_care_footer',
        'type' => 'select',
        'choices' => array(
            '1' => __('1 Column', 'paws-and-care'),
            '2' => __('2 Columns', 'paws-and-care'),
            '3' => __('3 Columns', 'paws-and-care'),
            '4' => __('4 Columns', 'paws-and-care'),
        ),
    ));

    // Copyright Text
    $wp_customize->add_setting('paws_and_care_copyright', array(
        'default'           => '© {year} {site_name}. All Rights Reserved.',
        'sanitize_callback' => 'paws_and_care_sanitize_copyright',
        'transport'         => 'refresh',
    ));
    $wp_customize->add_control(
        'paws_and_care_copyright',
        array(
            'label'       => __( 'Copyright Text', 'paws-and-care' ),
            'description' => __( 'Use {year} for current year, {site_name} for site name. HTML allowed.', 'paws-and-care' ),
            'section'     => 'paws_and_care_footer',
            'type'        => 'textarea',
        )
    );
}

/**
 * Sanitize copyright text
 */
function paws_and_care_sanitize_copyright( $input ) {

    $allowed_tags = array(
        'a'      => array(
            'href'   => array(),
            'title'  => array(),
            'target' => array(),
            'rel'    => array(),
        ),
        'br'     => array(),
        'em'     => array(),
        'strong' => array(),
        'span'   => array(
            'class' => array(),
        ),
        'p'      => array(),
    );

    // Keep tokens usable, but strip disallowed HTML/attrs
    $input = wp_kses( $input, $allowed_tags );

    return $input;
}

