<?php
include_once('include/head.php');
include_once('include/header.php');

/* =========================
   Get Slug
========================= */
$top_slug = $_GET['slug'] ?? '';

if (empty($top_slug)) {
    http_response_code(404);
    exit("Category not found");
}

$top_slug = mysqli_real_escape_string($con, $top_slug);

/* =========================
   Fetch Top Category
========================= */
$topQuery  = "SELECT * FROM top_categories WHERE slug = '$top_slug' LIMIT 1";
$topResult = mysqli_query($con, $topQuery);

if (!$topResult || mysqli_num_rows($topResult) === 0) {
    die("Category not found");
}

$topCategory = mysqli_fetch_assoc($topResult);

/* =========================
   Fetch Mid Categories
========================= */
$midCategories = [];
$midQuery = "
    SELECT * 
    FROM mid_categories 
    WHERE top_category_id = {$topCategory['id']}
    ORDER BY id ASC
";

$midResult = mysqli_query($con, $midQuery);

while ($row = mysqli_fetch_assoc($midResult)) {
    $midCategories[] = $row;
}
?>

<!-- ================= HERO / TOP CATEGORY ================= -->
<div class="container-fluid hero-header" style="background:linear-gradient(rgba(9,30,62,.7), rgba(9,30,62,.7)),
     url('<?php echo path(); ?>admin/assets/images/top_categories/<?php echo htmlspecialchars($topCategory['category_image']); ?>');
     background-size:cover;
     background-position:center;">

    <div class="row py-5">
        <div class="col-12 text-center text-white">
            <h1 class="display-4 animated zoomIn">
                <?php echo htmlspecialchars($topCategory['category_name']); ?>
            </h1>

            <nav class="mt-4">
                <a href="<?php echo path(); ?>" class="text-white">Home</a>
                <span class="mx-2">/</span>
                <span class="fw-bold">
                    <?php echo htmlspecialchars($topCategory['category_name']); ?>
                </span>
            </nav>
        </div>
    </div>
</div>

<!-- ================= Top Category Section Start ================= -->
<div class="container-fluid py-5 wow fadeInUp" data-wow-delay="0.1s">
    <div class="container">
        <div class="row g-5 align-items-center">

            <!-- ===== Content (LEFT) ===== -->
            <div class="col-lg-7">
                <div class="section-title mb-4">
                    <h5 class="position-relative d-inline-block text-primary text-uppercase">
                        About Services
                    </h5>

                    <h1 class="display-5 mb-0">
                        <?php echo htmlspecialchars($topCategory['category_name']); ?>
                    </h1>
                </div>

                <?php if (!empty($topCategory['category_description'])): ?>
                <div class="mb-4">
                    <?php echo $topCategory['category_description']; ?>
                </div>
                <?php endif; ?>


                </ul>
            </div>

            <!-- ===== Image (RIGHT) ===== -->
            <div class="col-lg-5" style="min-height: 450px;">
                <div class="position-relative h-100">
                    <?php if (!empty($topCategory['category_image'])): ?>
                    <img src="<?= path(); ?>admin/assets/images/top_categories/<?= htmlspecialchars($topCategory['category_image']); ?>"
                        alt="<?= htmlspecialchars($topCategory['category_name']); ?>"
                        class="position-absolute w-100 wow zoomIn" data-wow-delay="0.3s" style="
                     height: 450px;
                     object-fit: cover;
                     border-radius: 10px;
                 ">
                    <?php endif; ?>
                </div>
            </div>


        </div>
    </div>
</div>
<!-- ================= Top Category Section End ================= -->

<!-- why to choose start -->
<div class="container-fluid wow fadeInUp" data-wow-delay="0.1s">
    <div class="container">
        <div class="row g-5 mb-5">

            <div class="col-lg-12">
                <div class="section-title mb-2 text-center">

                    <h3 class="display-3 mb-0">Why To <?php echo htmlspecialchars($topCategory['category_name']); ?>
                    </h3>
                </div>

                <!-- Cards Row -->
                <div class="row service-section">

                    <!-- Card 1 -->
                    <div class="col-lg-4 col-md-6 col-12 mt-4">
                        <div class="icon-box h-100">
                            <i class="fa fa-bullseye service-icon wow zoomIn"></i>
                            <p class="service-title">
                                <a href="#">Safe & Reliable</a>
                            </p>
                            <p class="service-para">
                                Our highly skilled nurses and attendants with medical qualifications are reliable
                                and can be trusted to provide exceptional care for your loved ones.
                            </p>
                        </div>
                    </div>

                    <!-- Card 2 -->
                    <div class="col-lg-4 col-md-6 col-12 mt-4">
                        <div class="icon-box h-100">
                            <i class="fa service-icon wow zoomIn">&#xf0c0;</i>
                            <p class="service-title">
                                <a href="#">Save Money on Hospital Visits</a>
                            </p>
                            <p class="service-para">
                                You can save up to 50% on hospital and doctor visits by choosing Home Nursing or
                                Home Care.
                            </p>
                        </div>
                    </div>

                    <!-- Card 3 -->
                    <div class="col-lg-4 col-md-6 col-12 mt-4">
                        <div class="icon-box h-100">
                            <i class="fa fa-user service-icon wow zoomIn"></i>
                            <p class="service-title">
                                <a href="#">Professional Staff</a>
                            </p>
                            <p class="service-para">
                                Our highly skilled and trained caregivers provide companion care to seniors with a
                                variety of daily activities.
                            </p>
                        </div>
                    </div>

                </div>
            </div>

        </div>
    </div>
</div>
<!-- why to choose end -->



<!-- ================= MID CATEGORIES ================= -->
<div class="container-fluid py-5 wow fadeInUp" data-wow-delay="0.1s">
    <div class="container">

        <!-- Section Title -->
        <div class="section-title mb-5 text-center">
            <h5 class="position-relative d-inline-block text-primary text-uppercase">
                Our Services
            </h5>
            <h3 class="display-3 mb-0">
                Our Expert <?php echo htmlspecialchars($topCategory['category_name']); ?>
            </h3>
        </div>

        <!-- Services Grid -->
        <div class="row d-flex justify-content-center g-4">

            <?php if (!empty($midCategories)): ?>
            <?php foreach ($midCategories as $mid): ?>

            <div class="col-lg-4 col-md-6 wow zoomFade" data-wow-delay="0.2s">
                <div class="card service-card h-100 shadow-sm">

                    <!-- Image -->
                    <div class="overflow-hidden rounded-top">
                        <?php if (!empty($mid['category_image'])): ?>
                        <img src="<?php echo path(); ?>admin/assets/images/mid_categories/<?php echo htmlspecialchars($mid['category_image']); ?>"
                            alt="<?php echo htmlspecialchars($mid['category_name']); ?>" class="img-fluid w-100"
                            style="height:220px; object-fit:cover;">
                        <?php endif; ?>
                    </div>

                    <!-- Content -->
                    <div class="card-body text-center">
                        <h5 class="card-title mb-2">
                            <?php echo htmlspecialchars($mid['category_name']); ?>
                        </h5>

                        <p class="card-text small text-muted">
                            <?php echo strip_tags(substr($mid['category_description'], 0, 120)); ?>…
                        </p>
                    </div>

                    <!-- Button -->
                    <div class="card-footer bg-transparent border-0 text-center pb-3">
                        <a href="<?php path(); ?>services/<?php echo urlencode($mid['slug']); ?>"
                            class="btn btn-primary btn-sm px-4">
                            Read More
                        </a>
                    </div>

                </div>
            </div>

            <?php endforeach; ?>
            <?php else: ?>
            <div class="col-12 text-center">
                <p>No services found.</p>
            </div>
            <?php endif; ?>

        </div>
    </div>
</div>

<!-- ================= STYLES ================= -->
<style>
/* Service Card Styling */
.service-card {
    border: 2px solid #1469a6;
    border-radius: 12px;
    overflow: hidden;
    transition: all 0.4s ease-in-out;
    background: #fff;
}

.service-card img {
    transition: transform 0.5s ease-in-out;
}

.service-card:hover {
    transform: scale(1.05);
    box-shadow: 0 15px 40px rgba(13, 110, 253, 0.35);
}

.service-card:hover img {
    transform: scale(1.1);
}

/* Fade + zoom animation */
.wow.zoomFade {
    animation-name: zoomFade;
}

@keyframes zoomFade {
    from {
        opacity: 0;
        transform: scale(0.85);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}
</style>

<?php include_once('include/footer.php'); ?>