<?php
require_once __DIR__."/includes/header.php";

$slug=$_GET["slug"]??"";

$product_category=null;

foreach($products as $product){
    if($product["slug"]===$slug){
        $product_category=$product;
        break;
    }
}

if(!$product_category){
    http_response_code(404);
    $page_title="Product Not Found";
}else{
    $page_title=$product_category["category"];
}
?>


<?php if(!$product_category): ?>

<section class="page-hero">

    <div class="container-fluid px-lg-5">

        <div class="page-hero-inner">

            <span class="eyebrow">Product</span>

            <h1>
                Product <span>Not Found</span>
            </h1>

            <p>
                The product category you are looking for could not be found.
            </p>

            <div class="breadcrumb-wrap">
                <a href="index.php">Home</a>
                <i class="bi bi-chevron-right"></i>
                <a href="products.php">Products</a>
                <i class="bi bi-chevron-right"></i>
                <span>Not Found</span>
            </div>

        </div>

    </div>

</section>

<section class="product-not-found">

    <div class="container">

        <div class="product-not-found-inner">

            <i class="bi bi-box-seam"></i>

            <h2>Product Category Not Available</h2>

            <p>
                Please return to our product range and select another category.
            </p>

            <a href="products.php" class="btn btn-brand">
                View Products
                <i class="bi bi-arrow-right"></i>
            </a>

        </div>

    </div>

</section>

<?php else: ?>

<section class="page-hero product-category-hero">

    <div class="container-fluid px-lg-5">

        <div class="page-hero-inner">

            <span class="eyebrow">Product Category</span>

            <h1>
                <?=htmlspecialchars($product_category["category"])?>
            </h1>

            <p>
                Industrial equipment and systems designed for coating,
                painting, curing, drying and surface treatment applications.
            </p>

            <div class="breadcrumb-wrap">

                <a href="index.php">Home</a>

                <i class="bi bi-chevron-right"></i>

                <a href="products.php">Products</a>

                <i class="bi bi-chevron-right"></i>

                <span>
                    <?=htmlspecialchars($product_category["short_name"])?>
                </span>

            </div>

        </div>

    </div>

</section>

<section class="product-category-section">

    <div class="container-fluid px-lg-5">

        <div class="product-category-main">

            <div class="product-category-image">

                <img
                    src="<?=htmlspecialchars($product_category["image"])?>"
                    alt="<?=htmlspecialchars($product_category["category"])?>">

                <div class="product-category-image-overlay"></div>

                <div class="product-category-image-label">
                    <span>MVSK Industries LLP</span>
                    <strong>
                        <?=str_pad($product_category["id"],2,"0",STR_PAD_LEFT)?>
                    </strong>
                </div>

            </div>

            <div class="product-category-content">

                <span class="eyebrow">Our Solution</span>

                <h2>
                    <?=htmlspecialchars($product_category["category"])?>
                </h2>

                <div class="section-line"></div>

                <p>
                    MVSK Industries LLP provides industrial solutions
                    for applications requiring dependable coating,
                    painting, curing, drying or surface treatment
                    performance.
                </p>

                <?php if(!empty($product_category["items"])): ?>

    <div class="product-category-products">

        <div class="product-category-products-heading">
            <span>Available Solutions</span>
            <strong>
                <?=count($product_category["items"])?> Solutions
            </strong>
        </div>

        <div class="product-category-items">

            <?php foreach($product_category["items"] as $index=>$item): ?>

                <a
                    href="product.php?slug=<?=urlencode($item["slug"])?>"
                    class="product-category-item">

                    <span class="product-category-item-number">
                        <?=str_pad($index+1,2,"0",STR_PAD_LEFT)?>
                    </span>

                    <span class="product-category-item-name">
                        <?=htmlspecialchars($item["name"])?>
                    </span>

                    <i class="bi bi-arrow-up-right"></i>

                </a>

            <?php endforeach; ?>

        </div>

    </div>
 
    
                <?php else: ?>

                    <div class="product-category-single">

                        <span>Featured Solution</span>

                        <strong>
                            <?=htmlspecialchars($product_category["category"])?>
                        </strong>

                    </div>

                <?php endif; ?>

                <div class="product-category-actions">

                    <a href="contact.php#enquiry" class="btn btn-brand">
                        Request a Quote
                        <i class="bi bi-arrow-right"></i>
                    </a>

                    <a href="products.php" class="product-back-link">
                        <i class="bi bi-arrow-left"></i>
                        All Products
                    </a>

                </div>

            </div>

        </div>

    </div>

</section>

<section class="related-products-section">

    <div class="container-fluid px-lg-5">

        <div class="related-products-header">

            <div>

                <span class="eyebrow">Explore More</span>

                <h2>
                    Other <span>Product Solutions</span>
                </h2>

            </div>

            <a href="products.php" class="text-link">
                View All Products
                <i class="bi bi-arrow-right"></i>
            </a>

        </div>

        <div class="related-products-grid">

            <?php foreach($products as $related): ?>

                <?php if($related["slug"]===$product_category["slug"]) continue; ?>

                <a
                    href="product-category.php?slug=<?=urlencode($related["slug"])?>"
                    class="related-product">

                    <div class="related-product-image">

                        <img
                            src="<?=htmlspecialchars($related["image"])?>"
                            alt="<?=htmlspecialchars($related["category"])?>"
                            loading="lazy">

                    </div>

                    <div class="related-product-content">

                        <span>
                            Product Category
                        </span>

                        <h3>
                            <?=htmlspecialchars($related["category"])?>
                        </h3>

                        <i class="bi bi-arrow-up-right"></i>

                    </div>

                </a>

            <?php endforeach; ?>

        </div>

    </div>

</section>

<?php endif; ?>

<?php
require_once __DIR__."/includes/footer.php";
?>