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

<div class="glass-card p-0">
    <div class="card-header">
        <div class="card-header-left">
            <i class="fas fa-chart-line card-icon"></i>
            <h6 class="card-title">Income 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('income/store') ?>">
            <?= csrf_field() ?>

            <div class="row g-3">
                <div class="col-md-6">
                    <div class="mb-3">
                        <label class="form-label">Category <span class="text-danger">*</span></label>
                        <select name="category_id" class="form-select bg-transparent <?= errorClass('category_id') ?>">
                            <option value="">Select Category</option>
                            <?php foreach ($categories as $cat): ?>
                                <option value="<?= $cat->id ?>" <?= old('category_id') == $cat->id ? 'selected' : '' ?>>
                                    <?= e($cat->name) ?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                        <?= errorMsg('category_id') ?>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="mb-3">
                        <label class="form-label">Amount <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="amount"
                                   class="form-control bg-transparent <?= errorClass('amount') ?>"
                                   value="<?= e(old('amount')) ?>" required min="0">
                        </div>
                        <?= errorMsg('amount') ?>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="mb-3">
                        <label class="form-label">Date <span class="text-danger">*</span></label>
                        <input type="date" name="date" class="form-control bg-transparent <?= errorClass('date') ?>"
                               value="<?= e(old('date', date('Y-m-d'))) ?>" required>
                        <?= errorMsg('date') ?>
                    </div>
                </div>
            </div>

            <div class="row g-3">
                <div class="col-md-12">
                    <div class="mb-3">
                        <label class="form-label">Description <span class="text-danger">*</span></label>
                        <textarea name="description" class="form-control bg-transparent <?= errorClass('description') ?>"
                                  rows="3" maxlength="500"><?= e(old('description')) ?></textarea>
                        <?= errorMsg('description') ?>
                    </div>
                </div>
            </div>

            <div class="row g-3">
                <div class="col-md-6">
                    <div class="mb-3">
                        <label class="form-label">Payment Method <span class="text-danger">*</span></label>
                        <select name="payment_method" class="form-select bg-transparent <?= errorClass('payment_method') ?>">
                            <option value="cash" <?= old('payment_method') === 'cash' ? 'selected' : '' ?>>Cash</option>
                            <option value="card" <?= old('payment_method') === 'card' ? 'selected' : '' ?>>Card</option>
                            <option value="bank_transfer" <?= old('payment_method') === 'bank_transfer' ? 'selected' : '' ?>>Bank Transfer</option>
                            <option value="gift_card" <?= old('payment_method') === 'gift_card' ? 'selected' : '' ?>>Gift Card</option>
                            <option value="advance" <?= old('payment_method') === 'advance' ? 'selected' : '' ?>>Advance Payment</option>
                        </select>
                        <?= errorMsg('payment_method') ?>
                    </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>Save Income
                </button>
                <a href="<?= url('income') ?>" class="btn btn-outline-secondary">
                    <i class="fas fa-times me-1"></i>Cancel
                </a>
            </div>
        </form>
    </div>
</div>
