<?= $this->extend('admin/layout/main') ?>
<?= $this->section('content') ?>
<div class="d-flex justify-content-between align-items-center mb-3">
    <h3><?= lang('App.quotes') ?></h3>
    <a href="/admin/quotes/create" class="btn btn-dark btn-sm"><?= lang('App.add_new') ?></a>
</div>
<div class="card p-3">
<table class="table">
    <thead><tr><th>رقم العرض</th><th><?= lang('App.client') ?></th><th><?= lang('App.amount') ?></th><th>ساري حتى</th><th><?= lang('App.status') ?></th><th><?= lang('App.actions') ?></th></tr></thead>
    <tbody>
    <?php foreach ($quotes as $q): ?>
        <tr>
            <td><?= esc($q['quote_number']) ?></td>
            <td><?= esc($q['client_name']) ?></td>
            <td><?= number_format($q['amount'], 2) ?> <?= esc($q['currency']) ?></td>
            <td><?= esc($q['valid_until']) ?></td>
            <td><span class="badge bg-secondary"><?= lang('App.quote_' . $q['status']) ?></span></td>
            <td>
                <a href="/admin/quotes/<?= $q['id'] ?>/view" class="btn btn-sm btn-outline-secondary">عرض</a>
                <a href="/admin/quotes/<?= $q['id'] ?>/edit" class="btn btn-sm btn-outline-primary"><?= lang('App.edit') ?></a>
                <?php if ($q['status'] !== 'converted'): ?>
                    <form method="post" action="/admin/quotes/<?= $q['id'] ?>/convert" class="d-inline" onsubmit="return confirm('تحويل هذا العرض لفاتورة نهائية؟')">
                        <?= csrf_field() ?><button class="btn btn-sm btn-success">تحويل لفاتورة</button>
                    </form>
                <?php else: ?>
                    <a href="/admin/invoices/<?= $q['converted_invoice_id'] ?>/edit" class="btn btn-sm btn-outline-success">عرض الفاتورة</a>
                <?php endif; ?>
                <form method="post" action="/admin/quotes/<?= $q['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; ?>
    <?php if (empty($quotes)): ?><tr><td colspan="6" class="text-center text-muted"><?= lang('App.no_data') ?></td></tr><?php endif; ?>
    </tbody>
</table>
<?= $pager->links() ?>
</div>
<?= $this->endSection() ?>
