<?php include 'header.php' ?>


<main>
    <!-- Page banner area start here -->
    <section class="banner__inner-page bg-image pt-180 pb-180 bg-image" data-background="assets/images/banner-in.png">
        <div class="shape2 wow slideInLeft d-none d-md-block d-lg-block" data-wow-delay="00ms"
            data-wow-duration="1500ms">
            <img src="assets/images/banner/inner-banner-shape2.png" alt="shape">
        </div>
        <div class="shape1 wow slideInLeft d-none d-md-block d-lg-block" data-wow-delay="200ms"
            data-wow-duration="1500ms">
            <img src="assets/images/banner/inner-banner-shape1.png" alt="shape">
        </div>
        <div class="shape3 wow slideInRight d-none d-md-block d-lg-block" data-wow-delay="200ms"
            data-wow-duration="1500ms">
            <img class="sway__animationX" src="assets/images/banner/inner-banner-shape3.png" alt="shape">
        </div>
        <div class="container">

            <?php
            if (isset($_GET['product'])) {
                $product_category_name = $_GET['product'];
                $string_upper = strtoupper($product_category_name);
                $string_replace = str_replace('-', ' ', $string_upper);


                $sql = "SELECT DISTINCT category_name FROM `product` WHERE category_name = '$string_replace'";

                $result = mysqli_query($con, $sql);
                if ($result) {
                    foreach ($result as $key) {

                        $category = $key['category_name'];
                        ?>


                        <h2 class="wow fadeInUp banner-in-header" data-wow-delay="00ms" data-wow-duration="1500ms">
                            <?php echo $category ?>
                        </h2>

                    <?php }
                }
            }

            ?>

            <div class="breadcrumb-list wow fadeInUp" data-wow-delay="200ms" data-wow-duration="1500ms">
                <a href="index.php">Home</a><span><i class="fa-regular fa-angles-right mx-2"></i>Products</span>
            </div>
        </div>
    </section>
    <!-- Page banner area end here -->




    <!-- Service area start here -->
    <section class="service-inner-area pt-5 pb-120">
        <div class="container">
            <div class="row g-4">





                <?php
                if (isset($_GET['product'])) {
                    $product_category_name = $_GET['product'];
                    $string_upper = strtoupper($product_category_name);
                    $string_replace = str_replace('-', ' ', $string_upper);


                    $sql = "select * from `product` where category_name = '$string_replace'";

                    $result = mysqli_query($con, $sql);
                    if ($result) {
                        foreach ($result as $key) {
                            $id = $key['id'];
                            $image = $key['image'];
                            $name = $key['product_name'];
                            $description = $key['description'];
                            ?>

                            <div class="col-lg-4 col-md-6">
                                <div class="service-two__item with-shadow">
                                    <div class="image">
                                        <img src="my-admin/img_uploads/<?php echo $image ?>" style="width: 100%; height: 230px;" alt="image">
                                    </div>
                                    <div class="service-two__content">
                                        <div class="icon">
                                            <img src="assets/images/package-icon-1.png" style="width: 46px;" alt="icon">
                                        </div>
                                        <div class="shape"><img src="assets/images/shape/service-two-item-shape.png" alt="shape">
                                        </div>
                                        <h4><a href="product-details.php?product=<?php echo $id ?>" class="primary-hover">
                                                <?php echo $name ?>
                                            </a></h4>
                                        <p>
                                            <?php
                                            // Truncate news details to 30 words
                                            $words = explode(' ', $description);
                                            $word_count = count($words);
                                            $trimmed_details = implode(' ', array_slice($words, 0, min(17, $word_count)));

                                            // Output the truncated details
                                            echo $trimmed_details;

                                            // Add ellipsis if the content has more than 30 words
                                            if ($word_count > 17) {
                                                echo '.....';
                                            }
                                            ?>

                                        </p>
                                        <a class="read-more-btn" href="product-details.php?product=<?php echo $id ?> ">Read More <i
                                                class="fa-regular fa-arrow-right-long"></i></a>
                                    </div>
                                </div>
                            </div>





                        <?php }
                    }
                }

                ?>





            </div>
        </div>
    </section>
    <!-- Service area end here -->



    <?php include 'footer.php' ?>