<?php
include("admin/connection.php");
include('include/header.php');

$slug = $_GET['slug'];
$ser = mysqli_query($con, "SELECT * FROM `tbl_top_category` where slug='$slug'");
while ($row = mysqli_fetch_array($ser)) {
    $cat_name = $row['cat_name'];
    $slug = $row['slug'];
    $Image = $row['Image'];
    $t_id = $row['t_id'];
    $description = $row['description'];
}
?>
<style>
    .service-details__img img {
        aspect-ratio: 4 / 3;
    }
    .service-details__img-box-img img{
            aspect-ratio: 3 / 3;
    }
    .service-details__left p{
        text-align: justify;
    }
        .service-details__img-box-single{
        min-height: 415px;
    }

</style>
<!--Page Header Start-->
<section class="page-header">
    <div class="page-header__bg" style="background-image: url(<?php path() ?>assets/images/backgrounds/page-header-bg.jpg);">
    </div>
    <div class="container">
        <div class="page-header__inner">

            <h3><?php echo $cat_name; ?></h3>
            <div class="thm-breadcrumb__inner">
                <ul class="thm-breadcrumb list-unstyled">
                    <li><a href="<?php path() ?>index.php">Home</a></li>
                    <li><span class="fas fa-angle-right"></span></li>
                    <li><?php echo $cat_name; ?></li>

                </ul>
            </div>
        </div>
    </div>
</section>
<!--Page Header End-->

<!--Service Details Start-->
<section class="service-details">
    <div class="container">
        <div class="row">
            <div class="col-xl-6 col-lg-6">
                <div class="service-details__img">
                    <img src="<?php path(); ?>/admin/assets/images/service/<?php echo htmlspecialchars($Image); ?>" alt="">
                </div>
            </div>
            <div class="col-xl-6 col-lg-6">
                <div class="service-details__left">
                    <h3 class="service-details__title-1"><?php echo htmlspecialchars($cat_name); ?></h3>
                    <p class="service-details__text-2"><?php echo $description; ?></p>
                </div>
            </div>
            <!--  -->


            <?php
            $slug = isset($_GET['slug']) ? mysqli_real_escape_string($con, $_GET['slug']) : '';

            $currentCat = null;

            if ($slug != '') {
                $catQuery = mysqli_query($con, "SELECT * FROM tbl_top_category WHERE slug = '$slug' LIMIT 1");
                $currentCat = mysqli_fetch_assoc($catQuery);
            }
            ?>
            <div class="service-details__img-box">
                <div class="row text-center">
                    <?php
                    if ($currentCat) {

                        // Category ID
                        $catId = $currentCat['t_id'];

                        // Category slug (IMPORTANT for URL)
                        $service_slug = $currentCat['slug'];

                        // Fetch products
                        $products = mysqli_query($con, "SELECT * FROM product WHERE activity = 'yes' AND t_id = '$catId'");

                        if (mysqli_num_rows($products) > 0) {

                            while ($row = mysqli_fetch_assoc($products)) {
                    ?>
                                <div class="col-xl-3">
                                    <div class="service-details__img-box-single">
                                        <div class="service-details__img-box-img">
                                            <a href="<?php echo path() . $service_slug . '/' . $row['slug']; ?>">
                                                <img src="<?php echo path(); ?>admin/assets/images/service/<?php echo $row['Image']; ?>"
                                                    alt="">
                                            </a>
                                        </div>
                                        <div class="service-details__img-box-content">
                                            <div class="service-details__img-box-content-icon-and-title">
                                                <a href="<?php echo path() . $service_slug . '/' . $row['slug']; ?>">
                                                    <h3 class="service-details__img-box-content-title"><?php echo $row['title']; ?>
                                                    </h3>
                                                </a>
                                            </div>

                                            <a href="<?php echo path() . $service_slug . '/' . $row['slug']; ?>">
                                                <button type="button" class="btn btn-danger mt-3">View Details</button>
                                            </a>
                                        </div>
                                    </div>
                                </div>
                    <?php
                            }
                        } else {
                            echo "<div class='col-12 mb-5'><h4 class='text-center'></h4></div>";
                        }
                    } else {
                        echo "<div class='col-12'><h4 class='text-center'>Please select a category.</h4></div>";
                    }
                    ?>

                </div>
            </div>

        </div>
    </div>
</section>
<!--Service Details End-->



<?php
include("include/footer.php");
?>