<?php if (!defined('ABSPATH')) exit; ?>
<?php
/**
 * Minimal - Single Property Template
 *
 * Large serif-style headings (--ipp-font-heading). Clean, magazine-like layout.
 * Single column, max-width 800px centered. Gallery as a clean image strip.
 * Details in a two-column grid. Minimal decoration.
 *
 * @package Integrate_Palace_Properties
 */

$prop   = new IPP_Property_Helper(get_the_ID());
$images = $prop->gallery_images('large');
?>

<?php echo $prop->schema_json_ld(); ?>

<div class="ipp-single ipp-single--minimal" style="max-width:800px;margin:0 auto;padding:2rem 1rem;">

    <!-- Header -->
    <header style="margin-bottom:2.5rem;text-align:center;">
        <?php if ($prop->show('status') && $prop->status()) : ?>
            <span class="ipp-badge <?php echo strtolower($prop->status()) === 'active' ? 'ipp-badge--active' : 'ipp-badge--inactive'; ?>" style="margin-bottom:1rem;display:inline-block;">
                <?php echo esc_html($prop->status()); ?>
            </span>
        <?php endif; ?>

        <h1 style="font-family:var(--ipp-font-heading,Georgia,serif);font-size:2.5rem;font-weight:400;line-height:1.2;margin:0 0 0.5rem;">
            <?php echo esc_html(get_the_title()); ?>
        </h1>

        <?php if ($prop->show('address') && $prop->full_address()) : ?>
            <p style="color:var(--ipp-color-gray-500,#6b7280);font-size:1.0625rem;margin:0 0 1rem;">
                <?php echo esc_html($prop->full_address()); ?>
            </p>
        <?php endif; ?>

        <?php if ($prop->show('rent') && $prop->formatted_rent()) : ?>
            <p style="font-size:1.75rem;font-weight:600;color:var(--ipp-color-primary,#2563eb);margin:0;">
                <?php echo esc_html($prop->formatted_rent()); ?>
                <?php if ($prop->rental_period()) : ?>
                    <span style="font-size:0.9375rem;font-weight:400;color:var(--ipp-color-gray-400,#9ca3af);">/ <?php echo esc_html($prop->rental_period()); ?></span>
                <?php endif; ?>
            </p>
        <?php endif; ?>

        <div class="ipp-card__meta" style="justify-content:center;margin-top:1.25rem;">
            <?php if ($prop->show('bedrooms') && $prop->bedrooms()) : ?>
                <span class="ipp-card__meta-item" aria-label="<?php echo esc_attr($prop->bedrooms()); ?> bedrooms">
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M3 7v11a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2V7"/><path d="M21 11H3V9a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v2z"/><path d="M7 7V5a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v2"/></svg>
                    <?php echo esc_html($prop->bedrooms()); ?> Bed
                </span>
            <?php endif; ?>
            <?php if ($prop->show('bathrooms') && $prop->bathrooms()) : ?>
                <span class="ipp-card__meta-item" aria-label="<?php echo esc_attr($prop->bathrooms()); ?> bathrooms">
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M4 12h16a1 1 0 0 1 1 1v3a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4v-3a1 1 0 0 1 1-1z"/><path d="M6 12V5a2 2 0 0 1 2-2h1"/></svg>
                    <?php echo esc_html($prop->bathrooms()); ?> Bath
                </span>
            <?php endif; ?>
            <?php if ($prop->show('cars') && $prop->cars()) : ?>
                <span class="ipp-card__meta-item" aria-label="<?php echo esc_attr($prop->cars()); ?> car spaces">
                    <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M5 17h14M5 17a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1l2-3h8l2 3h1a2 2 0 0 1 2 2v6a2 2 0 0 1-2 2"/><circle cx="7.5" cy="15.5" r="1.5"/><circle cx="16.5" cy="15.5" r="1.5"/></svg>
                    <?php echo esc_html($prop->cars()); ?> Car
                </span>
            <?php endif; ?>
        </div>
    </header>

    <!-- Gallery Strip -->
    <?php if (!empty($images)) : ?>
    <div class="ipp-single__gallery ipp-gallery" style="margin-bottom:2.5rem;" aria-label="Property gallery">
        <div class="ipp-gallery__main">
            <img id="ipp-gallery-main-img"
                 src="<?php echo esc_url($images[0]['url']); ?>"
                 alt="<?php echo esc_attr($images[0]['alt'] ?: $prop->name()); ?>"
                 style="width:100%;aspect-ratio:16/9;object-fit:cover;border-radius:var(--ipp-radius,4px);">
        </div>
        <?php if (count($images) > 1) : ?>
        <div class="ipp-gallery__thumbs" role="list" aria-label="Gallery thumbnails" style="display:flex;gap:0.5rem;margin-top:0.5rem;overflow-x:auto;">
            <?php foreach ($images as $i => $img) : ?>
                <button class="ipp-gallery__thumb<?php echo $i === 0 ? ' is-active' : ''; ?>"
                        role="listitem"
                        data-full="<?php echo esc_url($img['url']); ?>"
                        data-alt="<?php echo esc_attr($img['alt'] ?: $prop->name()); ?>"
                        aria-label="View photo <?php echo esc_attr($i + 1); ?>"
                        style="flex-shrink:0;">
                    <img src="<?php echo esc_url($img['thumb']); ?>"
                         alt="" loading="lazy"
                         style="width:100%;height:100%;object-fit:cover;">
                </button>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>
    </div>
    <?php endif; ?>

    <!-- Details Grid -->
    <section class="ipp-single__section" aria-labelledby="ipp-minimal-details" style="margin-bottom:2.5rem;">
        <h2 id="ipp-minimal-details" class="ipp-single__section-title" style="font-family:var(--ipp-font-heading,Georgia,serif);font-weight:400;font-size:1.5rem;margin-bottom:1.25rem;">
            Details
        </h2>

        <?php
        $details = [
            'property_code'  => ['Property Code',  $prop->property_code()],
            'property_class' => ['Type',            $prop->property_class()],
            'date_available'  => ['Available',       $prop->formatted_date_available()],
            'bedrooms'       => ['Bedrooms',        $prop->bedrooms()],
            'bathrooms'      => ['Bathrooms',       $prop->bathrooms()],
            'ensuites'       => ['Ensuites',        $prop->ensuites()],
            'cars'           => ['Car Spaces',      $prop->cars()],
            'parking'        => ['Parking',         $prop->parking()],
            'year_built'     => ['Year Built',      $prop->year_built()],
            'stories'        => ['Stories',         $prop->stories()],
            'furnishings'    => ['Furnishings',     $prop->furnishings()],
            'floor_area'     => ['Floor Area',      $prop->floor_area()],
            'land_area'      => ['Land Area',       $prop->land_area_sqm() ? $prop->land_area_sqm() . ' sqm' : ''],
            'pets_allowed'   => ['Pets',            $prop->pets_allowed()],
            'smokers_allowed'=> ['Smokers',         $prop->smokers_allowed()],
        ];
        ?>
        <div style="display:grid;grid-template-columns:1fr 1fr;gap:0;">
            <?php foreach ($details as $key => $detail) : ?>
                <?php if ($prop->show($key) && !empty($detail[1])) : ?>
                    <div class="ipp-single__detail-row" style="padding:0.625rem 0;border-bottom:1px solid var(--ipp-color-gray-100,#f3f4f6);">
                        <span class="ipp-single__detail-label" style="color:var(--ipp-color-gray-400,#9ca3af);font-size:0.8125rem;text-transform:uppercase;letter-spacing:0.05em;"><?php echo esc_html($detail[0]); ?></span>
                        <span class="ipp-single__detail-value"><?php echo esc_html($detail[1]); ?></span>
                    </div>
                <?php endif; ?>
            <?php endforeach; ?>
        </div>
    </section>

    <!-- Features -->
    <?php if ($prop->show('feature_details') && $prop->feature_details()) : ?>
    <section class="ipp-single__section" aria-labelledby="ipp-minimal-features" style="margin-bottom:2.5rem;">
        <h2 id="ipp-minimal-features" class="ipp-single__section-title" style="font-family:var(--ipp-font-heading,Georgia,serif);font-weight:400;font-size:1.5rem;margin-bottom:1.25rem;">
            Features
        </h2>
        <ul style="list-style:none;padding:0;display:grid;grid-template-columns:1fr 1fr;gap:0.25rem 2rem;">
            <?php foreach ((array) $prop->feature_details() as $feature) : ?>
                <li style="padding:0.5rem 0;border-bottom:1px solid var(--ipp-color-gray-50,#f9fafb);color:var(--ipp-color-gray-600,#4b5563);">
                    <?php echo esc_html($feature); ?>
                </li>
            <?php endforeach; ?>
        </ul>
    </section>
    <?php endif; ?>

    <!-- Description -->
    <?php if ($prop->show('advert_text') && $prop->advert_text()) : ?>
    <section class="ipp-single__section" aria-labelledby="ipp-minimal-desc" style="margin-bottom:2.5rem;">
        <h2 id="ipp-minimal-desc" class="ipp-single__section-title" style="font-family:var(--ipp-font-heading,Georgia,serif);font-weight:400;font-size:1.5rem;margin-bottom:1.25rem;">
            Description
        </h2>
        <div class="ipp-single__description" style="line-height:1.8;color:var(--ipp-color-gray-600,#4b5563);">
            <?php echo wp_kses_post($prop->advert_text()); ?>
        </div>
    </section>
    <?php endif; ?>

    <!-- Virtual Tour -->
    <?php if ($prop->show('virtual_tour_url') && $prop->virtual_tour_url()) : ?>
    <section class="ipp-single__section" style="margin-bottom:2.5rem;">
        <a href="<?php echo esc_url($prop->virtual_tour_url()); ?>" target="_blank" rel="noopener noreferrer" class="ipp-btn ipp-btn--outline">
            Virtual Tour
        </a>
    </section>
    <?php endif; ?>

    <!-- Map -->
    <?php if ($prop->show('geographic_location') && $prop->has_map_coords()) : ?>
    <section class="ipp-single__section" aria-labelledby="ipp-minimal-map" style="margin-bottom:2.5rem;">
        <h2 id="ipp-minimal-map" class="ipp-single__section-title" style="font-family:var(--ipp-font-heading,Georgia,serif);font-weight:400;font-size:1.5rem;margin-bottom:1.25rem;">
            Location
        </h2>
        <div class="ipp-map" style="border-radius:var(--ipp-radius,4px);overflow:hidden;">
            <iframe src="<?php echo esc_url($prop->map_embed_url()); ?>"
                    width="100%" height="350"
                    style="border:0;display:block;"
                    allowfullscreen loading="lazy"
                    referrerpolicy="no-referrer-when-downgrade"
                    title="Property location map"></iframe>
        </div>
    </section>
    <?php endif; ?>

    <!-- Agent -->
    <section class="ipp-single__section" aria-labelledby="ipp-minimal-agent" style="border-top:1px solid var(--ipp-color-gray-200,#e5e7eb);padding-top:2rem;">
        <h2 id="ipp-minimal-agent" class="ipp-single__section-title" style="font-family:var(--ipp-font-heading,Georgia,serif);font-weight:400;font-size:1.5rem;margin-bottom:1.25rem;">
            Contact
        </h2>
        <div class="ipp-agent" style="display:flex;align-items:center;gap:1.5rem;flex-wrap:wrap;">
            <div style="width:64px;height:64px;border-radius:50%;background:var(--ipp-color-gray-100,#f3f4f6);display:flex;align-items:center;justify-content:center;flex-shrink:0;" aria-hidden="true">
                <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="var(--ipp-color-gray-400,#9ca3af)" stroke-width="1.5"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
            </div>
            <div>
                <?php if ($prop->agent_name()) : ?>
                    <p class="ipp-agent__name" style="font-family:var(--ipp-font-heading,Georgia,serif);font-size:1.125rem;"><?php echo esc_html($prop->agent_name()); ?></p>
                <?php endif; ?>
                <?php if ($prop->agent_title()) : ?>
                    <p class="ipp-agent__role" style="color:var(--ipp-color-gray-400,#9ca3af);font-size:0.875rem;"><?php echo esc_html($prop->agent_title()); ?></p>
                <?php endif; ?>
                <div class="ipp-agent__contact" style="margin-top:0.5rem;display:flex;gap:1rem;font-size:0.875rem;">
                    <?php if ($prop->agent_phone_mobile()) : ?>
                        <a href="tel:<?php echo esc_attr($prop->agent_phone_mobile()); ?>" class="ipp-agent__action"><?php echo esc_html($prop->agent_phone_mobile()); ?></a>
                    <?php endif; ?>
                    <?php if ($prop->agent_email()) : ?>
                        <a href="mailto:<?php echo esc_attr($prop->agent_email()); ?>?subject=<?php echo esc_attr('Enquiry about ' . $prop->name()); ?>" class="ipp-agent__action">
                            Enquire Now
                        </a>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </section>

</div><!-- .ipp-single -->
