<?php
include("include/header.php");

// ✅ Get slug from URL
if (isset($_GET['slug'])) {
    $slug = mysqli_real_escape_string($con, $_GET['slug']);

    // ✅ Fetch aluminium product by slug
    $query = "SELECT * FROM aluminium WHERE slug='$slug' LIMIT 1";
    $result = mysqli_query($con, $query);
    $aluminium = mysqli_fetch_assoc($result);
}
?>


<div class="breadcumb-wrapper" data-bg-src="<?php path() ?>/assets/img/hero/banner1.webp">
    <div class="container">
        <div class="breadcumb-content">
            <h1 class="breadcumb-title"><?php echo $aluminium['title']; ?></h1>
            <ul class="breadcumb-menu">
                <li><a href="<?php path() ?>/index.php">Home</a></li>
                <li><?php echo $aluminium['title']; ?></li>
            </ul>
        </div>
    </div>
</div>

<section class="space-top space-extra2-bottom">
    <div class="container">
        <div class="row">
            <!-- Main Content -->
            <div class="col-xxl-8 col-lg-8">
                <div class="page-single">

                    <div class="page-content">
                        <h2 class="h3 page-title"><?php echo $aluminium['title']; ?></h2>
                        <p class="mb-30">
                            <?php echo nl2br($aluminium['description']); ?>
                        </p>

                        <!-- ✅ Dynamic Services/Benefits from JSON -->
                        <?php if (!empty($aluminium['services_data'])): 
                            $services = json_decode($aluminium['services_data'], true);
                        ?>
                        <div class="row gy-30 align-items-center">
                            <div class="col-xl-12">
                                <h4 class="box-title">Key Benefits</h4>
                                <div class="th-faq-wrapper">
                                    <div class="accordion-1 accordion" id="benefitsAccordion">
                                        <?php 
                                    $i = 0;
                                    foreach ($services as $srv): 
                                        $isActive = ($i == 0) ? 'show' : '';
                                        $ariaExpanded = ($i == 0) ? 'true' : 'false';
                                        $activeClass = ($i == 0) ? 'active' : '';
                                    ?>
                                        <div class="accordion-card <?php echo $activeClass; ?>">
                                            <div class="accordion-header" id="collapse-item-<?php echo $i; ?>">
                                                <button class="accordion-button" type="button" data-bs-toggle="collapse"
                                                    data-bs-target="#collapse-<?php echo $i; ?>"
                                                    aria-expanded="<?php echo $ariaExpanded; ?>"
                                                    aria-controls="collapse-<?php echo $i; ?>">
                                                    <span class="serial-numb"><?php echo ($i+1) . "."; ?></span>
                                                    <?php echo $srv['heading']; ?>
                                                </button>
                                            </div>
                                            <div id="collapse-<?php echo $i; ?>"
                                                class="accordion-collapse collapse <?php echo $isActive; ?>"
                                                aria-labelledby="collapse-item-<?php echo $i; ?>"
                                                data-bs-parent="#benefitsAccordion">
                                                <div class="accordion-body">
                                                    <p class="faq-text"><?php echo $srv['content']; ?></p>
                                                </div>
                                            </div>
                                        </div>
                                        <?php 
                $i++;
                endforeach; 
                ?>
                                    </div>
                                </div>
                            </div>
                        </div>


                        <?php endif; ?>
                    </div>
                </div>
            </div>

            <!-- Sidebar -->
            <div class="col-xxl-4 col-lg-4">
                <aside class="sidebar-area">

                    <!-- Download Brochure -->
                    <div class="widget widget_download">
                        <h4 class="widget_title">Download</h4>
                        <div class="donwload-media-wrap">
                            <div class="download-media">
                                <div class="download-media_icon"><i class="fal fa-file-pdf"></i></div>
                                <div class="download-media_info">
                                    <h5 class="download-media_title">Aluminium Products Brochure</h5>
                                    <span class="download-media_text">Download</span>
                                </div>
                                <a href="assets/brochure/aluminium-products.pdf" class="download-media_btn">
                                    <i class="far fa-arrow-right"></i>
                                </a>
                            </div>
                        </div>
                    </div>

                    <!-- ✅ All Aluminium Products List -->
                    <div class="widget widget_products">
                        <h4 class="widget_title">All Aluminium Products</h4>
                        <div class="product-list">
                            <?php
                            $aluQuery = mysqli_query($con, "SELECT id, title, slug, short_des FROM aluminium ORDER BY id DESC");
                            while ($a = mysqli_fetch_assoc($aluQuery)) {
                            ?>
                            <div class="product-item d-flex align-items-center mb-3">

                                <div class="product-info">
                                    <h6 class="mb-1">
                                        <a href="aluminium-product-deatils.php?slug=<?php echo $a['slug']; ?>">
                                            <?php echo $a['title']; ?>
                                        </a>
                                    </h6>
                                    <p class="mb-0 small text-muted">
                                        <?php 
                                                $words = explode(" ", strip_tags($a['short_des']));
                                                $limited = array_slice($words, 0, 10);
                                                echo implode(" ", $limited) . (count($words) > 10 ? "..." : "");
                                            ?>
                                    </p>
                                </div>
                            </div>
                            <?php } ?>
                        </div>
                    </div>

                </aside>
            </div>
        </div>
    </div>
</section>

<!-- <style>
.breadcumb-title {
    color: black;
}

.breadcumb-menu li,
.breadcumb-menu a,
.breadcumb-menu span {
    color: black;
}

.breadcumb-menu li:after {
    color: black;
}
</style> -->




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