<?php

require_once __DIR__ . "/data/contact.php";
require_once __DIR__ . "/includes/header.php";
require_once 'admin/inc/config.php';

$statement = $pdo->prepare("
    SELECT
        id,
        product_name,
        product_slug,
        main_image
    FROM tbl_service
    WHERE status = 1
        AND top_category_id = 13
    ORDER BY id DESC
");
$statement->execute();
$machines = $statement->fetchAll(PDO::FETCH_ASSOC);

function e($value): string
{
    return htmlspecialchars(
        (string)($value ?? ''),
        ENT_QUOTES,
        'UTF-8'
    );
}

?>

<style>
    .machines-page-hero {
        position: relative;
        background-size: cover;
        background-position: center;
        background-repeat: no-repeat;
        color: #fff;
    }

    .machines-page-hero .page-hero-inner {
        position: relative;
        z-index: 2;
    }

    .machines-page-hero .eyebrow {
        color: var(--brand);
    }

    .machines-page-hero h1 {
        color: #fff;
    }

    .machines-page-hero .breadcrumb-wrap {
        color: #fff;
    }

    .machines-page-hero .breadcrumb-wrap a {
        color: var(--brand);
    }

    @media (max-width: 767px) {

        .machines-page-hero {
            padding: 65px 0;
            background-position: center center;
        }

        .machines-page-hero h1 {
            font-size: 34px;
            line-height: 1.2;
        }

        .machines-page-hero .breadcrumb-wrap {
            flex-wrap: wrap;
            gap: 7px;
            margin-top: 22px;
            font-size: 14px;
        }

    }
</style>


<section
    class="page-hero machines-page-hero"
    style="
        background-image:
            linear-gradient(
                90deg,
                rgba(0, 0, 0, .78) 0%,
                rgba(0, 0, 0, .38) 45%,
                rgba(0, 0, 0, .12) 80%
            ),
            url('<?= e($contact_page['banner_image'] ?? '') ?>');
    ">

    <div class="container-fluid px-lg-5">

        <div class="page-hero-inner">

            <h1>
                Our
                Machines
            </h1>

            <div class="breadcrumb-wrap">

                <a href="index.php">
                    Home
                </a>

                <i class="bi bi-chevron-right"></i>

                <span>
                    Our Machines
                </span>

            </div>

        </div>

    </div>

</section>


<section class="products-page-section">

    <div class="container-fluid px-lg-5">

        <div class="products-page-intro">

            <div>

                <span class="eyebrow">
                    Our Machines
                </span>

                <h2>
                    Advanced Machinery for
                    Industrial Applications
                </h2>

            </div>

            <p>
                Explore our range of industrial machines engineered for
                reliable performance, efficient operation and consistent
                production requirements.
            </p>

        </div>


        <div class="products-page-grid">

            <?php if (!empty($machines)): ?>

                <?php foreach ($machines as $machine): ?>

                    <?php
                    $machineImage = $machine['main_image'] ?? '';
                    ?>

                    <a
                        href="product.php?slug=<?= urlencode(
                            $machine['product_slug'] ?? ''
                        ) ?>"
                        class="product-page-card">

                        <div class="product-page-image">

                            <?php if (!empty($machineImage)): ?>

                                <img
                                    src="<?= rtrim($site['base_url'], '/') ?>/admin/assets/images/products/<?= e($machineImage) ?>"
                                    alt="<?= e($machine['product_name']) ?>"
                                    loading="lazy">

                            <?php else: ?>

                                <img
                                    src="<?= rtrim($site['base_url'], '/') ?>/admin/assets/images/products/default.jpg"
                                    alt="<?= e($machine['product_name']) ?>"
                                    loading="lazy">

                            <?php endif; ?>

                            <div class="product-page-overlay"></div>

                        </div>


                        <div class="product-page-content">

                            <h3>
                                <?= e($machine['product_name']) ?>
                            </h3>

                            <span class="product-page-link">

                                View Machine

                                <i class="bi bi-arrow-right"></i>

                            </span>

                        </div>

                    </a>

                <?php endforeach; ?>

            <?php else: ?>

                <div class="col-12">

                    <p>
                        No machines available.
                    </p>

                </div>

            <?php endif; ?>

        </div>

    </div>

</section>


<section class="products-page-cta">

    <div class="container-fluid px-lg-5">

        <div class="products-page-cta-inner">

            <div>

                <span class="eyebrow">
                    Need a Custom Solution?
                </span>

                <h2>
                    Tell Us About Your
                    Application
                </h2>

            </div>

            <a
                href="contact.php#enquiry"
                class="btn btn-brand">

                Request a Quote

                <i class="bi bi-arrow-right"></i>

            </a>

        </div>

    </div>

</section>


<?php
require_once __DIR__ . "/includes/footer.php";
?>