<div class="content-wrapper">
    <section class="content-header">
        <h1>
            Espace
            <small>commercial</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Accueil</a></li>
            <li class="active">Espace commercial</li>
        </ol>
    </section>
    <section class="content">
        <div class="card shadow-lg border-0 rounded">
            <div class="row g-0">
                <!-- Left: Product Image -->
                <div class="col-md-6 text-center">
                    <img src="<?= base_url('assets/images/product_image/' . $products['image']) ?>"
                        alt="<?= $products['name'] ?>"
                        class="img-fluid rounded"
                        style="width: 100%; height: 100%; object-fit: cover;">
                </div>

                <!-- Right: Product Details -->
                <div class="col-md-6 p-4">
                    <h2 class="text-dark"><?= $products['name'] ?></h2>
                    <h4 class="text-success fw-bold"><?= number_format($products['prix_vente'], 0, ',', ' ') ?> MGA</h4>
                    <p class="text-muted">Numéro de serie: <strong><?= $products['sku'] ?></strong></p>
                    <p class="text-muted">
                        Disponibilité: 
                        <strong><?= $products['product_sold'] ? 'Indisponible' : 'Disponible' ?></strong>
                    </p>
                    <p class="text-secondary">Moteur N° <?= $products['numero_de_moteur'] ?></p>
                    <p class="text-secondary">Boutique <b><?= $stores ?></b></p>
                    <p class="text-secondary"><?= $products['description'] ?></p>
                    <p class="text-secondary"> 
                            <b>Etat</b> <br>
                            <?php 
                            switch($products['etats']) {
                                case 1:
                                    echo 'Kit';
                                    break;
                                case 2:
                                    echo 'Non kit';
                                    break;
                                default:
                                    echo 'Non défini';
                            }
                            ?>
                        </p>
                        <p class="text-secondary"><b>Type :</b>
                            <br> <?= $products['type'] ?></p></br>

                    <!-- Buttons -->
                    <div class="d-flex mt-4">
                        <div>
                            <a href="/orders/createFromEspace/<?= $products['id'] ?>" class="btn btn-primary btn-block mt-3"><i class="fa fa-shopping-cart"></i> Commande</a>
                        </div>
                        <button onclick="window.history.back()" class="btn btn-outline-secondary">
                            <i class="fa fa-arrow-left"></i> Retour à la boutique
                        </button>
                    </div>
                </div>
            </div>
            <h3>Galleries</h3>
            <div class="row">
                <?php foreach ($galleries as $key => $value) { ?>
                    <div class="col-md-3 col-xs-12 col-sm-6 mb-3" style="margin-bottom: 1%;">
                        <div class="card shadow-lg border-0 rounded">
                            <div class="card-header bg-success text-white text-center p-0.5">
                                <!-- Clickable Image -->
                                <a href="#" data-toggle="modal" data-target="#imageModal<?= $key ?>">
                                    <img src="<?= base_url('assets/images/product_image/' . $value['images']) ?>"
                                        alt="<?= $value['images'] ?>"
                                        class="img-fluid img-thumbnail rounded"
                                        style="width: 100%; height: 250px; object-fit: cover;">
                                </a>
                            </div>
                        </div>
                    </div>

                    <!-- Bootstrap Modal for Each Image -->
                    <div class="modal fade" id="imageModal<?= $key ?>" tabindex="-1" aria-labelledby="imageModalLabel<?= $key ?>" aria-hidden="true">
                        <div class="modal-dialog modal-dialog-centered">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="imageModalLabel<?= $key ?>">Visualisation d'image</h5>
                                    <button type="button" class="btn-close" data-dismiss="modal" aria-label="Close"> <i class="fas fa-times"></i></button>
                                </div>
                                <div class="modal-body text-center" style="width: 100%;">
                                    <img src="<?= base_url('assets/images/product_image/' . $value['images']) ?>"
                                        alt="<?= $value['images'] ?>"
                                        class="img-fluid rounded"
                                        style="width: 100%; height: 100%; object-fit: cover;">>
                                </div>
                            </div>
                        </div>
                    </div>
                <?php } ?>
            </div>

        </div>
    </section>
</div>
<script>
    $("#espaceMainMenu").addClass('active');
</script>