<?php
/** @var array $properties */
/** @var array $portfolio */

$activeAdminPage = 'inventory';
$adminTitle = 'See every loaded property on its own inventory page.';
$adminDescription = 'Browse the live property table without the property editor and editorial tools making the page unnecessarily long.';

require dirname(__DIR__) . '/partials/admin-header.php';
?>

<section class="admin-workspace">
    <section class="admin-section">
        <div class="section-heading">
            <div>
                <span class="eyebrow">Loaded properties</span>
                <h2>Live property inventory</h2>
            </div>
            <a class="ghost-button" href="<?= htmlspecialchars(app_url('admin-properties'), ENT_QUOTES, 'UTF-8') ?>">Load or edit property</a>
        </div>

        <div class="admin-inventory-table">
            <div class="admin-inventory-row admin-inventory-head">
                <div>Listing</div>
                <div>Purpose</div>
                <div>Price</div>
                <div>Media</div>
                <div>Status</div>
                <div>Actions</div>
            </div>

            <?php foreach ($properties as $property): ?>
                <div class="admin-inventory-row">
                    <div class="admin-property-cell">
                        <img src="<?= htmlspecialchars((string) $property['image'], ENT_QUOTES, 'UTF-8') ?>" alt="<?= htmlspecialchars((string) $property['title'], ENT_QUOTES, 'UTF-8') ?>">
                        <div class="admin-property-summary">
                            <strong><?= htmlspecialchars((string) $property['title'], ENT_QUOTES, 'UTF-8') ?></strong>
                            <span><?= htmlspecialchars((string) $property['location'], ENT_QUOTES, 'UTF-8') ?></span>
                            <span><?= htmlspecialchars((string) $property['type'], ENT_QUOTES, 'UTF-8') ?></span>
                            <span><?= (int) $property['beds'] ?> bed | <?= htmlspecialchars((string) $property['baths'], ENT_QUOTES, 'UTF-8') ?> bath</span>
                        </div>
                    </div>
                    <div class="admin-inventory-value">
                        <span class="type-pill"><?= htmlspecialchars((string) ucfirst($property['purpose']), ENT_QUOTES, 'UTF-8') ?></span>
                    </div>
                    <div class="admin-inventory-value admin-price-cell">
                        <strong><?= htmlspecialchars((string) $property['price'], ENT_QUOTES, 'UTF-8') ?></strong>
                    </div>
                    <div class="admin-inventory-value">
                        <strong><?= is_array($property['images']) ? count($property['images']) : 0 ?> images</strong>
                        <span>Main + gallery</span>
                    </div>
                    <div class="admin-inventory-value">
                        <span class="type-pill"><?= htmlspecialchars((string) ucfirst($property['status']), ENT_QUOTES, 'UTF-8') ?></span>
                    </div>
                    <div class="admin-table-actions">
                        <a class="text-link" href="<?= htmlspecialchars(app_url('admin-properties', array('edit_property' => $property['id'])), ENT_QUOTES, 'UTF-8') ?>">Edit listing</a>
                    </div>
                </div>
            <?php endforeach; ?>

            <?php if ($properties === array()): ?>
                <div class="admin-inventory-row">
                    <div class="admin-empty-inline">No properties have been loaded yet.</div>
                </div>
            <?php endif; ?>
        </div>
    </section>
</section>
