<?php
/**
 * Rush Passport & Visa — Theme Functions
 */

// Load Google Fonts + theme styles
function rush_enqueue_assets() {
    wp_enqueue_style('google-fonts', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&display=swap', [], null);
    wp_enqueue_style('rush-passport-style', get_stylesheet_uri(), ['google-fonts'], '1.0.0');
    wp_enqueue_script('rush-passport-js', get_template_directory_uri() . '/js/main.js', [], '1.0.0', true);
}
add_action('wp_enqueue_scripts', 'rush_enqueue_assets');

// Theme support
function rush_theme_setup() {
    add_theme_support('title-tag');
    add_theme_support('post-thumbnails');
    add_theme_support('html5', ['search-form', 'comment-form', 'comment-list', 'gallery', 'caption']);
    add_theme_support('customize-selective-refresh-widgets');
    register_nav_menus(['primary' => 'Primary Menu']);
}
add_action('after_setup_theme', 'rush_theme_setup');

// Register City custom post type for multi-city template
function rush_register_post_types() {
    register_post_type('city', [
        'labels' => [
            'name'          => 'Cities',
            'singular_name' => 'City',
            'add_new_item'  => 'Add New City',
        ],
        'public'       => true,
        'has_archive'  => true,
        'show_in_rest' => true,
        'supports'     => ['title', 'editor', 'thumbnail', 'custom-fields'],
        'rewrite'      => ['slug' => 'locations'],
        'menu_icon'    => 'dashicons-location-alt',
    ]);
}
add_action('init', 'rush_register_post_types');

// Theme Customizer — city-swappable settings
function rush_customizer_settings($wp_customize) {
    // Panel
    $wp_customize->add_panel('rush_settings', [
        'title'    => 'Rush Passport Settings',
        'priority' => 10,
    ]);

    // ── CONTACT INFO ──
    $wp_customize->add_section('rush_contact', [
        'title' => 'Contact Info',
        'panel' => 'rush_settings',
    ]);
    $fields = [
        'rush_phone'        => 'Phone Number (display)',
        'rush_phone_link'   => 'Phone Number (tel: link, digits only)',
        'rush_hours_short'  => 'Hours (short, for header)',
        'rush_hours_full'   => 'Hours (full, for footer/office)',
        'rush_address'      => 'Street Address',
        'rush_city_state'   => 'City, State ZIP',
        'rush_map_embed'    => 'Google Maps Embed URL',
    ];
    foreach ($fields as $key => $label) {
        $wp_customize->add_setting($key, ['default' => '', 'sanitize_callback' => 'sanitize_text_field']);
        $wp_customize->add_control($key, ['label' => $label, 'section' => 'rush_contact', 'type' => 'text']);
    }

    // ── HERO ──
    $wp_customize->add_section('rush_hero', [
        'title' => 'Hero Section',
        'panel' => 'rush_settings',
    ]);
    $wp_customize->add_setting('rush_city_name', ['default' => 'New York', 'sanitize_callback' => 'sanitize_text_field']);
    $wp_customize->add_control('rush_city_name', ['label' => "City Name (e.g. 'New York')", 'section' => 'rush_hero', 'type' => 'text']);
    $wp_customize->add_setting('rush_hero_subhead', ['default' => "Same-day appointments available. Walk-ins welcome.", 'sanitize_callback' => 'sanitize_text_field']);
    $wp_customize->add_control('rush_hero_subhead', ['label' => 'Hero Subheadline', 'section' => 'rush_hero', 'type' => 'text']);
    $wp_customize->add_setting('rush_hero_image', ['default' => '', 'sanitize_callback' => 'esc_url_raw']);
    $wp_customize->add_control(new WP_Customize_Image_Control($wp_customize, 'rush_hero_image', ['label' => 'Hero Office Photo', 'section' => 'rush_hero']));

    // ── PRICING ──
    $wp_customize->add_section('rush_pricing', [
        'title' => 'Pricing',
        'panel' => 'rush_settings',
    ]);
    $pricing_fields = [
        'rush_price_emergency' => 'Emergency Price (e.g. $349)',
        'rush_price_rush'      => 'Rush Price (e.g. $249)',
        'rush_price_expedited' => 'Expedited Price (e.g. $149)',
        'rush_price_visa'      => 'Visa Price (e.g. From $149)',
    ];
    foreach ($pricing_fields as $key => $label) {
        $wp_customize->add_setting($key, ['default' => '', 'sanitize_callback' => 'sanitize_text_field']);
        $wp_customize->add_control($key, ['label' => $label, 'section' => 'rush_pricing', 'type' => 'text']);
    }

    // ── URGENCY BAR ──
    $wp_customize->add_section('rush_urgency', [
        'title' => 'Urgency Bar',
        'panel' => 'rush_settings',
    ]);
    $wp_customize->add_setting('rush_urgency_text', ['default' => 'Standard government processing takes 6–8 weeks. We get your passport in 24 hours.', 'sanitize_callback' => 'sanitize_text_field']);
    $wp_customize->add_control('rush_urgency_text', ['label' => 'Urgency Bar Text', 'section' => 'rush_urgency', 'type' => 'text']);
}
add_action('customize_register', 'rush_customizer_settings');

// Helper: get theme mod with fallback
function rush_get($key, $fallback = '') {
    return get_theme_mod($key, $fallback) ?: $fallback;
}
