<?php if (!defined('ABSPATH')) exit; ?>
<?php
/**
 * Palace Property - Archive Card Template (Default)
 *
 * Clean card layout with image (4/3), status badge, price overlay,
 * title, address, bed/bath/car meta, and date available footer.
 *
 * @package Integrate_Palace_Properties
 */

$prop = new IPP_Property_Helper();
$featured   = $prop->featured_image('large');
$permalink  = get_permalink();
?>
<article class="ipp-card" aria-label="<?php echo esc_attr($prop->name()); ?>">

    <a href="<?php echo esc_url($permalink); ?>" class="ipp-card__image" aria-label="<?php echo esc_attr($prop->name()); ?>">
        <?php if ($featured) : ?>
            <img src="<?php echo esc_url($featured['url']); ?>"
                 alt="<?php echo esc_attr($featured['alt'] ?: $prop->name()); ?>"
                 loading="lazy"
                 style="aspect-ratio:4/3;object-fit:cover;width:100%;">
        <?php else : ?>
            <span style="display:block;aspect-ratio:4/3;background:var(--ipp-color-gray-100,#f3f4f6);"></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'; ?>">
                <?php echo esc_html($prop->status()); ?>
            </span>
        <?php endif; ?>

        <?php if ($prop->show('rent') && $prop->formatted_rent()) : ?>
            <span class="ipp-card__price">
                <?php echo esc_html($prop->formatted_rent()); ?>
                <?php if ($prop->rental_period()) : ?>
                    <small><?php echo esc_html($prop->rental_period()); ?></small>
                <?php endif; ?>
            </span>
        <?php endif; ?>
    </a>

    <div class="ipp-card__body">
        <h3 class="ipp-card__title">
            <a href="<?php echo esc_url($permalink); ?>">
                <?php echo esc_html(get_the_title()); ?>
            </a>
        </h3>

        <?php if ($prop->show('address') && $prop->short_address()) : ?>
            <p class="ipp-card__address">
                <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z"/><circle cx="12" cy="10" r="3"/></svg>
                <?php echo esc_html($prop->short_address()); ?>
            </p>
        <?php endif; ?>

        <div class="ipp-card__meta">
            <?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" stroke-linecap="round" stroke-linejoin="round" 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" 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" stroke-linecap="round" stroke-linejoin="round" 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" 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" stroke-linecap="round" stroke-linejoin="round" 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>
    </div>

    <div class="ipp-card__footer">
        <?php if ($prop->show('date_available') && $prop->formatted_date_available()) : ?>
            <span>Available <?php echo esc_html($prop->formatted_date_available()); ?></span>
        <?php endif; ?>
        <a href="<?php echo esc_url($permalink); ?>" class="ipp-btn ipp-btn--outline">View Property</a>
    </div>

</article>
