<?php
/**
 * Theme Customizer
 *
 * @package Navier_Instruments
 */

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

/**
 * Add customizer options
 */
function navier_customize_register($wp_customize) {

    // ===========================================
    // SECTION: Header Settings
    // ===========================================
    $wp_customize->add_section('navier_header_section', array(
        'title'    => __('Header Settings', 'navier-instruments'),
        'priority' => 30,
    ));

    // Header CTA Text
    $wp_customize->add_setting('navier_header_cta_text', array(
        'default'           => __('Contact Us', 'navier-instruments'),
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'refresh',
    ));
    $wp_customize->add_control('navier_header_cta_text', array(
        'label'   => __('Header CTA Button Text', 'navier-instruments'),
        'section' => 'navier_header_section',
        'type'    => 'text',
    ));

    // Header CTA Link
    $wp_customize->add_setting('navier_header_cta_link', array(
        'default'           => '#contact',
        'sanitize_callback' => 'esc_url_raw',
        'transport'         => 'refresh',
    ));
    $wp_customize->add_control('navier_header_cta_link', array(
        'label'   => __('Header CTA Button Link', 'navier-instruments'),
        'section' => 'navier_header_section',
        'type'    => 'url',
    ));

    // ===========================================
    // SECTION: Hero Section
    // ===========================================
    $wp_customize->add_section('navier_hero_section', array(
        'title'    => __('Hero Section', 'navier-instruments'),
        'priority' => 31,
    ));

    // Hero Badge
    $wp_customize->add_setting('navier_hero_badge', array(
        'default'           => __('Eco-Responsible Innovation', 'navier-instruments'),
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('navier_hero_badge', array(
        'label'   => __('Hero Badge Text', 'navier-instruments'),
        'section' => 'navier_hero_section',
        'type'    => 'text',
    ));

    // Hero Title
    $wp_customize->add_setting('navier_hero_title', array(
        'default'           => __('Excellence in <span>Air Sampling</span> Technology', 'navier-instruments'),
        'sanitize_callback' => 'wp_kses_post',
    ));
    $wp_customize->add_control('navier_hero_title', array(
        'label'       => __('Hero Title (use <span> for highlight)', 'navier-instruments'),
        'section'     => 'navier_hero_section',
        'type'        => 'textarea',
    ));

    // Hero Description
    $wp_customize->add_setting('navier_hero_description', array(
        'default'           => __('Navier Instruments designs and manufactures innovative air sampling solutions for industrial and laboratory environments.', 'navier-instruments'),
        'sanitize_callback' => 'sanitize_textarea_field',
    ));
    $wp_customize->add_control('navier_hero_description', array(
        'label'   => __('Hero Description', 'navier-instruments'),
        'section' => 'navier_hero_section',
        'type'    => 'textarea',
    ));

    // Hero Image
    $wp_customize->add_setting('navier_hero_image', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'navier_hero_image', array(
        'label'   => __('Hero Image', 'navier-instruments'),
        'section' => 'navier_hero_section',
    )));

    // Hero CTA 1
    $wp_customize->add_setting('navier_hero_cta1_text', array(
        'default'           => __('Discover Our Products', 'navier-instruments'),
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('navier_hero_cta1_text', array(
        'label'   => __('Primary CTA Text', 'navier-instruments'),
        'section' => 'navier_hero_section',
        'type'    => 'text',
    ));

    $wp_customize->add_setting('navier_hero_cta1_link', array(
        'default'           => '#products',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control('navier_hero_cta1_link', array(
        'label'   => __('Primary CTA Link', 'navier-instruments'),
        'section' => 'navier_hero_section',
        'type'    => 'url',
    ));

    // Hero CTA 2
    $wp_customize->add_setting('navier_hero_cta2_text', array(
        'default'           => __('Contact Us', 'navier-instruments'),
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('navier_hero_cta2_text', array(
        'label'   => __('Secondary CTA Text', 'navier-instruments'),
        'section' => 'navier_hero_section',
        'type'    => 'text',
    ));

    $wp_customize->add_setting('navier_hero_cta2_link', array(
        'default'           => '#contact',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control('navier_hero_cta2_link', array(
        'label'   => __('Secondary CTA Link', 'navier-instruments'),
        'section' => 'navier_hero_section',
        'type'    => 'url',
    ));

    // Hero Stats
    for ($i = 1; $i <= 3; $i++) {
        $wp_customize->add_setting("navier_stat_{$i}_value", array(
            'default'           => $i === 1 ? '25+' : ($i === 2 ? '500+' : '100%'),
            'sanitize_callback' => 'sanitize_text_field',
        ));
        $wp_customize->add_control("navier_stat_{$i}_value", array(
            'label'   => sprintf(__('Stat %d Value', 'navier-instruments'), $i),
            'section' => 'navier_hero_section',
            'type'    => 'text',
        ));

        $wp_customize->add_setting("navier_stat_{$i}_label", array(
            'default'           => $i === 1 ? __('Years of Experience', 'navier-instruments') : ($i === 2 ? __('Clients Worldwide', 'navier-instruments') : __('Made in France', 'navier-instruments')),
            'sanitize_callback' => 'sanitize_text_field',
        ));
        $wp_customize->add_control("navier_stat_{$i}_label", array(
            'label'   => sprintf(__('Stat %d Label', 'navier-instruments'), $i),
            'section' => 'navier_hero_section',
            'type'    => 'text',
        ));
    }

    // ===========================================
    // SECTION: About Section
    // ===========================================
    $wp_customize->add_section('navier_about_section', array(
        'title'    => __('About Section', 'navier-instruments'),
        'priority' => 32,
    ));

    $wp_customize->add_setting('navier_about_title', array(
        'default'           => __('Pioneers in Air Sampling Technology', 'navier-instruments'),
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('navier_about_title', array(
        'label'   => __('About Title', 'navier-instruments'),
        'section' => 'navier_about_section',
        'type'    => 'text',
    ));

    $wp_customize->add_setting('navier_about_text', array(
        'default'           => __('Based in Senlis, France, Navier Instruments has been at the forefront of air sampling technology for over two decades.', 'navier-instruments'),
        'sanitize_callback' => 'sanitize_textarea_field',
    ));
    $wp_customize->add_control('navier_about_text', array(
        'label'   => __('About Text', 'navier-instruments'),
        'section' => 'navier_about_section',
        'type'    => 'textarea',
    ));

    $wp_customize->add_setting('navier_about_image', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw',
    ));
    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'navier_about_image', array(
        'label'   => __('About Image', 'navier-instruments'),
        'section' => 'navier_about_section',
    )));

    $wp_customize->add_setting('navier_about_badge_value', array(
        'default'           => '25+',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('navier_about_badge_value', array(
        'label'   => __('Badge Value', 'navier-instruments'),
        'section' => 'navier_about_section',
        'type'    => 'text',
    ));

    $wp_customize->add_setting('navier_about_badge_label', array(
        'default'           => __('Years of Excellence', 'navier-instruments'),
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('navier_about_badge_label', array(
        'label'   => __('Badge Label', 'navier-instruments'),
        'section' => 'navier_about_section',
        'type'    => 'text',
    ));

    // ===========================================
    // SECTION: Contact Information
    // ===========================================
    $wp_customize->add_section('navier_contact_section', array(
        'title'    => __('Contact Information', 'navier-instruments'),
        'priority' => 33,
    ));

    $wp_customize->add_setting('navier_contact_address', array(
        'default'           => 'Senlis, Oise 60300, France',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('navier_contact_address', array(
        'label'   => __('Address', 'navier-instruments'),
        'section' => 'navier_contact_section',
        'type'    => 'text',
    ));

    $wp_customize->add_setting('navier_phone', array(
        'default'           => '+33 3 44 00 00 00',
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('navier_phone', array(
        'label'   => __('Phone', 'navier-instruments'),
        'section' => 'navier_contact_section',
        'type'    => 'text',
    ));

    $wp_customize->add_setting('navier_email', array(
        'default'           => 'contact@navier-instruments.com',
        'sanitize_callback' => 'sanitize_email',
    ));
    $wp_customize->add_control('navier_email', array(
        'label'   => __('Email', 'navier-instruments'),
        'section' => 'navier_contact_section',
        'type'    => 'email',
    ));

    $wp_customize->add_setting('navier_hours', array(
        'default'           => __('Mon - Fri: 9:00 - 18:00', 'navier-instruments'),
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control('navier_hours', array(
        'label'   => __('Business Hours', 'navier-instruments'),
        'section' => 'navier_contact_section',
        'type'    => 'text',
    ));

    // ===========================================
    // SECTION: Social Media
    // ===========================================
    $wp_customize->add_section('navier_social_section', array(
        'title'    => __('Social Media', 'navier-instruments'),
        'priority' => 34,
    ));

    $social_networks = array('linkedin', 'twitter', 'facebook', 'youtube', 'instagram');

    foreach ($social_networks as $network) {
        $wp_customize->add_setting("navier_{$network}", array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
        ));
        $wp_customize->add_control("navier_{$network}", array(
            'label'   => ucfirst($network) . ' URL',
            'section' => 'navier_social_section',
            'type'    => 'url',
        ));
    }

    // ===========================================
    // SECTION: Footer Settings
    // ===========================================
    $wp_customize->add_section('navier_footer_section', array(
        'title'    => __('Footer Settings', 'navier-instruments'),
        'priority' => 35,
    ));

    $wp_customize->add_setting('navier_footer_description', array(
        'default'           => __('Spécialiste du prélèvement d\'air en milieu industriel et laboratoire. Innovation, qualité et éco-responsabilité au service de votre santé.', 'navier-instruments'),
        'sanitize_callback' => 'sanitize_textarea_field',
    ));
    $wp_customize->add_control('navier_footer_description', array(
        'label'   => __('Footer Description', 'navier-instruments'),
        'section' => 'navier_footer_section',
        'type'    => 'textarea',
    ));
}
add_action('customize_register', 'navier_customize_register');

/**
 * Customizer live preview
 */
function navier_customize_preview_js() {
    wp_enqueue_script(
        'navier-customizer',
        NAVIER_URI . '/assets/js/customizer.js',
        array('customize-preview'),
        NAVIER_VERSION,
        true
    );
}
add_action('customize_preview_init', 'navier_customize_preview_js');
