<?= $this->extend('admin/layout/main') ?>
<?= $this->section('content') ?>
<div class="d-flex justify-content-between align-items-center mb-3">
    <h3><?= lang('App.services') ?></h3>
    <a href="/admin/services/create" class="btn btn-dark btn-sm"><?= lang('App.add_new') ?></a>
</div>
<div class="card p-3">
<table class="table">
    <thead><tr><th><?= lang('App.client') ?></th><th><?= lang('App.name') ?></th><th><?= lang('App.renewal_date') ?></th><th><?= lang('App.amount') ?></th><th><?= lang('App.status') ?></th><th><?= lang('App.actions') ?></th></tr></thead>
    <tbody>
    <?php foreach ($services as $s): ?>
        <?php
            $days = (strtotime($s['renewal_date']) - time()) / 86400;
            $rowClass = $days < 0 ? 'table-danger' : ($days <= 7 ? 'table-warning' : '');
        ?>
        <tr class="<?= $rowClass ?>">
            <td><?= esc($s['client_name']) ?></td>
            <td><?= esc($s['name']) ?></td>
            <td><?= esc($s['renewal_date']) ?></td>
            <td><?= number_format($s['price'], 2) ?> <?= esc($s['currency']) ?></td>
            <td><?= lang('App.' . $s['status']) ?></td>
            <td>
                <a href="/admin/services/<?= $s['id'] ?>/edit" class="btn btn-sm btn-outline-primary"><?= lang('App.edit') ?></a>
                <form method="post" action="/admin/services/<?= $s['id'] ?>/delete" class="d-inline" onsubmit="return confirm('?')">
                    <?= csrf_field() ?><button class="btn btn-sm btn-outline-danger"><?= lang('App.delete') ?></button>
                </form>
            </td>
        </tr>
    <?php endforeach; ?>
    </tbody>
</table>
<?= $pager->links() ?>
</div>
<?= $this->endSection() ?>
