<?= $this->Form->create(null, ['type' => 'get', 'class' => 'mb-3 me-3']) ?>
<div class="input-group mt-2">
    <?= $this->Form->control('search', [
        'label' => false,
        'placeholder' => 'Buscar por: Razón Social / Nombre',
        'value' => $searchTerm ?? '',
        'class' => 'form-control',
    ]) ?>
    <button class="btn btn-info mx-2" type="submit">Buscar</button>
</div>
<div class="input-group mt-2">
    <?= $this->Form->control('searchDoc', [
        'label' => false,
        'placeholder' => 'Buscar por: RUC / DNI',
        'value' => $searchDoc ?? '',
        'class' => 'form-control',
    ]) ?>
    <button class="btn btn-info mx-2" type="submit">Buscar</button>
</div>
<div class="input-group mt-2">
    <?= $this->Form->control('searchTelefono', [
        'label' => false,
        'placeholder' => 'Buscar por: Teléfono',
        'value' => $searchTelefono ?? '',
        'class' => 'form-control',
    ]) ?>
    <button class="btn btn-info mx-2" type="submit">Buscar</button>
</div>
<?= $this->Form->end() ?>

<div class="clientesFacturacion index content">
    <?= $this->Html->link(__('Añadir Cliente'), ['action' => 'add'], ['class' => 'button float-right btn btn-info']) ?>
    <div class="contenedor principal">
        <div class="table-responsive">
            <table class="table table-striped mt-3">
                <thead class="bg-info text-white">
                    <tr>
                        <th><?= $this->Paginator->sort('id', 'ID') ?></th>
                        <th><?= $this->Paginator->sort('nombre_razon_social', 'Cliente') ?></th>
                        <th><?= $this->Paginator->sort('tipo_doc', 'Tipo Doc.') ?></th>
                        <th><?= $this->Paginator->sort('numero_doc', 'N° Doc.') ?></th>
                        <th><?= $this->Paginator->sort('telefono', 'Teléfono') ?></th>
                        <th><?= $this->Paginator->sort('created', 'Fecha de Creación') ?></th>
                        <th class="actions text-dark"><?= __('Acciones') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($clientesFacturacion as $cliente): ?>
                    <tr>
                        <td><?= $this->Number->format($cliente->id) ?></td>
                        <td><?= h($cliente->nombre_razon_social) ?></td>
                        <td><?= h($cliente->tipo_doc === '6' ? 'RUC' : 'DNI') ?></td>
                        <td><?= h($cliente->numero_doc) ?></td>
                        <td><?= h($cliente->telefono) ?></td>
                        <td><?= h($cliente->created->format('d/m/Y')) ?></td>
                        <td class="actions text-center">
                            <?= $this->Html->link(
                                '<i class="fas fa-eye"></i>',
                                ['action' => 'view', $cliente->id],
                                ['escape' => false, 'title' => 'Ver', 'class' => 'btn btn-info btn-sm']
                            ) ?>
                            <?= $this->Html->link(
                                '<i class="fas fa-edit"></i>',
                                ['action' => 'edit', $cliente->id],
                                ['escape' => false, 'title' => 'Editar', 'class' => 'btn btn-warning btn-sm']
                            ) ?>
                            <?php if ($this->Permisos->tiene('ClientesFacturacion', 'delete')): ?>
                            <?= $this->Form->postLink(
                                '<i class="fas fa-trash"></i>',
                                ['action' => 'delete', $cliente->id],
                                ['escape' => false, 'title' => 'Eliminar', 'class' => 'btn btn-danger btn-sm', 'confirm' => __('¿Estás seguro de que quieres eliminar al cliente {0}?', $cliente->nombre_razon_social)]
                            ) ?>
                            <?php endif; ?>
                        </td>
                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>
    <div class="paginator">
        <ul class="pagination">
            <?= $this->Paginator->first('<< ' . __('Primero')) ?>
            <?= $this->Paginator->prev('< ' . __('Anterior')) ?>
            <?= $this->Paginator->numbers() ?>
            <?= $this->Paginator->next(__('Siguiente') . ' >') ?>
            <?= $this->Paginator->last(__('Último') . ' >>') ?>
        </ul>
        <p><?= $this->Paginator->counter(__('Página {{page}} de {{pages}}, mostrando {{current}} registro(s) de un total de {{count}}')) ?></p>
    </div>
</div>
