<?php if (!defined('ABSPATH')) exit; ?>
<?php
/**
 * Developer - Archive Card Template
 *
 * Barebone semantic HTML. No decorative classes. Uses <article>, <header>,
 * <footer>, proper heading hierarchy. All data attributes for JS hooks.
 * Minimal styling -- designed for theme developers to override completely.
 *
 * @package Integrate_Palace_Properties
 */

$prop      = new IPP_Property_Helper();
$featured  = $prop->featured_image('large');
$permalink = get_permalink();
?>
<article class="ipp-card ipp-card--developer"
         data-property-code="<?php echo esc_attr($prop->property_code()); ?>"
         data-property-status="<?php echo esc_attr($prop->status()); ?>"
         data-bedrooms="<?php echo esc_attr($prop->bedrooms()); ?>"
         data-bathrooms="<?php echo esc_attr($prop->bathrooms()); ?>"
         data-cars="<?php echo esc_attr($prop->cars()); ?>"
         data-rent="<?php echo esc_attr($prop->rent()); ?>"
         data-rental-period="<?php echo esc_attr($prop->rental_period()); ?>"
         data-suburb="<?php echo esc_attr($prop->suburb()); ?>"
         data-region="<?php echo esc_attr($prop->region()); ?>"
         data-postcode="<?php echo esc_attr($prop->postcode()); ?>"
         data-property-class="<?php echo esc_attr($prop->property_class()); ?>"
         data-date-available="<?php echo esc_attr($prop->date_available()); ?>"
         aria-label="<?php echo esc_attr($prop->name()); ?>">

    <?php if ($featured) : ?>
    <a href="<?php echo esc_url($permalink); ?>" data-role="property-image">
        <img src="<?php echo esc_url($featured['url']); ?>"
             alt="<?php echo esc_attr($featured['alt'] ?: $prop->name()); ?>"
             loading="lazy"
             data-image-id="<?php echo esc_attr($featured['id']); ?>">
    </a>
    <?php endif; ?>

    <header>
        <?php if ($prop->show('status') && $prop->status()) : ?>
            <span data-role="property-status"><?php echo esc_html($prop->status()); ?></span>
        <?php endif; ?>

        <h3>
            <a href="<?php echo esc_url($permalink); ?>" data-role="property-link">
                <?php echo esc_html(get_the_title()); ?>
            </a>
        </h3>

        <?php if ($prop->show('address') && $prop->full_address()) : ?>
            <address data-role="property-address"><?php echo esc_html($prop->full_address()); ?></address>
        <?php endif; ?>
    </header>

    <div data-role="property-meta">
        <?php if ($prop->show('rent') && $prop->formatted_rent()) : ?>
            <span data-role="property-price" data-raw-rent="<?php echo esc_attr($prop->rent()); ?>">
                <?php echo esc_html($prop->formatted_rent()); ?>
                <?php if ($prop->rental_period()) : ?>
                    <span data-role="rental-period"><?php echo esc_html($prop->rental_period()); ?></span>
                <?php endif; ?>
            </span>
        <?php endif; ?>

        <dl data-role="property-specs">
            <?php if ($prop->show('bedrooms') && $prop->bedrooms()) : ?>
                <div data-spec="bedrooms">
                    <dt>Bedrooms</dt>
                    <dd><?php echo esc_html($prop->bedrooms()); ?></dd>
                </div>
            <?php endif; ?>
            <?php if ($prop->show('bathrooms') && $prop->bathrooms()) : ?>
                <div data-spec="bathrooms">
                    <dt>Bathrooms</dt>
                    <dd><?php echo esc_html($prop->bathrooms()); ?></dd>
                </div>
            <?php endif; ?>
            <?php if ($prop->show('ensuites') && $prop->ensuites()) : ?>
                <div data-spec="ensuites">
                    <dt>Ensuites</dt>
                    <dd><?php echo esc_html($prop->ensuites()); ?></dd>
                </div>
            <?php endif; ?>
            <?php if ($prop->show('cars') && $prop->cars()) : ?>
                <div data-spec="cars">
                    <dt>Car Spaces</dt>
                    <dd><?php echo esc_html($prop->cars()); ?></dd>
                </div>
            <?php endif; ?>
        </dl>
    </div>

    <footer>
        <?php if ($prop->show('date_available') && $prop->formatted_date_available()) : ?>
            <time data-role="date-available" datetime="<?php echo esc_attr($prop->date_available()); ?>">
                Available <?php echo esc_html($prop->formatted_date_available()); ?>
            </time>
        <?php endif; ?>

        <?php if ($prop->show('property_class') && $prop->property_class()) : ?>
            <span data-role="property-type"><?php echo esc_html($prop->property_class()); ?></span>
        <?php endif; ?>

        <a href="<?php echo esc_url($permalink); ?>" data-role="view-property">View Property</a>
    </footer>

</article>
