<?php
// Include configuration and models using existing init.php
require_once __DIR__ . '/app/Core/init.php';

// Initialize models
$itemModel = new Item();


// Set page variables
$page_title = 'States';
$body_class = '';


$nigerian_states = 'Abia, Adamawa, Akwa Ibom, Anambra, Bauchi, Bayelsa, Benue, Borno, Cross River, Delta, Ebonyi, Edo, Ekiti, Enugu, FCT, Gombe, Imo, Jigawa, Kaduna, Kano, Katsina, Kebbi, Kogi, Kwara, Lagos, Nasarawa, Niger, Ogun, Ondo, Osun, Oyo, Plateau, Rivers, Sokoto, Taraba, Yobe, Zamfara';

$states = explode( ", ", $nigerian_states);

// Include header template
include __DIR__ . '/templates/layouts/frontend/header.php';
?>

    <!-- start hero section -->
    <div class="py-5 bg-light">
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-lg-8 text-center">
                    <h1 class="display-4 fw-bold mb-4">Find by <?=$page_title; ?></h1>
                    <p class="lead text-muted">Your trusted marketplace for renting and sharing items. We connect people who need items with those who have them to share.</p>
                </div>
            </div>
        </div>
    </div>
    <!-- end hero section -->

    <!-- start featured section -->
    <div class="py-5 position-relative overflow-hidden bg-light mx-3 mt-3 rounded-4">
        <div class="container py-4">
            <div class="row g-3 g-ld-4">
            <?php foreach ($states as $state): ?>
                <div class="col-lg-4 col-md-6 col-sm-6 d-flex">
                    <!-- start state -->
                    <div class="align-items-center border-0 card card-hover d-flex flex-fill flex-row flex-wrap p-3 p-sm-3 rounded-4 shadow-sm w-100">
                        <div class="flex-grow-1 ms-2 ms-md-3">
                            <h3 class="fs-19 fw-semibold mb-1">
                                <a href="items.php?search=&location=<?= $state ?>"><?= htmlspecialchars($state) ?></a>
                            </h3>
                            <p class="mb-0 small"><?= $itemModel->count_state_total($state)." Items"; ?> </p>
                        </div>
                        <a href="items.php?search=&location=<?= $state ?>" class="align-items-center d-flex fw-semibold gap-2 link-hover">
                            <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-arrow-up-right" viewBox="0 0 16 16">
                                <path fill-rule="evenodd" d="M14 2.5a.5.5 0 0 0-.5-.5h-6a.5.5 0 0 0 0 1h4.793L2.146 13.146a.5.5 0 0 0 .708.708L13 3.707V8.5a.5.5 0 0 0 1 0v-6z"></path>
                            </svg>
                        </a>
                    </div>
                    <!-- end /. category -->
                </div>
                <?php endforeach; ?>
            </div>
        </div>
    </div>
    <!-- end /. featured section -->


<?php
// Include footer template
include __DIR__ . '/templates/layouts/frontend/footer.php';
?>