<?php $__env->startSection('search-bar'); ?>
    <div class="row g-3 mb-4 align-items-center justify-content-between">
        <div class="col-auto">
            <h1 class="app-page-title mb-0" style="color: #404242">LES PROSPERTS</h1>
        </div>
        <div class="col-auto">
            <div class="page-utilities">
                <div class="row g-2 justify-content-start justify-content-md-end align-items-center">
                    <div class="col-auto">
                        <form action="#" method="GET" class="table-search-form row gx-1 align-items-center">
                            <div class="col-auto">
                                <input type="text" id="searchInput" name="search" class="form-control search-orders"
                                    placeholder="Recherche ... " onkeyup="searchClients()">
                            </div>
                        </form>
                    </div><!--//col-->

                    <div class="col-auto d-flex align-items-center gap-2">
                        <?php if(auth()->user()->role == 'super-admin'): ?>
                        <div class="dropdown">
                            <button class="btn app-btn-secondary dropdown-toggle" type="button" id="exportDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                                <i class="fas fa-file-pdf"></i> Exporter en pdf
                            </button>
                            <ul class="dropdown-menu" aria-labelledby="exportDropdown">
                                <li><a class="dropdown-item" href="<?php echo e(route('clients.pdf')); ?>"><i class="fas fa-file-pdf"></i> Exporter Prospert</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('prospects.pdf')); ?>"><i class="fas fa-file-pdf"></i> Exporter Clients</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('fournisseurs.pdf')); ?>"><i class="fas fa-file-pdf"></i> Exporter Fournisseurs</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('fournisseurClients.pdf')); ?>"><i class="fas fa-file-pdf"></i> Exporter Fournisseur Clients</a></li>
                                <li><hr class="dropdown-divider"></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('allData.pdf')); ?>"><i class="fas fa-file-pdf"></i> Exporter Toutes les Tables</a></li>
                            </ul>
                        </div>
                        <div class="dropdown">
                            <button class="btn app-btn-secondary dropdown-toggle" type="button" id="exportDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                                <i class="fas fa-file-excel"></i> Exporter en Excel
                            </button>
                            <ul class="dropdown-menu" aria-labelledby="exportDropdown">
                                <li><a class="dropdown-item" href="<?php echo e(route('export.clients')); ?>"><i class="fas fa-file-excel"></i> Exporter Prospert</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('export.prospects')); ?>"><i class="fas fa-file-excel"></i> Exporter Clients</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('export.fournisseurs')); ?>"><i class="fas fa-file-excel"></i> Exporter Fournisseurs</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('export.fournisseurClients')); ?>"><i class="fas fa-file-excel"></i> Exporter Fournisseur Clients</a></li>
                                <li><hr class="dropdown-divider"></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('export.excel')); ?>"><i class="fas fa-file-excel"></i> Exporter Toutes les Tables</a></li>
                            </ul>
                        </div>
                        <?php elseif(auth()->user()->role == 'admin'): ?>
                        <div class="dropdown">
                            <button class="btn app-btn-secondary dropdown-toggle" type="button" id="exportDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                                <i class="fas fa-file-pdf"></i> EXPORTER en pdf
                            </button>
                            <ul class="dropdown-menu" aria-labelledby="exportDropdown">
                                <li><a class="dropdown-item" href="<?php echo e(route('clients.pdf')); ?>"><i class="fas fa-file-pdf"></i> Exporter Prospert</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('prospects.pdf')); ?>"><i class="fas fa-file-pdf"></i> Exporter Clients</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('fournisseurs.pdf')); ?>"><i class="fas fa-file-pdf"></i> Exporter Fournisseurs</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('fournisseurClients.pdf')); ?>"><i class="fas fa-file-pdf"></i> Exporter Fournisseur Clients</a></li>
                                <li><hr class="dropdown-divider"></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('allData.pdf')); ?>"><i class="fas fa-file-pdf"></i> Exporter Toutes les Tables</a></li>
                            </ul>
                        </div>
                        <div class="dropdown">
                            <button class="btn app-btn-secondary dropdown-toggle" type="button" id="exportDropdown" data-bs-toggle="dropdown" aria-expanded="false">
                                <i class="fas fa-file-excel"></i> Exporter en Excel
                            </button>
                            <ul class="dropdown-menu" aria-labelledby="exportDropdown">
                                <li><a class="dropdown-item" href="<?php echo e(route('export.clients')); ?>"><i class="fas fa-file-excel"></i> Exporter Prospert</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('export.prospects')); ?>"><i class="fas fa-file-excel"></i> Exporter Clients</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('export.fournisseurs')); ?>"><i class="fas fa-file-excel"></i> Exporter Fournisseurs</a></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('export.fournisseurClients')); ?>"><i class="fas fa-file-excel"></i> Exporter Fournisseur Clients</a></li>
                                <li><hr class="dropdown-divider"></li>
                                <li><a class="dropdown-item" href="<?php echo e(route('export.excel')); ?>"><i class="fas fa-file-excel"></i> Exporter Toutes les Tables</a></li>
                            </ul>
                        </div>
                        <?php endif; ?>
                    </div>
                    
                    
                </div><!--//row-->
            </div><!--//table-utilities-->
        </div><!--//col-auto-->
    </div><!--//row-->
<?php $__env->stopSection(); ?>

<?php $__env->startSection('parties-prenantes'); ?>
    <nav id="orders-table-tab" class="orders-table-tab app-nav-tabs nav shadow-sm flex-column flex-sm-row mb-4">
        <a href="/prospectsSection" class="flex-sm-fill text-sm-center nav-link">Clients</a>
        <a href="/clientsSection" class="flex-sm-fill text-sm-center nav-link active">Prosperts</a>
        <a href="/suppliersSection" class="flex-sm-fill text-sm-center nav-link">Fournisseurs</a>
        <a href="/suppliersAndClientsSection" class="flex-sm-fill text-sm-center nav-link">Fournisseurs Clients</a>
    </nav>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('errorContent'); ?>
    <script>
        document.addEventListener("DOMContentLoaded", function() {
            var modalType = document.getElementById('modals').getAttribute('data-error');

            if (modalType === 'default') {
                var addModal = new bootstrap.Modal(document.getElementById('add_client'));
                addModal.show();
            } else if (modalType === 'update') {
                var updateModal = new bootstrap.Modal(document.getElementById('update_client'));
                updateModal.show();
            } else if (modalType === 'remark') {
                var remark = new bootstrap.Modal(document.getElementById('remark'));
                remark.show();
            }
        });
    </script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
    <div id="modals" style="display:none;" data-error="<?php echo e(session('modalType')); ?>"></div>
    <form action="<?php echo e(route('client.add')); ?>" method="POST">
        <?php echo csrf_field(); ?>
        <div class="modal fade" id="add_client" tabindex="-1" aria-labelledby="clientModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="clientModalLabel">Ajouter un client</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <div class="modal-body">

                        <label class="form-label"><strong class="det">Nom de la société</strong></label><br>
                        <input type="text" class="form-control" name="nomSociete_client"
                            placeholder="Entrer le nom de la société..." value="<?php echo e(old('nomSociete_client')); ?>" />
                        <?php $__errorArgs = ['nomSociete_client', 'default'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-danger"><?php echo e($message); ?></span> <br>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>



                        <label class="form-label"><strong class="det">GSM1 de la société</strong></label><br>
                        <input type="tel" class="form-control" name="GSM1_client"
                            placeholder="Entrer le GSM1..." value="<?php echo e(old('GSM1_client')); ?>" pattern="[0-9]{10,15}" oninput="this.value = this.value.replace(/[^0-9]/g, '')"/>
                        <?php $__errorArgs = ['GSM1_client', 'default'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-danger"><?php echo e($message); ?></span> <br>

                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>


                        <label class="form-label"><strong class="det">GSM2 de la société</strong></label><br>
                        <input type="tel" class="form-control" name="GSM2_client"
                            placeholder="Entrer le GSM2..." value="<?php echo e(old('GSM2_client')); ?>" pattern="[0-9]{10,15}" oninput="this.value = this.value.replace(/[^0-9]/g, '')"/>
                        <?php $__errorArgs = ['GSM2_client', 'default'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-danger"><?php echo e($message); ?></span> <br>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                        
                        
                        <label class="form-label"><strong class="det">Personne à contacter</strong></label><br>
                        <input type="text" class="form-control" name="nom_client" placeholder="Entrer le client..."
                            value="<?php echo e(old('nom_client')); ?>" />
                        <?php $__errorArgs = ['nom_client', 'default'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-danger"><?php echo e($message); ?></span> <br>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>


                        <label class="form-label"><strong class="det">Numero de telephone</strong></label><br>
                        <input type="tel" class="form-control" name="tele_client"
                            placeholder="Entrer le contact..." value="<?php echo e(old('tele_client')); ?>" pattern="[0-9]{10,15}" oninput="this.value = this.value.replace(/[^0-9]/g, '')"/>
                        <?php $__errorArgs = ['tele_client', 'default'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-danger"><?php echo e($message); ?></span> <br>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>


                        <label class="form-label"><strong class="det">Email</strong></label><br>
                        <input type="email" class="form-control" name="email_client" placeholder="Entrer l'émail..."
                            value="<?php echo e(old('email_client')); ?>" />
                        <?php $__errorArgs = ['email_client', 'default'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-danger"><?php echo e($message); ?></span> <br>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>


                        <label class="form-label"><strong class="det">Lien de la société</strong></label><br>
                        <input type="url" class="form-control" name="lien_client"
                            placeholder="Entrer le lien..." value="<?php echo e(old('lien_client')); ?>"/>
                        <?php $__errorArgs = ['lien_client', 'default'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-danger"><?php echo e($message); ?></span> <br>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>

                        <label class="form-label"><strong class="det">Ville</strong></label>
                        <input type="text" class="form-control" name="ville_client" placeholder="Entrer la ville..."
                            value="<?php echo e(old('ville_client')); ?>" />
                        <?php $__errorArgs = ['ville_client', 'default'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="text-danger"><?php echo e($message); ?></span> <br>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>

                        <label for="categorie" class="form-label"><strong class="det">Catégorie</strong></label>
                        <select id="categorie" class="form-control" name="categorie_id">
                            <option value="">Sélectionner la catégorie</option>
                            <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $categorie): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($categorie->id); ?>"
                                    <?php echo e(request('categorie_id') == $categorie->id ? 'selected' : ''); ?>>
                                    <?php echo e($categorie->nom_categorie); ?>

                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>

                        <!-- Label pour les sous-catégories, caché tant qu'une catégorie n'est pas sélectionnée -->
                        <label for="sous-categorie" class="form-label" id="label-sous-categorie"
                            <?php echo e(request('categorie_id') ? '' : 'style=display:none;'); ?>>
                            <strong class="det">Sous-Catégorie</strong>
                        </label>

                        <!-- Sélecteur de sous-catégorie, caché tant qu'une catégorie n'est pas sélectionnée -->
                        <select id="sous-categorie" class="form-control" name="sous_categorie_id"
                            <?php echo e(request('categorie_id') ? '' : 'style=display:none;'); ?>>
                            <option value="">Sélectionner une sous-catégorie</option>
                            <?php if(request('categorie_id')): ?>
                                <?php $__currentLoopData = $sousCategories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $sousCategorie): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($sousCategorie->id); ?>"
                                        <?php echo e(request('sous_categorie_id') == $sousCategorie->id ? 'selected' : ''); ?>>
                                        <?php echo e($sousCategorie->nom_produit); ?>

                                    </option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            <?php endif; ?>
                        </select>



                    </div>
                    <div class="modal-footer">
                        <input type="submit" class="btn btn-success" value="Ajouter" data-bs-dismiss="modal">
                    </div>
                </div>
            </div>
        </div>
    </form>

    <div class="app-card app-card-orders-table mb-5">
        <div class="app-card-body">
            <div class="table-responsive">
                <table id="client-table" class="table app-table-hover mb-0 text-center">
                    <thead>
                        <tr>
                            <th class="cell">Nom de la société</th>
                            <th class="cell">GSM1 de la société</th>
                            <th class="cell">GSM2 de la société</th>
                            <th class="cell">Personne à contacter</th>
                            <th class="cell">Numero de telephone</th>
                            <th class="cell">Email</th>
                            <th class="cell">Lien de la société</th>
                            <th class="cell">Ville</th>
                            <th class="cell">Catégorie</th>
                            <th class="cell">Contacté Par</th>
                            <th class="cell text-end">
                                <button type="button" class="btn app-btn-secondary" data-bs-toggle="modal"
                                    data-bs-target="#add_client">
                                    Ajouter
                                </button>

                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                            $utilisateurs = \App\Models\User::get();
                        ?>
                        <?php $__currentLoopData = $clients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $client): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td class="cell2">
                                    <?php echo !empty($client->nomSociete_client) ? $client->nomSociete_client : '<span class="text-danger">Particulier</span>'; ?>

                                </td>
                                <td class="cell2">
                                    <?php echo !empty($client->GSM1_client) ? $client->GSM1_client : '<span class="text-danger">Non disponible</span>'; ?>

                                </td>
                                <td class="cell2">
                                    <?php echo !empty($client->GSM2_client) ? $client->GSM2_client : '<span class="text-danger">Non disponible</span>'; ?>

                                </td>
                                <td class="cell2">
                                    <?php echo !empty($client->nom_client) ? $client->nom_client : '<span class="text-danger">Non disponible</span>'; ?>

                                </td>
                                <td class="cell2">
                                    <?php echo !empty($client->tele_client) ? $client->tele_client : '<span class="text-danger">Non disponible</span>'; ?>

                                </td>
                                <td class="cell2">
                                    <?php echo !empty($client->email_client) ? $client->email_client : '<span class="text-danger">Non disponible</span>'; ?>

                                </td>
                                <td class="cell2">
                                    <?php if(!empty($client->lien_client)): ?>
                                        <a href="<?php echo e($client->lien_client); ?>" target="_blank" class="text-primary">
                                            <?php echo e(Str::limit($client->lien_client, 20)); ?> <!-- Limite l'affichage -->
                                        </a>
                                    <?php else: ?>
                                        <span class="text-danger">Non disponible</span>
                                    <?php endif; ?>
                                </td>
                                <td class="cell2"><?php echo e($client->ville_client); ?></td>
                                <td class="cell2">
                                    <?php $__empty_1 = true; $__currentLoopData = $client->categorieClients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $assoc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                                        <?php if($assoc->categorie): ?>
                                            <?php echo e($assoc->categorie->nom_categorie); ?>

                                        <?php endif; ?>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                                        Non catégorisé
                                    <?php endif; ?>
                                </td>

                                <td class="cell2">
                                    <?php echo e(!empty($client->utilisateur->name) ? $client->utilisateur->name : 'Personne'); ?>

                                </td>

                                <?php if(auth()->user()->role == 'super-admin'): ?>
                                    <td class="button-container">
                                        <div class="d-flex align-items-center gap-2"
                                            style="display: inline; border-radius: 1cap; border-style: inherit; color: transparent;">
                                            <a href="#" class="btn btn-outline-primary border-btn me-4"
                                                data-bs-toggle="modal" data-bs-target="#update_client"
                                                data-id="<?php echo e($client->id); ?>"
                                                data-society="<?php echo e($client->nomSociete_client); ?>"
                                                data-GSM1="<?php echo e($client->GSM1_client); ?>"
                                                data-GSM2="<?php echo e($client->GSM2_client); ?>"
                                                data-lien="<?php echo e($client->lien_client); ?>"
                                                data-name="<?php echo e($client->nom_client); ?>"
                                                data-tele="<?php echo e($client->tele_client); ?>"
                                                data-email="<?php echo e($client->email_client); ?>"
                                                data-ville="<?php echo e($client->ville_client); ?>"
                                                data-category="<?php echo e($client->categories->first()?->id ?? ''); ?>">
                                                Modifier
                                            </a>




                                            <button type="button" class="btn btn-outline-success border-btn me-4"
                                                data-bs-toggle="modal" data-bs-target="#remark-<?php echo e($client->id); ?>">
                                                Remarque
                                            </button>



                                            <button type="button"
                                                class="btn btn-outline-info detailButton border-btn me-4"
                                                data-bs-toggle="modal"
                                                data-bs-target="#ModalClientDetails-<?php echo e($client->id); ?>"
                                                data-name="<?php echo e($client->nom_client); ?>"
                                                data-email="<?php echo e($client->email_client); ?>"
                                                data-tele="<?php echo e($client->tele_client); ?>"
                                                data-ville="<?php echo e($client->ville_client); ?>"
                                                data-society-name="<?php echo e(!empty($client->nomSociete_client) ? $client->nomSociete_client : 'Particulier'); ?>"
                                                data-GSM1="<?php echo e(!empty($client->GSM1_client) ? $client->GSM1_client : 'Non disponible'); ?>"
                                                data-GSM2="<?php echo e(!empty($client->GSM2_client) ? $client->GSM2_client : 'Non disponible'); ?>"
                                                data-lien="<?php echo e(!empty($client->lien_client) ? $client->lien_client : 'Non disponible'); ?>"
                                                data-remark="<?php echo e($client->remark); ?>"
                                                data-user="<?php echo e(!empty($client->utilisateur->name) ? $client->utilisateur->name : 'Personne'); ?>">

                                                Details
                                            </button>


                                            <form action="<?php echo e(route('client.destroy', $client->id)); ?>" method="POST"
                                                style="display: inline border-radius: 1cap; border-style: inherit; color: transparent;"
                                                id="delete-form-<?php echo e($client->id); ?>">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('DELETE'); ?>
                                                <button type="button" class="btn btn-outline-danger border-btn me-4"
                                                    onclick="confirmDelete(<?php echo e($client->id); ?>)">
                                                    Supprimer
                                                </button>
                                            </form>

                                            <form class="user-form"
                                                action="<?php echo e(route('user.select.client', $client->id)); ?>" method="POST">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('POST'); ?>
                                                <select class="form-select userSelect" aria-label="Default select example"
                                                    data-client-id="<?php echo e($client->id); ?>" style="margin-right:100px"
                                                    name="user_id">
                                                    <option value="">Contacté Par</option>
                                                    <?php $__currentLoopData = $utilisateurs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($user->id); ?>"
                                                            <?php echo e(old('user_id') == $user->id ? 'selected' : ''); ?>>
                                                            <?php echo e($user->name); ?>

                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </form>

                                            <form class="client-form" action="<?php echo e(route('client.select', $client->id)); ?>"
                                                method="POST">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('POST'); ?>
                                                <select name="status" id="" class="form-select status-select">
                                                    <option value="">Selectionner la table</option>
                                                    <?php $__currentLoopData = $select; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($item); ?>"><?php echo e($item); ?>

                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </form>
                                        </div>
                                    </td>
                                <?php elseif(auth()->user()->role == 'admin'): ?>
                                    <td class="button-container">
                                        <div class="d-flex align-items-center gap-2"
                                            style="display: inline; border-radius: 1cap; border-style: inherit; color: transparent;">
                                            <a href="#" class="btn btn-outline-primary border-btn me-4"
                                                data-bs-toggle="modal" data-bs-target="#update_client"
                                                data-id="<?php echo e($client->id); ?>"
                                                data-society="<?php echo e($client->nomSociete_client); ?>"
                                                data-GSM1="<?php echo e($client->GSM1_client); ?>"
                                                data-GSM2="<?php echo e($client->GSM2_client); ?>"
                                                data-lien="<?php echo e($client->lien_client); ?>"
                                                data-name="<?php echo e($client->nom_client); ?>"
                                                data-tele="<?php echo e($client->tele_client); ?>"
                                                data-email="<?php echo e($client->email_client); ?>"
                                                data-ville="<?php echo e($client->ville_client); ?>"
                                                data-category="<?php echo e($client->categories->first()?->id ?? ''); ?>">
                                                Modifier
                                            </a>


                                            <form class="user-form"
                                                action="<?php echo e(route('user.select.client', $client->id)); ?>" method="POST">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('POST'); ?>
                                                <select class="form-select userSelect" aria-label="Default select example"
                                                    data-client-id="<?php echo e($client->id); ?>" style="margin-right:100px"
                                                    name="user_id">
                                                    <option value="">Contacté Par</option>
                                                    <?php $__currentLoopData = $utilisateurs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($user->id); ?>"
                                                            <?php echo e(old('user_id') == $user->id ? 'selected' : ''); ?>>
                                                            <?php echo e($user->name); ?>

                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </form>

                                            <button type="button" class="btn btn-outline-success border-btn me-4"
                                                data-bs-toggle="modal" data-bs-target="#remark-<?php echo e($client->id); ?>">
                                                Remarque
                                            </button>



                                            <button type="button"
                                                class="btn btn-outline-info detailButton border-btn me-4"
                                                data-bs-toggle="modal"
                                                data-bs-target="#ModalClientDetails-<?php echo e($client->id); ?>"
                                                data-name="<?php echo e($client->nom_client); ?>"
                                                data-email="<?php echo e($client->email_client); ?>"
                                                data-tele="<?php echo e($client->tele_client); ?>"
                                                data-ville="<?php echo e($client->ville_client); ?>"
                                                data-society-name="<?php echo e(!empty($client->nomSociete_client) ? $client->nomSociete_client : 'Particulier'); ?>"
                                                data-GSM1="<?php echo e(!empty($client->GSM1_client) ? $client->GSM1_client : 'Non disponible'); ?>"
                                                data-GSM2="<?php echo e(!empty($client->GSM2_client) ? $client->GSM2_client : 'Non disponible'); ?>"
                                                data-lien="<?php echo e(!empty($client->lien_client) ? $client->lien_client : 'Non disponible'); ?>"
                                                data-remark="<?php echo e($client->remark); ?>"
                                                data-user="<?php echo e(!empty($client->utilisateur->name) ? $client->utilisateur->name : 'Personne'); ?>">

                                                Details
                                            </button>

                                            <form class="client-form" action="<?php echo e(route('client.select', $client->id)); ?>"
                                                method="POST">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('POST'); ?>
                                                <select name="status" id="" class="form-select status-select">
                                                    <option value="">Selectionner la table</option>
                                                    <?php $__currentLoopData = $select; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($item); ?>"><?php echo e($item); ?>

                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </form>
                                        </div>
                                    </td>
                                <?php elseif(auth()->user()->role == 'utilisateur'): ?>
                                    <td class="button-container">
                                        <div class="d-flex align-items-center gap-2"
                                            style="display: inline; border-radius: 1cap; border-style: inherit; color: transparent;">


                                            <button type="button" class="btn btn-outline-success border-btn me-4"
                                                data-bs-toggle="modal" data-bs-target="#remark-<?php echo e($client->id); ?>">
                                                Remarque
                                            </button>



                                            <button type="button"
                                                class="btn btn-outline-info detailButton border-btn me-4"
                                                data-bs-toggle="modal"
                                                data-bs-target="#ModalClientDetails-<?php echo e($client->id); ?>"
                                                data-name="<?php echo e($client->nom_client); ?>"
                                                data-email="<?php echo e($client->email_client); ?>"
                                                data-tele="<?php echo e($client->tele_client); ?>"
                                                data-ville="<?php echo e($client->ville_client); ?>"
                                                data-society-name="<?php echo e(!empty($client->nomSociete_client) ? $client->nomSociete_client : 'Particulier'); ?>"
                                                data-GSM1="<?php echo e(!empty($client->GSM1_client) ? $client->GSM1_client : 'Non disponible'); ?>"
                                                data-GSM2="<?php echo e(!empty($client->GSM2_client) ? $client->GSM2_client : 'Non disponible'); ?>"
                                                data-lien="<?php echo e(!empty($client->lien_client) ? $client->lien_client : 'Non disponible'); ?>"
                                                data-remark="<?php echo e($client->remark); ?>"
                                                data-user="<?php echo e(!empty($client->utilisateur->name) ? $client->utilisateur->name : 'Personne'); ?>">

                                                Details
                                            </button>
                                            <form class="user-form"
                                                action="<?php echo e(route('user.select.client', $client->id)); ?>" method="POST">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('POST'); ?>
                                                <select class="form-select userSelect" aria-label="Default select example"
                                                    data-client-id="<?php echo e($client->id); ?>" style="margin-right:100px"
                                                    name="user_id">
                                                    <option value="">Contacté Par</option>
                                                    <?php $__currentLoopData = $utilisateurs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($user->id); ?>"
                                                            <?php echo e(old('user_id') == $user->id ? 'selected' : ''); ?>>
                                                            <?php echo e($user->name); ?>

                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </form>
                                            <form class="client-form" action="<?php echo e(route('client.select', $client->id)); ?>"
                                                method="POST">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('POST'); ?>
                                                <select name="status" id="" class="form-select status-select">
                                                    <option value="">Selectionner la table</option>
                                                    <?php $__currentLoopData = $select; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <option value="<?php echo e($item); ?>"><?php echo e($item); ?>

                                                        </option>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </select>
                                            </form>
                                        </div>
                                    </td>
                                <?php endif; ?>
                                <form action="<?php echo e(route('remark.client', $client->id)); ?>" method="POST">
                                    <?php echo csrf_field(); ?>
                                    <div class="modal fade" id="remark-<?php echo e($client->id); ?>" tabindex="-1"
                                        aria-labelledby="exampleModalLabel" aria-hidden="true">
                                        <div class="modal-dialog modal-dialog-centered">
                                            <div class="modal-content">
                                                <div class="modal-header">
                                                    <h5 class="modal-title" id="exampleModalLabel">REMARQUE</h5>
                                                    <button type="button" class="btn-close" data-bs-dismiss="modal"
                                                        aria-label="Close"></button>
                                                </div>
                                                <div class="modal-body">

                                                    <div class="form-group">
                                                        <textarea name="remark" id="remarque" class="form-control" style="height: 100px"><?php echo e(old('remark', $client->remark)); ?></textarea>
                                                        <?php $__errorArgs = ['remark'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                            <div class="alert alert-danger">
                                                                <?php echo e($message); ?></div>
                                                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                                    </div>

                                                </div>
                                                <div class="modal-footer">
                                                    <button type="submit" class="btn btn-success">Ajouter la
                                                        remarque</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                            </tr>
                            <div class="modal fade" id="ModalClientDetails-<?php echo e($client->id); ?>" tabindex="-1"
                                aria-labelledby="exampleModalLabel" aria-hidden="true">
                                <div class="modal-dialog modal-dialog-centered">
                                    <div class="modal-content">
                                        <div class="modal-header">
                                            <h5>Details du client
                                            </h5>
                                            <button type="button" class="btn-close" data-bs-dismiss="modal"
                                                aria-label="Close"></button>
                                        </div>
                                        <div class="modal-body">
                                            <div class="row">

                                                <div class="col-6 det" style="font-size: 18px">Nom de la socité</div>
                                                <div class="col-6 showSocietyClient"><span style="font-size: 18px"
                                                        id="showSocietyDetail-<?php echo e($client->id); ?>"></span></div>

                                                <div class="col-6 det" style="font-size: 18px">GSM1 de la société</strong>
                                                </div>
                                                <div class="col-6 showGSM1Client"><span style="font-size: 18px"
                                                        id="showGSM1Detail-<?php echo e($client->id); ?>"></span></div>

                                                <div class="col-6 det" style="font-size: 18px">GSM2 de la société</strong>
                                                </div>
                                                <div class="col-6 showGSM2Client"><span style="font-size: 18px"
                                                        id="showGSM2Detail-<?php echo e($client->id); ?>"></span></div>

                                                <div class="col-6 det" style="font-size: 18px">Personne à
                                                    contacter</strong></div>
                                                <div class="col-6 showNameClient"><span style="font-size: 18px"
                                                        id="showNameDetail-<?php echo e($client->id); ?>"></span></div>

                                                <div class="col-6 det" style="font-size: 18px">Numero De
                                                    Telephone</strong></div>
                                                <div class="col-6 showContactClient"><span style="font-size: 18px"
                                                        id="showContactDetail-<?php echo e($client->id); ?>"></span></div>

                                                <div class="col-6 det" style="font-size: 18px">Email</strong></div>
                                                <div class="col-6 showEmailClient"><span style="font-size: 18px"
                                                        id="showEmailDetail-<?php echo e($client->id); ?>"></span></div>
                                                
                                                
                                                <div class="col-6 det" style="font-size: 18px">Lien de la société</strong>
                                                </div>
                                                <div class="col-6 showLienClient"><a href="<?php echo e($client->lien_client); ?>" target="_blank" class="text-primary" style="font-size: 18px">
                                                    <?php echo e(Str::limit($client->lien_client, 20)); ?> <!-- Limite l'affichage -->
                                                </a></div>

                                                <div class="col-6 det" style="font-size: 18px">Ville</strong></div>
                                                <div class="col-6 showVilleClient"><span style="font-size: 18px"
                                                        id="showVilleDetail-<?php echo e($client->id); ?>"></span></div>



                                                <div class="col-6 det" style="font-size: 18px">Les catégories</strong>
                                                </div>
                                                <div class="col-6">
                                                    <select
                                                        class="form-select form-select-sm col-6 info-client showCategoryClient"
                                                        aria-label=".form-select-sm example"
                                                        id="categories-<?php echo e($client->id); ?>" style="color: #5d6778">
                                                        <option class="col-6" value="" selected>Voir la(les)
                                                            catégories</option>
                                                        <?php $__currentLoopData = $client->allCategories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $categorie): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                            <option value="<?php echo e($categorie->id); ?>">
                                                                <?php echo e($categorie->nom_categorie); ?>

                                                            </option>
                                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                    </select>
                                                </div>

                                                <div class="col-6 det" style="font-size: 18px">Sous-Catégorie</strong>
                                                </div>
                                                <div class="col-6">
                                                    <select
                                                        class="form-select form-select-sm col-6 info-client showProductClient"
                                                        aria-label=".form-select-sm example"
                                                        id="products-<?php echo e($client->id); ?>"
                                                        style="color: #5d6778; font-size: 15px"><strong>
                                                            <option class="col-6" value="" selected>Voir les
                                                                produits associé</option>
                                                        </strong>
                                                    </select>
                                                </div>

                                                <div class="col-6 det" style="font-size: 18px">Contacté Par</strong></div>
                                                <div class="col-6 showUserClient"><span style="font-size: 18px"
                                                        id="showUserDetail-<?php echo e($client->id); ?>"></span></div>

                                                <div class="col-6 det" style="font-size: 18px">Remarque</strong></div>
                                                <div class="col-6 showRemarkClient"><span style="font-size: 18px"
                                                        id="showRemarkDetail-<?php echo e($client->id); ?>"></span></div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    </div>
    </div>

    <!--//modifier-client-->
    <?php if(isset($client)): ?>
        <div class="modal fade" id="update_client" tabindex="-1" aria-labelledby="exampleModalLabel"
            aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <form action="<?php echo e(route('client.update')); ?>" method="POST">
                        <?php echo csrf_field(); ?>
                        <input type="hidden" name="id" id="updateClientId">
                        <div class="modal-header">
                            <h5 class="modal-title" id="exampleModalLabel">Modifier le client</h5>
                            <button type="button" class="btn-close" data-bs-dismiss="modal"
                                aria-label="Close"></button>
                        </div>
                        <div class="modal-body">
                            <div>
                                <label class="form-label"><strong class="det">Nom de la société</strong></label>
                                <input type="text" class="form-control" name="newNomSociete_client"
                                    placeholder="Entrer le nom de la société..." id="updateClientSociety"
                                    value="<?php echo e(old('newNomSociete_client', $client->nomSociete_client)); ?>" />
                                <?php if($errors->has('newNomSociete_client')): ?>
                                    <span class="text-danger">
                                        <?php echo e($errors->first('newNomSociete_client')); ?></span> <br>
                                <?php endif; ?>

                            </div>
                            <div>
                                <label class="form-label"><strong class="det">GSM1 de la société</strong></label>
                                <input type="tel" class="form-control" name="newGSM1_client"
                                    placeholder="Entrer GSM1..." id="updateClientGSM1"
                                    value="<?php echo e(old('newGSM1_client', $client->GSM1_client)); ?>" pattern="[0-9]{10,15}" oninput="this.value = this.value.replace(/[^0-9]/g, '')"/>
                                <?php if($errors->has('newGSM1_client')): ?>
                                    <span class="text-danger">
                                        <?php echo e($errors->first('newGSM1_client')); ?></span> <br>
                                <?php endif; ?>

                            </div>
                            <div>
                                <label class="form-label"><strong class="det">GSM2 de la société</strong></label>
                                <input type="tel" class="form-control" name="newGSM2_client"
                                    placeholder="Entrer GSM2..." id="updateClientGSM2"
                                    value="<?php echo e(old('newGSM2_client', $client->GSM2_client)); ?>" pattern="[0-9]{10,15}" oninput="this.value = this.value.replace(/[^0-9]/g, '')"/>
                                <?php if($errors->has('newGSM2_client')): ?>
                                    <span class="text-danger">
                                        <?php echo e($errors->first('newGSM2_client')); ?></span> <br>
                                <?php endif; ?>

                            </div>
                            <div>
                                <label class="form-label"><strong class="det">Personne à contacter</strong></label>
                                <input id="updateClientName" type="text" class="form-control" name="newNom_client"
                                    placeholder="Entrer le client..."
                                    value="<?php echo e(old('newNom_client', $client->nom_client)); ?>" />
                                <?php if($errors->has('newNom_client')): ?>
                                    <span class="text-danger">
                                        <?php echo e($errors->first('newNom_client')); ?></span> <br>
                                <?php endif; ?>

                            </div>
                            <div>
                                <label class="form-label"><strong class="det">Numéro De Téléphone</strong></label>
                                <input id="updateClientContact" type="tel" class="form-control"
                                    name="newTele_client" placeholder="Entrer le contact..."
                                    value="<?php echo e(old('newTele_client', $client->tele_client)); ?>" pattern="[0-9]{10,15}" oninput="this.value = this.value.replace(/[^0-9]/g, '')"/>
                                <?php if($errors->has('newTele_client')): ?>
                                    <span class="text-danger">
                                        <?php echo e($errors->first('newTele_client')); ?></span> <br>
                                <?php endif; ?>

                            </div>
                            <div>
                                <label class="form-label"><strong class="det">Email</strong></label>
                                <input id="updateClientEmail" type="email" class="form-control" name="newEmail_client"
                                    placeholder="Entrer l'émail..."
                                    value="<?php echo e(old('newEmail_client', $client->email_client)); ?>" />
                                <?php if($errors->has('newEmail_client')): ?>
                                    <span class="text-danger">
                                        <?php echo e($errors->first('newEmail_client')); ?></span> <br>
                                <?php endif; ?>

                            </div>

                            <div>
                                <label class="form-label"><strong class="det">Lien de la société</strong></label>
                                <input type="url" class="form-control" name="newLien_client"
                                    placeholder="Entrer le lien..." id="updateClientLien"
                                    value="<?php echo e(old('newLien_client', $client->lien_client)); ?>"/>
                                <?php if($errors->has('newLien_client')): ?>
                                    <span class="text-danger">
                                        <?php echo e($errors->first('newLien_client')); ?></span> <br>
                                <?php endif; ?>

                            </div>

                            <div>
                                <label class="form-label"><strong class="det">Ville</strong></label>
                                <input id="updateClientVille" type="text" class="form-control" name="newVille_client"
                                    placeholder="Entrer la ville..."
                                    value="<?php echo e(old('newVille_client', $client->ville_client)); ?>" />
                                <?php if($errors->has('newVille_client')): ?>
                                    <span class="text-danger">
                                        <?php echo e($errors->first('newVille_client')); ?></span>
                                <?php endif; ?>

                            </div>

                            <div>
                                <label class="form-label"><strong class="det">Catégorie</strong></label>
                                <select id="updateClientCategory" class="form-select form-select-sm"
                                    aria-label=".form-select-sm example" name="newCategorie_id" style="height: 39px">
                                    <?php $__currentLoopData = $categories; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($cat->id); ?>">

                                            <?php echo e($cat->nom_categorie); ?>

                                        </option>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </select>
                                <?php if($errors->has('newCategorie_id')): ?>
                                    <span class="text-danger">
                                        <?php echo e($errors->first('newCategorie_id')); ?></span>
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="modal-footer">
                            <input type="submit" class="btn btn-primary" data-bs-dismiss="modal" value="Modifier">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    <?php endif; ?>
    <div>

        <div>
            <?php echo e($clients->links('vendor.pagination.bootstrap-4')); ?>


        </div>
    </div>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('script'); ?>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const select = document.getElementById('pagination-select');
            const form = document.getElementById('pagination-form');
            const perPageInput = document.getElementById('per-page-input');

            select.addEventListener('change', function() {
                perPageInput.value = this.value;
                form.submit();
            });
        });
    </script>
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            // Quand une catégorie est sélectionnée
            $('#categorie').change(function() {
                var categorieId = $(this).val();

                // Si une catégorie est sélectionnée
                if (categorieId) {
                    // Afficher le champ des sous-catégories et son label
                    $('#label-sous-categorie').show();
                    $('#sous-categorie').show();

                    // Faire une requête AJAX pour récupérer les sous-catégories
                    $.ajax({
                        url: '/sous-categories/' + categorieId, // L'URL de ta route
                        type: 'GET',
                        success: function(response) {
                            // Vider le select de sous-catégories
                            $('#sous-categorie').empty();
                            $('#sous-categorie').append(
                                '<option value="">Sélectionner une sous-catégorie</option>');

                            // Ajouter les sous-catégories au select
                            $.each(response, function(index, sousCategorie) {
                                $('#sous-categorie').append('<option value="' +
                                    sousCategorie.id + '">' + sousCategorie
                                    .nom_produit + '</option>');
                            });
                        },
                        error: function(xhr, status, error) {
                            // Si une erreur se produit
                            console.log('Erreur :', error);
                        }
                    });
                } else {
                    // Si aucune catégorie n'est sélectionnée, cacher le champ des sous-catégories et son label
                    $('#label-sous-categorie').hide();
                    $('#sous-categorie').hide();
                }
            });
        });
    </script>

    </script>

    <script>
        document.addEventListener("DOMContentLoaded", function() {
            const updateProspectModal = document.getElementById('update_client');
            updateProspectModal.addEventListener('show.bs.modal', event => {
                const button = event.relatedTarget;

                const clientId = button.getAttribute('data-id');
                const clientName = button.getAttribute('data-name');
                const clientEmail = button.getAttribute('data-email');
                const clientContact = button.getAttribute('data-tele');
                const clientVille = button.getAttribute('data-ville');
                const clientSociety = button.getAttribute('data-society');
                const clientGSM1 = button.getAttribute('data-GSM1');
                const clientGSM2 = button.getAttribute('data-GSM2');
                const clientLien = button.getAttribute('data-lien');
                const clientCategory = button.getAttribute('data-category')

                document.getElementById('updateClientId').value = clientId;
                document.getElementById('updateClientName').value = clientName;
                document.getElementById('updateClientEmail').value = clientEmail;
                document.getElementById('updateClientContact').value = clientContact;
                document.getElementById('updateClientVille').value = clientVille;
                document.getElementById('updateClientSociety').value = clientSociety;
                document.getElementById('updateClientGSM1').value = clientGSM1;
                document.getElementById('updateClientGSM2').value = clientGSM2;
                document.getElementById('updateClientLien').value = clientLien;
                document.getElementById('updateClientCategory').value = clientCategory;


            });
        });
    </script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const selects = document.querySelectorAll('.status-select');
            selects.forEach(select => {
                select.addEventListener('change', function() {
                    const form = this.closest('.client-form');
                    if (form) {
                        form.submit();
                    }
                });
            });
        });
    </script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const selects = document.querySelectorAll('.userSelect'); // Sélectionne tous les selects
            selects.forEach(select => {
                select.addEventListener('change', function() {
                    const form = this.closest(
                        '.user-form'); // Trouve le formulaire correspondant
                    if (form) {
                        form.submit();
                    }
                });
            });
        });
    </script>

    <script>
        function confirmDelete(clientId) {
            Swal.fire({
                title: 'Supprimer le client !',
                text: "êtes-vous sûr que vous voulez supprimer ce client ?",
                icon: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#d33',
                cancelButtonColor: '#3085d6',
                cancelButtonText: 'Annuler',
                confirmButtonText: 'Oui, Supprimer-le !'
            }).then((result) => {
                if (result.isConfirmed) {
                    document.getElementById('delete-form-' + clientId).submit();
                    Swal.fire(
                        "Supprimé !",
                        "Le client a été supprimé avec succès.",
                        "success"
                    );
                }
            });
        }
    </script>

    <script>
        document.querySelectorAll(`.detailButton`).forEach(button => {

            button.addEventListener('click', function() {
                const clientId = this.getAttribute('data-bs-target').split('-').pop();
                const clientName = this.getAttribute('data-name') || 'Non disponible'
                const clientEmail = this.getAttribute('data-email') || 'Non disponible'
                const clientContact = this.getAttribute('data-tele') || 'Non disponible'
                const clientVille = this.getAttribute('data-ville')
                const clientSociety = this.getAttribute('data-society-name')
                const clientGSM1 = this.getAttribute('data-GSM1')
                const clientGSM2 = this.getAttribute('data-GSM2')
                const clientLien = this.getAttribute('data-lien')
                const clientRemark = this.getAttribute('data-remark')
                const clientUser = this.getAttribute('data-user')

                document.querySelector(`#showNameDetail-${clientId}`).innerText = clientName
                document.querySelector(`#showEmailDetail-${clientId}`).innerText = clientEmail
                document.querySelector(`#showContactDetail-${clientId}`).innerText = clientContact
                document.querySelector(`#showVilleDetail-${clientId}`).innerText = clientVille
                document.querySelector(`#showSocietyDetail-${clientId}`).innerText = clientSociety
                document.querySelector(`#showGSM1Detail-${clientId}`).innerText = clientGSM1
                document.querySelector(`#showGSM2Detail-${clientId}`).innerText = clientGSM2
                document.querySelector(`#showLienDetail-${clientId}`).innerText = clientLien
                document.querySelector(`#showRemarkDetail-${clientId}`).innerText = clientRemark
                document.querySelector(`#showUserDetail-${clientId}`).innerText = clientUser
            })
        });

        document.addEventListener('DOMContentLoaded', function() {

            const categories = <?php echo json_encode($categories, 15, 512) ?>;
            // console.log(categories);

            document.querySelectorAll('.showCategoryclient').forEach(selectCategory => {
                const clientId = selectCategory.id.split('-').pop();
                const products = document.getElementById(`products-${clientId}`);


                if (products) {
                    selectCategory.addEventListener('change', function() {
                        const selectedCategoryId = this.value;
                        products.innerHTML = '';

                        if (selectedCategoryId) {
                            const selectedCategory = categories.find(category => {
                                return category.id == selectedCategoryId;
                            });

                            if (selectedCategory && selectedCategory.sous_categories.length > 0) {
                                selectedCategory.sous_categories.forEach(sous_category => {
                                    const option = document.createElement('option');
                                    option.value = sous_category.id;
                                    option.textContent = sous_category.nom_produit;
                                    option.selected = true;
                                    option.disabled = true;

                                    products.appendChild(option);
                                });
                            } else {
                                const emptyOption = document.createElement('option');
                                emptyOption.textContent = 'Aucun produit trouvé';
                                emptyOption.disabled = true;
                                products.appendChild(emptyOption);
                            }
                        }
                    });
                }
            });
        });
    </script>


    <script>
        function searchClients() {
            let input = document.getElementById('searchInput');
            let filter = input.value.toLowerCase();
            let table = document.getElementById('client-table');
            let tr = table.getElementsByTagName('tr');

            // Itérer à travers les lignes du tableau (commence à 1 pour ignorer l'entête)
            for (let i = 1; i < tr.length; i++) {
                let tds = tr[i].getElementsByTagName('td');
                let matchFound = false;

                // Vérifier chaque colonne pour la recherche
                for (let j = 0; j < tds.length; j++) {
                    let td = tds[j];
                    if (td) {
                        if (td.textContent.toLowerCase().includes(filter)) {
                            matchFound = true;
                            break;
                        }
                    }
                }

                // Afficher ou masquer la ligne en fonction de la correspondance
                if (matchFound) {
                    tr[i].style.display = '';
                } else {
                    tr[i].style.display = 'none';
                }
            }
        }
    </script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content2'); ?>
    <div class="modal fade" id="QueryClientsDetails" tabindex="-1" aria-labelledby="exampleModalLabel"
        aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="show-info-client show-society">
                        <label class="label-detail-client">Nom de la société</label>
                        <h6 class="info-client" id="showSocietyClient">
                        </h6>
                    </div>
                    <div class="show-info-client show-society">
                        <label class="label-detail-client">GSM1 de la société</label>
                        <h6 class="info-client" id="showGSM1Client">
                        </h6>
                    </div>
                    <div class="show-info-client show-society">
                        <label class="label-detail-client">GSM2 de la société</label>
                        <h6 class="info-client" id="showGSM2Client">
                        </h6>
                    </div>
                    <div class="show-info-client show-name">
                        <label class="label-detail-client">Personne à contacter</label>
                        <h6 class="info-client" id="showNameClient"></h6>
                    </div>
                    <div class="show-info-client show-contact">
                        <label class="label-detail-client">Numero De Telephone</label>
                        <h6 class="info-client" id="showContactClient"></h6>
                    </div>
                    <div class="show-info-client show-email">
                        <label class="label-detail-client">Email</label>
                        <h6 class="info-client" id="showEmailClient">
                        </h6>
                    </div>
                    <div class="show-info-client show-society">
                        <label class="label-detail-client">Lien de la société</label>
                        <h6 class="info-client" id="showLienClient">
                        </h6>
                    </div>


                    <div class="show-info-client show-ville">
                        <label class="label-detail-client">Ville</label>
                        <h6 class="info-client" id="showVilleClient">
                        </h6>
                    </div>
                    <div class="show-info-client show-category" style="margin-top:10px">
                        <label class="label-detail-client">Les catégories</label>
                        <select class="form-select form-select-sm info-client showCategoryClient"
                            aria-label=".form-select-sm example" style="width: 200px; height: 30px"
                            id="categoriesQuery-1">
                            <option value="" selected>Voir la(les) catégories</option>

                        </select>
                    </div>

                    <div class="show-info-client show-product" style="margin-bottom: 40px; margin-top:10px">
                        <label class="form-label label-detail-client">Sous-Catégorie</label>
                        <select class="form-select form-select-sm info-client showProductClient"
                            aria-label=".form-select-sm example" id="productsQuery-1" style="width: 200px; height: 30px">

                        </select>
                    </div>
                    <div class="show-info-client show-user">
                        <label class="label-detail-client">Contacté Par</label>
                        <h6 class="info-client" id="showUserClient">
                        </h6>
                    </div>
                    <div class="show-info-client show-remark">
                        <label class="label-detail-client">Remarque</label>
                        <p class="info-client" id="showRemarkClient" style="font-size: 12px">
                        </p>
                    </div>


                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('myApp.admin.adminLayout.adminPage', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/nettoyagecasabla/fournisseurs.materiel-levage-maroc.com/resources/views/myApp/admin/links/clients.blade.php ENDPATH**/ ?>