<?php
/**
 * @var \App\View\AppView $this
 * @var iterable<\App\Model\Entity\Servicio> $servicios
 * @var string $searchTerm
 */
?>

<div class="servicios index content">
    <div class="row mb-3">
        <div class="col-md-6">
            <?= $this->Html->link(__('Añadir Servicio'), ['action' => 'add'], ['class' => 'button btn btn-info openModal']) ?>
        </div>
        <div class="col-md-6">
            <?= $this->Form->create(null, ['type' => 'get', 'valueSets' => false]) ?>
            <div class="input-group">
                <?= $this->Form->text('search', [
                    'placeholder' => 'Buscar por nombre de servicio...',
                    'class' => 'form-control',
                    'value' => $searchTerm ?? ''
                ]) ?>
                <div class="input-group-append">
                    <?= $this->Form->button('Buscar', ['type' => 'submit', 'class' => 'btn btn-primary']) ?>
                    <?= $this->Html->link('Limpiar', ['action' => 'index'], ['class' => 'btn btn-secondary ml-2']) ?>
                </div>
            </div>
            <?= $this->Form->end() ?>
        </div>
    </div>

    <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', 'N° de Servicio') ?></th>
                        <th><?= $this->Paginator->sort('nombre', 'Nombre') ?></th>
                        <th><?= $this->Paginator->sort('costo', 'Costo') ?></th>
                        <th><?= $this->Paginator->sort('created', 'Creado') ?></th>
                        <th><?= $this->Paginator->sort('modified', 'Modificado') ?></th>
                        <th class="actions text-dark"><?= __('Acciones') ?></th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($servicios as $servicio): ?>
                    <tr>
                        <td><?= $this->Number->format($servicio->id) ?></td>
                        <td><?= h($servicio->nombre) ?></td>
                        <td><?= h($servicio->costo) ?></td>
                        <td><?= h($servicio->created) ?></td>
                        <td><?= h($servicio->modified) ?></td>
                        <td class="actions text-center">
                            <!-- Íconos personalizados para acciones -->
                            <?= $this->Html->link(
                                '<i class="fas fa-eye"></i>',
                                ['action' => 'view', $servicio->id],
                                ['escape' => false, 'title' => 'Ver', 'class' => 'btn btn-info btn-sm openModal']
                            ) ?>
                            <?= $this->Html->link(
                                '<i class="fas fa-edit"></i>',
                                ['action' => 'edit', $servicio->id],
                                ['escape' => false, 'title' => 'Editar', 'class' => 'btn btn-warning btn-sm openModal']
                            ) ?>
                        </td>


                    </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>

    <!-- Paginación -->
    <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>
