<?php if (!defined('ABSPATH')) exit; ?>
<?php
/**
 * Grid Gallery - Archive Card Template
 *
 * Masonry-style emphasis on photography. Variable height images.
 * Title overlaid on hover with dark gradient. Minimal info visible by
 * default, full details on hover.
 *
 * @package Integrate_Palace_Properties
 */

$prop      = new IPP_Property_Helper();
$featured  = $prop->featured_image('large');
$permalink = get_permalink();
$uid       = 'ipp-gg-' . esc_attr($prop->property_code() ?: uniqid());
?>
<style>
    .ipp-card--grid-gallery .ipp-card--grid-gallery__overlay {
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    .ipp-card--grid-gallery:hover .ipp-card--grid-gallery__overlay,
    .ipp-card--grid-gallery:focus-within .ipp-card--grid-gallery__overlay {
        opacity: 1;
    }
</style>

<article class="ipp-card ipp-card--grid-gallery"
         style="position:relative;overflow:hidden;border-radius:var(--ipp-radius,8px);break-inside:avoid;margin-bottom:1rem;"
         aria-label="<?php echo esc_attr($prop->name()); ?>">

    <a href="<?php echo esc_url($permalink); ?>" style="display:block;position:relative;">
        <?php if ($featured) : ?>
            <img src="<?php echo esc_url($featured['url']); ?>"
                 alt="<?php echo esc_attr($featured['alt'] ?: $prop->name()); ?>"
                 loading="lazy"
                 style="width:100%;display:block;object-fit:cover;">
        <?php else : ?>
            <span style="display:block;width:100%;aspect-ratio:4/3;background:var(--ipp-color-gray-200,#e5e7eb);"></span>
        <?php endif; ?>

        <?php if ($prop->show('status') && $prop->status()) : ?>
            <span class="ipp-card__badge ipp-badge <?php echo strtolower($prop->status()) === 'active' ? 'ipp-badge--active' : 'ipp-badge--inactive'; ?>"
                  style="position:absolute;top:0.75rem;left:0.75rem;z-index:3;">
                <?php echo esc_html($prop->status()); ?>
            </span>
        <?php endif; ?>

        <!-- Hover overlay with full details -->
        <div class="ipp-card--grid-gallery__overlay"
             style="position:absolute;inset:0;background:linear-gradient(transparent 30%,rgba(0,0,0,0.8));display:flex;flex-direction:column;justify-content:flex-end;padding:1.25rem;color:#fff;">

            <?php if ($prop->show('rent') && $prop->formatted_rent()) : ?>
                <p class="ipp-card__price" style="font-size:1.125rem;font-weight:700;margin:0 0 0.25rem;color:#fff;">
                    <?php echo esc_html($prop->formatted_rent()); ?>
                    <?php if ($prop->rental_period()) : ?>
                        <span style="font-size:0.75rem;font-weight:400;opacity:0.8;">/ <?php echo esc_html($prop->rental_period()); ?></span>
                    <?php endif; ?>
                </p>
            <?php endif; ?>

            <h3 class="ipp-card__title" style="margin:0 0 0.25rem;color:#fff;font-size:1.0625rem;">
                <?php echo esc_html(get_the_title()); ?>
            </h3>

            <?php if ($prop->show('address') && $prop->short_address()) : ?>
                <p class="ipp-card__address" style="margin:0 0 0.5rem;color:rgba(255,255,255,0.8);font-size:0.8125rem;">
                    <?php echo esc_html($prop->short_address()); ?>
                </p>
            <?php endif; ?>

            <div class="ipp-card__meta" style="display:flex;gap:0.625rem;font-size:0.8125rem;">
                <?php if ($prop->show('bedrooms') && $prop->bedrooms()) : ?>
                    <span class="ipp-card__meta-item" style="color:rgba(255,255,255,0.9);" aria-label="<?php echo esc_attr($prop->bedrooms()); ?> bedrooms">
                        <svg width="14" height="14" 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()); ?>
                    </span>
                <?php endif; ?>
                <?php if ($prop->show('bathrooms') && $prop->bathrooms()) : ?>
                    <span class="ipp-card__meta-item" style="color:rgba(255,255,255,0.9);" aria-label="<?php echo esc_attr($prop->bathrooms()); ?> bathrooms">
                        <svg width="14" height="14" 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()); ?>
                    </span>
                <?php endif; ?>
                <?php if ($prop->show('cars') && $prop->cars()) : ?>
                    <span class="ipp-card__meta-item" style="color:rgba(255,255,255,0.9);" aria-label="<?php echo esc_attr($prop->cars()); ?> car spaces">
                        <svg width="14" height="14" 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()); ?>
                    </span>
                <?php endif; ?>
            </div>

            <?php if ($prop->show('date_available') && $prop->formatted_date_available()) : ?>
                <p style="margin:0.375rem 0 0;font-size:0.75rem;color:rgba(255,255,255,0.7);">
                    Available <?php echo esc_html($prop->formatted_date_available()); ?>
                </p>
            <?php endif; ?>
        </div>
    </a>

</article>
