<?php
/**
 * Theme Setup
 *
 * @package HomeProz
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

/**
 * Sets up theme defaults and registers support for various WordPress features.
 */
function homeproz_setup() {
    // Add default posts and comments RSS feed links to head
    add_theme_support('automatic-feed-links');

    // Let WordPress manage the document title
    add_theme_support('title-tag');

    // Enable support for Post Thumbnails on posts and pages
    add_theme_support('post-thumbnails');

    // Custom image sizes
    add_image_size('property-card', 640, 400, true);      // 16:10 ratio for property cards
    add_image_size('property-gallery', 1200, 800, true);  // Gallery images
    add_image_size('agent-photo', 400, 400, true);        // Square agent photos

    // Register navigation menus
    register_nav_menus(array(
        'primary'   => esc_html__('Primary Menu', 'homeproz'),
        'footer'    => esc_html__('Footer Menu', 'homeproz'),
    ));

    // Switch default core markup to output valid HTML5
    add_theme_support('html5', array(
        'search-form',
        'comment-form',
        'comment-list',
        'gallery',
        'caption',
        'style',
        'script',
    ));

    // Add support for block styles
    add_theme_support('wp-block-styles');

    // Add support for responsive embeds
    add_theme_support('responsive-embeds');

    // Add support for editor styles
    add_theme_support('editor-styles');

    // Add support for custom logo
    add_theme_support('custom-logo', array(
        'height'      => 100,
        'width'       => 300,
        'flex-height' => true,
        'flex-width'  => true,
    ));

    // Disable core block patterns (we'll add our own)
    remove_theme_support('core-block-patterns');
}
add_action('after_setup_theme', 'homeproz_setup');

/**
 * Register widget areas
 */
function homeproz_widgets_init() {
    register_sidebar(array(
        'name'          => esc_html__('Blog Sidebar', 'homeproz'),
        'id'            => 'sidebar-blog',
        'description'   => esc_html__('Widgets for the blog sidebar.', 'homeproz'),
        'before_widget' => '<section id="%1$s" class="widget %2$s">',
        'after_widget'  => '</section>',
        'before_title'  => '<h3 class="widget-title">',
        'after_title'   => '</h3>',
    ));

    register_sidebar(array(
        'name'          => esc_html__('Footer Column 1', 'homeproz'),
        'id'            => 'footer-1',
        'description'   => esc_html__('First footer widget area.', 'homeproz'),
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h4 class="widget-title">',
        'after_title'   => '</h4>',
    ));

    register_sidebar(array(
        'name'          => esc_html__('Footer Column 2', 'homeproz'),
        'id'            => 'footer-2',
        'description'   => esc_html__('Second footer widget area.', 'homeproz'),
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h4 class="widget-title">',
        'after_title'   => '</h4>',
    ));

    register_sidebar(array(
        'name'          => esc_html__('Footer Column 3', 'homeproz'),
        'id'            => 'footer-3',
        'description'   => esc_html__('Third footer widget area.', 'homeproz'),
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget'  => '</div>',
        'before_title'  => '<h4 class="widget-title">',
        'after_title'   => '</h4>',
    ));
}
add_action('widgets_init', 'homeproz_widgets_init');
