<?php if (isset($component)) { $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54 = $attributes; } ?>
<?php $component = App\View\Components\AppLayout::resolve([] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('app-layout'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\App\View\Components\AppLayout::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes([]); ?>
     <?php $__env->slot('title', null, []); ?> 
        Directorio de Proveedores
     <?php $__env->endSlot(); ?>

    <!-- Filtros y Acciones -->
    <div class="card mb-4 border-0 shadow-sm rounded-4">
        <div class="card-body p-4">
            <div class="row g-3 align-items-center justify-content-between">
                <div class="col-md-8">
                    <form method="GET" action="<?php echo e(route('proveedores.index')); ?>" class="d-flex flex-wrap gap-2">
                        <input type="text" name="search" value="<?php echo e(request('search')); ?>" placeholder="Buscar proveedor por nombre..." class="form-control" style="max-width: 280px;">
                        
                        <select name="tipo" class="form-select tom-select" style="max-width: 200px;">
                            <option value="">Cualquier Tipo</option>
                            <option value="mercado" <?php echo e(request('tipo') === 'mercado' ? 'selected' : ''); ?>>Mercado Local</option>
                            <option value="distribuidor" <?php echo e(request('tipo') === 'distribuidor' ? 'selected' : ''); ?>>Distribuidor May.</option>
                            <option value="otro" <?php echo e(request('tipo') === 'otro' ? 'selected' : ''); ?>>Otro</option>
                        </select>

                        <button type="submit" class="btn btn-outline-secondary rounded-pill">
                            <i class="bi bi-funnel-fill"></i> Buscar
                        </button>
                        
                        <?php if(request()->hasAny(['search', 'tipo'])): ?>
                            <a href="<?php echo e(route('proveedores.index')); ?>" class="btn btn-light rounded-pill border">Limpiar</a>
                        <?php endif; ?>
                    </form>
                </div>
                <div class="col-md-4 text-md-end mt-3 mt-md-0">
                    <button type="button" class="btn btn-primary rounded-pill fw-bold shadow-sm" data-bs-toggle="modal" data-bs-target="#createProveedorModal">
                        <i class="bi bi-plus-circle-fill me-1"></i> Añadir Proveedor
                    </button>
                </div>
            </div>
        </div>
    </div>

    <!-- Directorio (Grid de Tarjetas o Tabla) -->
    <div class="card border-0 shadow-sm rounded-4">
        <div class="card-body p-0">
            <div class="table-responsive">
                <table class="table table-hover align-middle mb-0">
                    <thead class="bg-light">
                        <tr>
                            <th class="ps-4 py-3 text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Razón Social / Nombre</th>
                            <th class="py-3 text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Contacto</th>
                            <th class="py-3 text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Clasificación</th>
                            <th class="py-3 text-secondary text-uppercase text-center" style="font-size: 0.75rem; font-weight: 700;">Órdenes</th>
                            <th class="py-3 text-secondary text-uppercase text-center" style="font-size: 0.75rem; font-weight: 700;">Estado</th>
                            <th class="pe-4 py-3 text-end text-secondary text-uppercase" style="font-size: 0.75rem; font-weight: 700;">Acciones</th>
                        </tr>
                    </thead>
                    <tbody class="border-top-0">
                        <?php $__empty_1 = true; $__currentLoopData = $proveedores; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $prov): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td class="ps-4 py-3">
                                    <div class="d-flex align-items-center">
                                        <div class="rounded-circle bg-light d-flex align-items-center justify-content-center border me-3" style="width: 40px; height: 40px;">
                                            <i class="bi bi-truck text-secondary fs-5"></i>
                                        </div>
                                        <div>
                                            <div class="fw-bold text-dark"><?php echo e($prov->razon_social); ?></div>
                                            <div class="text-muted small">RUC: <?php echo e($prov->ruc ?: 'N/A'); ?></div>
                                        </div>
                                    </div>
                                </td>
                                <td class="py-3">
                                    <div class="text-dark fw-semibold small"><?php echo e($prov->contacto_nombre ?: 'Sin especificar'); ?></div>
                                    <div class="text-muted small"><i class="bi bi-telephone text-secondary me-1"></i><?php echo e($prov->telefono ?: '-'); ?></div>
                                </td>
                                <td class="py-3">
                                    <?php if($prov->tipo == 'mercado'): ?>
                                        <span class="badge bg-warning bg-opacity-10 text-warning rounded-pill px-2">Mercado Local</span>
                                    <?php elseif($prov->tipo == 'distribuidor'): ?>
                                        <span class="badge bg-info bg-opacity-10 text-info rounded-pill px-2">Distribuidor</span>
                                    <?php else: ?>
                                        <span class="badge bg-secondary bg-opacity-10 text-secondary rounded-pill px-2">Otro</span>
                                    <?php endif; ?>
                                </td>
                                <td class="py-3 text-center">
                                    <span class="badge bg-light text-dark border rounded-pill px-2"><?php echo e($prov->ordenes_compra_count ?? 0); ?></span>
                                </td>
                                <td class="py-3 text-center">
                                    <?php if($prov->activo): ?>
                                        <span class="badge bg-success bg-opacity-10 text-success rounded-pill px-2">Activo</span>
                                    <?php else: ?>
                                        <span class="badge bg-danger bg-opacity-10 text-danger rounded-pill px-2">Inactivo</span>
                                    <?php endif; ?>
                                </td>
                                <td class="pe-4 py-3 text-end">
                                    <a href="<?php echo e(route('proveedores.show', $prov)); ?>" class="btn btn-sm btn-light border rounded-circle" title="Ficha del Proveedor">
                                        <i class="bi bi-building text-primary"></i>
                                    </a>
                                    <button class="btn btn-sm btn-light border rounded-circle mx-1" data-bs-toggle="modal" data-bs-target="#editProveedorModal<?php echo e($prov->id); ?>" title="Editar datos">
                                        <i class="bi bi-pencil text-warning"></i>
                                    </button>
                                </td>
                            </tr>

                            <!-- Modal Editar Proveedor -->
                            <div class="modal fade" id="editProveedorModal<?php echo e($prov->id); ?>" tabindex="-1" aria-labelledby="editProvLabel<?php echo e($prov->id); ?>" aria-hidden="true">
                                <div class="modal-dialog modal-lg modal-dialog-centered">
                                    <div class="modal-content border-0 shadow-lg rounded-4">
                                        <div class="modal-header bg-light border-bottom-0 pb-0 rounded-top-4 pt-4 px-4">
                                            <h5 class="modal-title fw-bold" id="editProvLabel<?php echo e($prov->id); ?>"><i class="bi bi-building-add text-warning me-2"></i> Editar Proveedor: <?php echo e($prov->razon_social); ?></h5>
                                            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                        </div>
                                        <div class="modal-body p-4 text-start">
                                            <form method="POST" action="<?php echo e(route('proveedores.update', $prov)); ?>">
                                                <?php echo csrf_field(); ?>
                                                <?php echo method_field('PUT'); ?>
                                                <div class="row g-3">
                                                    <div class="col-md-7">
                                                        <label class="form-label fw-bold small text-muted">Razón Social o Nombre <span class="text-danger">*</span></label>
                                                        <input type="text" class="form-control" name="razon_social" value="<?php echo e($prov->razon_social); ?>" required>
                                                    </div>
                                                    <div class="col-md-5">
                                                        <label class="form-label fw-bold small text-muted">RUC/Documento</label>
                                                        <input type="text" class="form-control" name="ruc" value="<?php echo e($prov->ruc); ?>" maxlength="11">
                                                    </div>
                                                    
                                                    <div class="col-md-4">
                                                        <label class="form-label fw-bold small text-muted">Teléfono</label>
                                                        <input type="text" class="form-control" name="telefono" value="<?php echo e($prov->telefono); ?>">
                                                    </div>
                                                    <div class="col-md-4">
                                                        <label class="form-label fw-bold small text-muted">Persona de Contacto</label>
                                                        <input type="text" class="form-control" name="contacto_nombre" value="<?php echo e($prov->contacto_nombre); ?>">
                                                    </div>
                                                    <div class="col-md-4">
                                                        <label class="form-label fw-bold small text-muted">Correo Electrónico</label>
                                                        <input type="email" class="form-control" name="email" value="<?php echo e($prov->email); ?>">
                                                    </div>
                                                    
                                                    <div class="col-md-8">
                                                        <label class="form-label fw-bold small text-muted">Dirección Fiscal / Entrega</label>
                                                        <input type="text" class="form-control" name="direccion" value="<?php echo e($prov->direccion); ?>">
                                                    </div>
                                                    <div class="col-md-4">
                                                        <label class="form-label fw-bold small text-muted">Clasificación <span class="text-danger">*</span></label>
                                                        <select name="tipo" class="form-select tom-select" required>
                                                            <option value="mercado" <?php echo e($prov->tipo == 'mercado' ? 'selected' : ''); ?>>Mercado Local</option>
                                                            <option value="distribuidor" <?php echo e($prov->tipo == 'distribuidor' ? 'selected' : ''); ?>>Distribuidor Mayorista</option>
                                                            <option value="otro" <?php echo e($prov->tipo == 'otro' ? 'selected' : ''); ?>>Otro</option>
                                                        </select>
                                                    </div>
                                                    
                                                    <div class="col-12 mt-3">
                                                        <div class="form-check form-switch custom-switch bg-light p-3 rounded-3 border">
                                                            <input class="form-check-input ms-1" type="checkbox" role="switch" id="activo_prov_<?php echo e($prov->id); ?>" name="activo" value="1" <?php echo e($prov->activo ? 'checked' : ''); ?>>
                                                            <label class="form-check-label fw-bold small ms-2 mt-1 text-dark" for="activo_prov_<?php echo e($prov->id); ?>">
                                                                El proveedor está marcado como Activo (puede recibir órdenes de compra).
                                                            </label>
                                                        </div>
                                                    </div>
                                                    
                                                    <div class="col-12">
                                                        <label class="form-label fw-bold small text-muted">Notas Adicionales</label>
                                                        <textarea name="notas" class="form-control" rows="2"><?php echo e($prov->notas); ?></textarea>
                                                    </div>
                                                </div>

                                                <div class="mt-4 pt-3 border-top text-end">
                                                    <button type="button" class="btn btn-light rounded-pill border fw-bold px-4 me-2 shadow-sm" data-bs-dismiss="modal">Cancelar</button>
                                                    <button type="submit" class="btn btn-primary rounded-pill fw-bold shadow-sm px-4">
                                                        <i class="bi bi-save me-1"></i> Guardar Cambios
                                                    </button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <!-- Fin Modal Editar -->

                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr>
                                <td colspan="6" class="text-center py-5 text-muted">
                                    <i class="bi bi-building-dash fs-1 d-block mb-3 text-light"></i>
                                    No hay proveedores registrados aún o no coinciden con la búsqueda.
                                </td>
                            </tr>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
            
            <?php if($proveedores->hasPages()): ?>
                <div class="p-3 border-top">
                    <?php echo e($proveedores->links('pagination::bootstrap-5')); ?>

                </div>
            <?php endif; ?>
        </div>
    </div>

    <!-- Modal para Crear Nuevo Proveedor -->
    <div class="modal fade" id="createProveedorModal" tabindex="-1" aria-labelledby="createProvLabel" aria-hidden="true">
        <div class="modal-dialog modal-lg modal-dialog-centered">
            <div class="modal-content border-0 shadow-lg rounded-4">
                <div class="modal-header bg-light border-bottom-0 pb-0 rounded-top-4 pt-4 px-4">
                    <h5 class="modal-title fw-bold" id="createProvLabel"><i class="bi bi-building-add text-primary me-2"></i> Añadir Nuevo Proveedor</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body p-4">
                    <form method="POST" action="<?php echo e(route('proveedores.store')); ?>">
                        <?php echo csrf_field(); ?>
                        <div class="row g-3">
                            <div class="col-md-7">
                                <label class="form-label fw-bold small text-muted">Razón Social o Nombre <span class="text-danger">*</span></label>
                                <input type="text" class="form-control" name="razon_social" value="<?php echo e(old('razon_social')); ?>" required>
                            </div>
                            <div class="col-md-5">
                                <label class="form-label fw-bold small text-muted">RUC/Documento</label>
                                <input type="text" class="form-control" name="ruc" value="<?php echo e(old('ruc')); ?>" maxlength="11">
                            </div>
                            
                            <div class="col-md-4">
                                <label class="form-label fw-bold small text-muted">Teléfono</label>
                                <input type="text" class="form-control" name="telefono" value="<?php echo e(old('telefono')); ?>">
                            </div>
                            <div class="col-md-4">
                                <label class="form-label fw-bold small text-muted">Persona de Contacto</label>
                                <input type="text" class="form-control" name="contacto_nombre" value="<?php echo e(old('contacto_nombre')); ?>">
                            </div>
                            <div class="col-md-4">
                                <label class="form-label fw-bold small text-muted">Correo Electrónico</label>
                                <input type="email" class="form-control" name="email" value="<?php echo e(old('email')); ?>">
                            </div>
                            
                            <div class="col-md-8">
                                <label class="form-label fw-bold small text-muted">Dirección Fiscal / Entrega</label>
                                <input type="text" class="form-control" name="direccion" value="<?php echo e(old('direccion')); ?>">
                            </div>
                            <div class="col-md-4">
                                <label class="form-label fw-bold small text-muted">Clasificación <span class="text-danger">*</span></label>
                                <select name="tipo" class="form-select tom-select" required>
                                    <option value="mercado" <?php echo e(old('tipo') == 'mercado' ? 'selected' : ''); ?>>Mercado Local</option>
                                    <option value="distribuidor" <?php echo e(old('tipo') == 'distribuidor' ? 'selected' : ''); ?>>Distribuidor Mayorista</option>
                                    <option value="otro" <?php echo e(old('tipo') == 'otro' ? 'selected' : ''); ?>>Otro</option>
                                </select>
                            </div>
                            
                            <div class="col-12">
                                <label class="form-label fw-bold small text-muted">Notas Adicionales</label>
                                <textarea name="notas" class="form-control" rows="2"><?php echo e(old('notas')); ?></textarea>
                            </div>
                        </div>

                        <div class="mt-4 pt-3 border-top text-end">
                            <button type="button" class="btn btn-light rounded-pill border fw-bold px-4 me-2 shadow-sm" data-bs-dismiss="modal">Cancelar</button>
                            <button type="submit" class="btn btn-primary rounded-pill fw-bold shadow-sm px-4">
                                <i class="bi bi-check-lg me-1"></i> Registrar Proveedor
                            </button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
 <?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $attributes = $__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__attributesOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54)): ?>
<?php $component = $__componentOriginal9ac128a9029c0e4701924bd2d73d7f54; ?>
<?php unset($__componentOriginal9ac128a9029c0e4701924bd2d73d7f54); ?>
<?php endif; ?>
<?php /**PATH C:\laragon\www\gastrog\resources\views/proveedores/index.blade.php ENDPATH**/ ?>