@php($r = $recurringExpense ?? null)

<div class="row g-3">
    <div class="col-md-4">
        <label class="form-label">{{ __('admin/expenses.field_amount') }} <span class="text-danger">*</span></label>
        <input type="number" step="0.01" min="0" name="amount" class="form-control"
               value="{{ old('amount', $r->amount ?? '') }}" required>
    </div>

    <div class="col-md-4">
        <label class="form-label">{{ __('admin/expenses.field_currency') }} <span class="text-danger">*</span></label>
        <select name="currency_id" class="form-select" required>
            @foreach($currencies as $currency)
                <option value="{{ $currency->id }}" @selected(old('currency_id', $r->currency_id ?? '') == $currency->id)>{{ $currency->code }} — {{ $currency->name }}</option>
            @endforeach
        </select>
    </div>

    <div class="col-md-4">
        <label class="form-label">{{ __('admin/expenses.recurring_field_frequency') }} <span class="text-danger">*</span></label>
        <select name="frequency" class="form-select" required>
            @foreach($frequencies as $freq)
                <option value="{{ $freq }}" @selected(old('frequency', $r->frequency ?? 'monthly') === $freq)>{{ __('admin/expenses.recurring_freq_'.$freq) }}</option>
            @endforeach
        </select>
    </div>

    <div class="col-md-6">
        <label class="form-label">{{ __('admin/expenses.recurring_field_start_date') }} <span class="text-danger">*</span></label>
        <input type="text" name="start_date" class="form-control recurring-datepicker"
               value="{{ old('start_date', isset($r) ? $r->start_date?->format('Y-m-d') : '') }}" required>
    </div>

    <div class="col-md-6">
        <label class="form-label">{{ __('admin/expenses.recurring_field_end_date') }}</label>
        <input type="text" name="end_date" class="form-control recurring-datepicker"
               value="{{ old('end_date', isset($r) ? $r->end_date?->format('Y-m-d') : '') }}">
    </div>

    <div class="col-md-6">
        <label class="form-label">{{ __('admin/expenses.field_category') }}</label>
        <select name="category_id" class="form-select">
            <option value="">{{ __('admin/expenses.field_none') }}</option>
            @foreach($categories as $category)
                <option value="{{ $category->id }}" @selected(old('category_id', $r->category_id ?? '') == $category->id)>{{ $category->name }}</option>
            @endforeach
        </select>
    </div>

    <div class="col-md-6">
        <label class="form-label">{{ __('admin/expenses.field_vendor') }}</label>
        <select name="vendor_id" class="form-select">
            <option value="">{{ __('admin/expenses.field_none') }}</option>
            @foreach($vendors as $vendor)
                <option value="{{ $vendor->id }}" @selected(old('vendor_id', $r->vendor_id ?? '') == $vendor->id)>{{ $vendor->name }}</option>
            @endforeach
        </select>
    </div>

    <div class="col-12">
        <label class="form-label">{{ __('admin/expenses.field_description') }} <span class="text-danger">*</span></label>
        <input type="text" name="description" maxlength="255" class="form-control"
               value="{{ old('description', $r->description ?? '') }}" required>
    </div>

    <div class="col-12">
        <label class="form-label">{{ __('admin/expenses.field_note') }}</label>
        <textarea name="note" rows="3" maxlength="2000" class="form-control">{{ old('note', $r->note ?? '') }}</textarea>
    </div>

    @include('admin.expenses.partials.linkable', ['linkModel' => $r])

    <div class="col-12">
        <div class="form-check form-switch">
            <input type="checkbox" name="is_active" class="form-check-input" id="recurringActive" value="1"
                   @checked(old('is_active', $r->is_active ?? true))>
            <label class="form-check-label" for="recurringActive">{{ __('admin/expenses.recurring_field_active') }}</label>
        </div>
    </div>
</div>
