<?php
function howcan_slider_customizer( $wp_customize ) {

    // === Slider Section ===
    $wp_customize->add_section( 'howcan_slider_section', array(
        'title'    => __( 'Homepage Slider', 'howcan' ),
        'priority' => 10,
        'panel'    => 'howcan_theme_options_panel',
    ) );

    // === Loop for 3 Slides ===
    for ( $i = 1; $i <= 3; $i++ ) {

        // === Slide Image ===
        $wp_customize->add_setting( "howcan_slider_image_$i", array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        ) );

        $wp_customize->add_control( new WP_Customize_Image_Control( $wp_customize, "howcan_slider_image_$i", array(
            'label'   => sprintf( __( 'Slide %d Image', 'howcan' ), $i ),
            'section' => 'howcan_slider_section',
        ) ) );

        // === Slide Title ===
        $wp_customize->add_setting( "howcan_slider_title_$i", array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        ) );

        $wp_customize->add_control( "howcan_slider_title_$i", array(
            'label'   => sprintf( __( 'Slide %d Title', 'howcan' ), $i ),
            'section' => 'howcan_slider_section',
            'type'    => 'text',
        ) );

        // === Slide Subtitle ===
        $wp_customize->add_setting( "howcan_slider_subtitle_$i", array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        ) );

        $wp_customize->add_control( "howcan_slider_subtitle_$i", array(
            'label'   => sprintf( __( 'Slide %d Subtitle', 'howcan' ), $i ),
            'section' => 'howcan_slider_section',
            'type'    => 'text',
        ) );

        // === Slide Button Text ===
        $wp_customize->add_setting( "howcan_slider_btn_text_$i", array(
            'default'           => '',
            'sanitize_callback' => 'sanitize_text_field',
        ) );

        $wp_customize->add_control( "howcan_slider_btn_text_$i", array(
            'label'   => sprintf( __( 'Slide %d Button Text', 'howcan' ), $i ),
            'section' => 'howcan_slider_section',
            'type'    => 'text',
        ) );

        // === Slide Button Link ===
        $wp_customize->add_setting( "howcan_slider_btn_link_$i", array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        ) );

        $wp_customize->add_control( "howcan_slider_btn_link_$i", array(
            'label'   => sprintf( __( 'Slide %d Button Link', 'howcan' ), $i ),
            'section' => 'howcan_slider_section',
            'type'    => 'url',
        ) );
    }
}
add_action( 'customize_register', 'howcan_slider_customizer' );