<?php $__env->startSection('title', 'Notificaciones'); ?>

<?php $__env->startSection('content'); ?>
<div class="bg-body-light">
    <div class="content content-full">
        <div class="d-flex flex-column flex-sm-row justify-content-sm-between align-items-sm-center py-2">
            <div class="flex-grow-1">
                <h1 class="h3 fw-bold mb-2">
                    <i class="fa fa-bell text-primary me-2"></i>Notificaciones
                </h1>
                <h2 class="fs-base lh-base fw-medium text-muted mb-0">
                    Listado y seguimiento de notificaciones emitidas.
                </h2>
            </div>
            <?php if(session('tipo_usuario') == 1): ?>
            <div class="mt-3 mt-sm-0 ms-sm-3">
                <a href="<?php echo e(route('notificaciones.create')); ?>" class="btn btn-primary">
                    <i class="fa fa-plus-circle me-1"></i> Nueva Notificación
                </a>
            </div>
            <?php endif; ?>
        </div>
    </div>
</div>

<div class="content">
    <?php if(session('success')): ?>
        <div class="alert alert-success d-flex align-items-center mb-4" role="alert">
            <div class="flex-shrink-0"><i class="fa fa-fw fa-check-circle"></i></div>
            <div class="flex-grow-1 ms-3">
                <p class="mb-0"><?php echo e(session('success')); ?></p>
            </div>
            <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </div>
    <?php endif; ?>

    <div class="block block-rounded block-bordered shadow-sm">
        <div class="block-content block-content-full">
            <form method="GET" action="<?php echo e(route('notificaciones.index')); ?>">
                <div class="row g-3">
                    <div class="col-md-3">
                        <label class="form-label fs-xs text-uppercase fw-bold text-muted">Urbanización</label>
                        <select name="urb" id="selUrb" class="form-select form-select-sm">
                            <option value="0">— Todas —</option>
                            <?php $__currentLoopData = $urbanizaciones; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $u): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($u->id); ?>" <?php echo e($urb == $u->id ? 'selected' : ''); ?>>
                                    <?php echo e($u->id); ?>. <?php echo e($u->nombre); ?>

                                </option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-md-2">
                        <label class="form-label fs-xs text-uppercase fw-bold text-muted">Distrito</label>
                        <select name="dis" id="selDis" class="form-select form-select-sm">
                            <option value="0">— Todos —</option>
                            <?php $__currentLoopData = $distritos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $d): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($d->id); ?>" <?php echo e($dis == $d->id ? 'selected' : ''); ?>><?php echo e($d->nombre); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-md-1">
                        <label class="form-label fs-xs text-uppercase fw-bold text-muted">Mzno</label>
                        <select name="manzano" id="selMan" class="form-select form-select-sm">
                            <option value="">— —</option>
                            <?php $__currentLoopData = $manzanos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $m): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($m); ?>" <?php echo e($manzano == $m ? 'selected' : ''); ?>><?php echo e($m); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                        </select>
                    </div>
                    <div class="col-md-3">
                        <label class="form-label fs-xs text-uppercase fw-bold text-muted">Cód. Cliente</label>
                        <input type="text" class="form-control form-control-sm" name="cliente"
                               value="<?php echo e($cliente); ?>" placeholder="Buscar por ID..." inputmode="numeric">
                    </div>
                    <div class="col-md-3 d-flex align-items-end gap-2">
                        <button type="submit" class="btn btn-alt-primary btn-sm flex-grow-1">
                            <i class="fa fa-search me-1"></i> Buscar
                        </button>
                        <a href="<?php echo e(route('notificaciones.index')); ?>" class="btn btn-alt-secondary btn-sm" title="Limpiar">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="block block-rounded block-bordered">
        <div class="block-content p-0">
            <div class="table-responsive">
                <table class="table table-vcenter table-hover table-striped mb-0">
                    <thead class="bg-body-dark">
                        <tr class="fs-xs text-uppercase">
                            <th class="text-center" style="width: 70px;">N°</th>
                            <th style="width: 120px;">Fecha</th>
                            <th>Cliente</th>
                            <th>Urb. / Distrito</th>
                            <th class="text-center">Ubicación</th>
                            <th class="text-center" style="width: 80px;">Notif.</th>
                            <th class="text-center" style="width: 120px;">Estado</th>
                        </tr>
                    </thead>
                    <tbody class="fs-sm">
                        <?php $__empty_1 = true; $__currentLoopData = $notificaciones; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $n): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr style="cursor:pointer" onclick="window.location='<?php echo e(route('notificaciones.show', $n->id)); ?>'">
                            <td class="text-center fw-bold text-primary"><?php echo e($n->id); ?></td>
                            <td><?php echo e(\App\Helpers\FechaHelper::bdToLocal($n->fecha)); ?></td>
                            <td>
                                <div class="fw-semibold"><?php echo e($n->nom_cliente ?? 'Desconocido'); ?></div>
                            </td>
                            <td>
                                <div class="fw-medium"><?php echo e($n->nom_urb); ?></div>
                                <div class="fs-xs text-muted"><?php echo e($n->nom_dis); ?></div>
                            </td>
                            <td class="text-center">
                                <span class="badge bg-body-dark text-dark border">M: <?php echo e($n->manzano); ?></span>
                                <span class="badge bg-body-dark text-dark border">L: <?php echo e($n->lote); ?></span>
                            </td>
                            <td class="text-center">
                                <span class="badge bg-secondary rounded-pill"><?php echo e($n->nronotificacion); ?>°</span>
                            </td>
                            <td class="text-center">
                                <?php if($n->estado == 0): ?>
                                    <span class="badge rounded-pill bg-warning-light text-warning">
                                        <i class="fa fa-clock me-1"></i> Pendiente
                                    </span>
                                <?php else: ?>
                                    <span class="badge rounded-pill bg-success-light text-success">
                                        <i class="fa fa-check me-1"></i> Atendida
                                    </span>
                                <?php endif; ?>
                            </td>
                        </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="7" class="text-center py-5">
                                <i class="fa fa-inbox fa-2x text-muted mb-2"></i>
                                <p class="text-muted mb-0">No se encontraron notificaciones.</p>
                            </td>
                        </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
        <?php if($notificaciones->hasPages()): ?>
        <div class="block-content block-content-full bg-body-light">
            <div class="d-flex justify-content-center">
                <?php echo e($notificaciones->links()); ?>

            </div>
        </div>
        <?php endif; ?>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
// Mantengo tu lógica AJAX intacta
document.getElementById('selUrb').addEventListener('change', async function () {
    const selDis = document.getElementById('selDis');
    const selMan = document.getElementById('selMan');
    selDis.innerHTML = '<option value="0">— Todos —</option>';
    selMan.innerHTML = '<option value="">— —</option>';
    if (this.value == 0) return;
    const data = await fetch(`<?php echo e(url('notificaciones/distritos')); ?>/${this.value}`).then(r => r.json());
    data.forEach(d => selDis.innerHTML += `<option value="${d.id}">${d.nombre}</option>`);
});
document.getElementById('selDis').addEventListener('change', async function () {
    const selMan = document.getElementById('selMan');
    selMan.innerHTML = '<option value="">— —</option>';
    if (this.value == 0) return;
    const data = await fetch(`<?php echo e(url('notificaciones/lotes')); ?>/${this.value}`).then(r => r.json());
    const manzanos = [...new Set(data.map(l => l.manzano))];
    manzanos.forEach(m => selMan.innerHTML += `<option value="${m}">${m}</option>`);
});
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /var/www/proyect-laravel/cosmos-app/resources/views/notificaciones/index.blade.php ENDPATH**/ ?>