<?php
/**
 * @var array $customers
 */
?>
<div class="page-title mb-4">
    <h5><i class="fas fa-plus-circle me-2 text-gold"></i>Create Gift Card</h5>
</div>

<div class="glass-card p-0">
    <div class="card-header">
        <div class="card-header-left">
            <i class="fas fa-gift card-icon"></i>
            <h6 class="card-title">Gift Card Information</h6>
        </div>
        <div>
            <span class="text-muted small"><span class="text-danger">*</span> Required fields</span>
        </div>
    </div>
    <div class="card-body">
        <form method="POST" action="<?= url('gift-cards/store') ?>">
            <?= csrf_field() ?>

            <div class="row g-3">
                <div class="col-md-6">
                    <div class="mb-3">
                        <label class="form-label">Customer <span class="text-danger">*</span></label>
                        <select name="customer_id" class="form-select bg-transparent <?= errorClass('customer_id') ?>" required>
                            <option value="">Select Customer</option>
                            <?php foreach ($customers as $c): ?>
                                <option value="<?= $c->id ?>" <?= old('customer_id') == $c->id ? 'selected' : '' ?>>
                                    <?= e($c->first_name . ' ' . $c->last_name) ?> (<?= e($c->phone) ?>)
                                </option>
                            <?php endforeach; ?>
                        </select>
                        <?= errorMsg('customer_id') ?>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="mb-3">
                        <label class="form-label">Initial Balance <span class="text-danger">*</span></label>
                        <div class="input-group">
                            <span class="input-group-text bg-transparent border-gold"><?= APP_CURRENCY_SYMBOL ?></span>
                            <input type="number" step="0.01" name="initial_balance"
                                   class="form-control bg-transparent <?= errorClass('initial_balance') ?>"
                                   value="<?= e(old('initial_balance', 0)) ?>" required min="0">
                        </div>
                        <?= errorMsg('initial_balance') ?>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="mb-3">
                        <label class="form-label">Expiry Date <span class="text-danger">*</span></label>
                        <input type="date" name="expiry_date" class="form-control bg-transparent <?= errorClass('expiry_date') ?>"
                               value="<?= e(old('expiry_date', date('Y-m-d', strtotime('+1 year')))) ?>" required>
                        <?= errorMsg('expiry_date') ?>
                    </div>
                </div>
            </div>

            <div class="mt-4 d-flex gap-2">
                <button type="submit" class="btn btn-gold">
                    <i class="fas fa-save me-1"></i>Create Gift Card
                </button>
                <a href="<?= url('gift-cards') ?>" class="btn btn-outline-secondary">
                    <i class="fas fa-times me-1"></i>Cancel
                </a>
            </div>
        </form>
    </div>
</div>
