<x-app-layout>
    <x-slot name="header">{{ __('Add Expense') }}</x-slot>

    <div class="card shadow-sm">
        <div class="card-body">
            <form action="{{ route('expenses.store') }}" method="POST">
                @csrf
                <div class="row g-3 mb-3">
                    <div class="col-md-4">
                        <label class="form-label fw-semibold">{{ __('Expense No') }}</label>
                        <input type="text" name="expense_no" class="form-control" value="{{ old('expense_no', $nextExpenseNo) }}">
                    </div>
                </div>
                <div class="row g-3">
                    <div class="col-md-4">
                        <label class="form-label" for="expense_date">{{ __('Date') }}</label>
                        <input id="expense_date" type="date" name="expense_date" class="form-control" value="{{ old('expense_date', now()->format('Y-m-d')) }}" required>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label" for="expense_category_id">{{ __('Category') }}</label>
                        <select id="expense_category_id" name="expense_category_id" class="form-select">
                            <option value="">{{ __('-- Select Category --') }}</option>
                            @foreach($expenseCategories as $cat)
                                <option value="{{ $cat->id }}" {{ old('expense_category_id') == $cat->id ? 'selected' : '' }}>{{ $cat->name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-md-4">
                        <label class="form-label" for="frequency">{{ __('Frequency') }}</label>
                        <select id="frequency" name="frequency" class="form-select" required>
                            <option value="one_time">{{ __('One Time') }}</option>
                            <option value="monthly">{{ __('Monthly') }}</option>
                            <option value="weekly">{{ __('Weekly') }}</option>
                            <option value="yearly">{{ __('Yearly') }}</option>
                        </select>
                    </div>
                </div>

                <div class="row g-3 mt-3">
                    <div class="col-md-4">
                        <label class="form-label" for="amount">{{ __('Amount') }}</label>
                        <input id="amount" type="number" step="0.01" name="amount" class="form-control" value="{{ old('amount') }}" required>
                    </div>
                </div>

                <div class="mb-3 mt-3">
                    <label class="form-label" for="notes">{{ __('Notes') }}</label>
                    <textarea id="notes" name="notes" class="form-control" rows="3">{{ old('notes') }}</textarea>
                </div>

                <button type="submit" class="btn btn-primary">{{ __('Save Expense') }}</button>
                <a href="{{ route('expenses.index') }}" class="btn btn-secondary">{{ __('Cancel') }}</a>
            </form>
        </div>
    </div>
</x-app-layout>
