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

<?php $__env->startSection('content'); ?>
<div class="sinagem-main">
    <div class="s-card">
        <div class="s-card-header">
            <h4 class="s-card-title">
                <i class="fas fa-scissors"></i>
                Escamadores
            </h4>
            <a href="<?php echo e(route('mercado.escamadores.create')); ?>" class="btn btn-primary btn-sm">
                <i class="fas fa-plus-circle"></i>
                Novo Escamador
            </a>
        </div>

        <div class="s-card-body">
            <?php if(session('success')): ?>
                <div class="sinagem-alert sinagem-alert-success">
                    <i class="fas fa-check-circle"></i>
                    <span><?php echo e(session('success')); ?></span>
                    <button type="button" class="flash-close">&times;</button>
                </div>
            <?php endif; ?>

            <?php if(session('error')): ?>
                <div class="sinagem-alert sinagem-alert-danger">
                    <i class="fas fa-exclamation-circle"></i>
                    <span><?php echo e(session('error')); ?></span>
                    <button type="button" class="flash-close">&times;</button>
                </div>
            <?php endif; ?>

            <!-- Filtros -->
            <form method="GET" class="row g-3 mb-4 align-items-end">
                <div class="col-md-3">
                    <label for="market_id" class="form-label">Mercado</label>
                    <select name="market_id" id="market_id" class="form-control">
                        <option value="">Todos os Mercados</option>
                        <?php $__currentLoopData = $markets ?? []; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $market): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($market->id); ?>" <?php echo e(request('market_id') == $market->id ? 'selected' : ''); ?>>
                                <?php echo e($market->name); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-md-3">
                    <label for="status" class="form-label">Status</label>
                    <select name="status" id="status" class="form-control">
                        <option value="">Todos</option>
                        <option value="active" <?php echo e(request('status') == 'active' ? 'selected' : ''); ?>>Ativo</option>
                        <option value="pending" <?php echo e(request('status') == 'pending' ? 'selected' : ''); ?>>Pendente</option>
                        <option value="inactive" <?php echo e(request('status') == 'inactive' ? 'selected' : ''); ?>>Inativo</option>
                        <option value="suspended" <?php echo e(request('status') == 'suspended' ? 'selected' : ''); ?>>Suspenso</option>
                    </select>
                </div>
                <div class="col-md-4">
                    <label for="search" class="form-label">Pesquisar</label>
                    <input type="text" name="search" id="search" class="form-control" placeholder="Nome, badge ou telefone..." value="<?php echo e(request('search')); ?>">
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary w-100">
                        <i class="fas fa-search"></i> Filtrar
                    </button>
                </div>
            </form>

            <!-- Tabela DataTable -->
            <div class="sinagem-datatable-wrapper">
                <div class="table-responsive">
                    <table id="escamadores-table" class="s-table">
                        <thead>
                            <tr>
                                <th>Nome</th>
                                <th>Badge</th>
                                <th>Email</th>
                                <th>Telefone</th>
                                <th>Status</th>
                                <th>Mercados</th>
                                <th class="text-center">Ações</th>
                            </tr>
                        </thead>
                        <tbody>
                            <!-- DataTables preenche via AJAX -->
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('styles'); ?>
<style>
    .sinagem-alert {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
        border-radius: var(--radius-md, 8px);
        margin-bottom: 1rem;
        border-left: 3px solid;
    }

    .sinagem-alert-success {
        background: #d1fae5;
        border-left-color: #10b981;
        color: #065f46;
    }

    .sinagem-alert-danger {
        background: #fee2e2;
        border-left-color: #ef4444;
        color: #991b1b;
    }

    .flash-close {
        margin-left: auto;
        background: none;
        border: none;
        font-size: 1.1rem;
        cursor: pointer;
        color: inherit;
        opacity: 0.6;
    }

    .flash-close:hover {
        opacity: 1;
    }
</style>
<?php $__env->stopPush(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
$(document).ready(function() {
    const table = $('#escamadores-table').DataTable({
        processing: true,
        serverSide: true,
        ajax: {
            url: '<?php echo e(route("mercado.escamadores.table-data")); ?>',
            type: 'GET',
            data: function(d) {
                d.market_id = $('#market_id').val();
                d.status = $('#status').val();
                d.search = $('#search').val();
            }
        },
        columns: [
            { data: 'name', name: 'name' },
            { data: 'badge_number', name: 'badge_number' },
            { data: 'email', name: 'email' },
            { data: 'phone', name: 'phone' },
            { data: 'status', name: 'status' },
            { data: 'markets', name: 'markets', orderable: false, searchable: false },
            { data: 'actions', name: 'actions', orderable: false, searchable: false, className: 'text-center' }
        ],
        pageLength: 15,
        language: {
            processing: '<i class="fas fa-spinner fa-spin"></i> Processando...',
            search: '<i class="fas fa-search"></i> Pesquisar:',
            lengthMenu: 'Mostrar _MENU_ registros por página',
            info: 'Mostrando _START_ a _END_ de _TOTAL_ registros',
            infoEmpty: 'Mostrando 0 a 0 de 0 registros',
            infoFiltered: '(filtrado de _MAX_ registros no total)',
            loadingRecords: '<i class="fas fa-spinner fa-spin"></i> Carregando...',
            zeroRecords: '<i class="fas fa-database"></i> Nenhum registro encontrado',
            emptyTable: '<i class="fas fa-table"></i> Nenhum dado disponível na tabela',
            paginate: {
                first: '<i class="fas fa-angle-double-left"></i>',
                previous: '<i class="fas fa-angle-left"></i>',
                next: '<i class="fas fa-angle-right"></i>',
                last: '<i class="fas fa-angle-double-right"></i>'
            }
        },
        responsive: true,
        order: [[0, 'asc']],
        drawCallback: function() {
            initTooltips();
        }
    });

    $('#market_id, #status, #search').on('change keyup', function() {
        table.ajax.reload();
    });

    function initTooltips() {
        if (typeof bootstrap !== 'undefined') {
            $('[title]').each(function() {
                const tooltip = bootstrap.Tooltip.getInstance(this);
                if (tooltip) tooltip.dispose();
                new bootstrap.Tooltip(this, { placement: 'top', trigger: 'hover' });
            });
        }
    }

    $('.flash-close').on('click', function() {
        $(this).closest('.sinagem-alert').fadeOut(300, function() {
            $(this).remove();
        });
    });
});
</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/html/resources/views/admin/mercado/escamadores/index.blade.php ENDPATH**/ ?>