<?php

function municipio_setup() {
    load_theme_textdomain( 'municipio', get_template_directory() . '/languages' );
    add_theme_support( 'title-tag' );
    add_theme_support( 'post-thumbnails' );
    add_theme_support( 'custom-logo', [
        'height'      => 80,
        'width'       => 240,
        'flex-height' => true,
        'flex-width'  => true,
    ] );
    add_theme_support( 'html5', [ 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', 'style', 'script' ] );

    register_nav_menus( [
        'primary' => __( 'Primary Menu', 'municipio' ),
        'footer'  => __( 'Footer Menu', 'municipio' ),
    ] );
}
add_action( 'after_setup_theme', 'municipio_setup' );

function municipio_enqueue_assets() {
    wp_enqueue_style(
        'municipio-fonts',
        'https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Playfair+Display:ital,wght@1,600&display=swap',
        [],
        null
    );
    wp_enqueue_style( 'municipio-main', get_template_directory_uri() . '/assets/css/main.css', [ 'municipio-fonts' ], '1.0.0' );
    wp_enqueue_script( 'municipio-main', get_template_directory_uri() . '/assets/js/main.js', [], '1.0.0', true );
}
add_action( 'wp_enqueue_scripts', 'municipio_enqueue_assets' );

function municipio_register_cpts() {
    register_post_type( 'carousel_slide', [
        'labels'        => [
            'name'          => __( 'Carousel Slides', 'municipio' ),
            'singular_name' => __( 'Carousel Slide', 'municipio' ),
            'add_new_item'  => __( 'Add New Slide', 'municipio' ),
            'edit_item'     => __( 'Edit Slide', 'municipio' ),
        ],
        'public'        => false,
        'show_ui'       => true,
        'show_in_menu'  => true,
        'supports'      => [ 'title', 'thumbnail', 'page-attributes' ],
        'menu_icon'     => 'dashicons-images-alt2',
        'rewrite'       => false,
    ] );
}
add_action( 'init', 'municipio_register_cpts' );

function municipio_customizer( $wp_customize ) {
    $wp_customize->add_section( 'municipio_landing', [
        'title'    => __( 'Landing Page', 'municipio' ),
        'priority' => 30,
    ] );

    $wp_customize->add_setting( 'municipio_quote_title', [
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ] );
    $wp_customize->add_control( 'municipio_quote_title', [
        'label'   => __( 'Heading', 'municipio' ),
        'section' => 'municipio_landing',
        'type'    => 'text',
    ] );

    $wp_customize->add_setting( 'municipio_quote_text', [
        'default'           => '',
        'sanitize_callback' => 'sanitize_textarea_field',
        'transport'         => 'postMessage',
    ] );
    $wp_customize->add_control( 'municipio_quote_text', [
        'label'   => __( 'Quote / Subtitle', 'municipio' ),
        'section' => 'municipio_landing',
        'type'    => 'textarea',
    ] );

    $wp_customize->add_setting( 'municipio_map_shortcode', [
        'default'           => '',
        'sanitize_callback' => 'wp_kses_post',
    ] );
    $wp_customize->add_control( 'municipio_map_shortcode', [
        'label'       => __( 'Map Shortcode', 'municipio' ),
        'description' => __( 'Paste the shortcode from your map plugin, e.g. [my_map]', 'municipio' ),
        'section'     => 'municipio_landing',
        'type'        => 'text',
    ] );

    $wp_customize->add_setting( 'municipio_map_heading', [
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
    ] );
    $wp_customize->add_control( 'municipio_map_heading', [
        'label'   => __( 'Map Section Heading', 'municipio' ),
        'section' => 'municipio_landing',
        'type'    => 'text',
    ] );

    $wp_customize->add_section( 'municipio_footer_section', [
        'title'    => __( 'Footer', 'municipio' ),
        'priority' => 40,
    ] );

    $wp_customize->add_setting( 'municipio_footer_text', [
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
    ] );
    $wp_customize->add_control( 'municipio_footer_text', [
        'label'       => __( 'Footer Copyright Text', 'municipio' ),
        'description' => __( 'Leave blank to auto-generate.', 'municipio' ),
        'section'     => 'municipio_footer_section',
        'type'        => 'text',
    ] );
}
add_action( 'customize_register', 'municipio_customizer' );
