<x-app-layout>
    <x-slot name="header">{{ __('New Bank Withdrawal') }}</x-slot>

    <div class="card shadow-sm" style="max-width: 640px;">
        <div class="card-body">
            <form action="{{ route('bank-withdrawals.store') }}" method="POST">
                @csrf
                @php
                    $selectedCurrencyId = old('currency_id', optional($currencies->first())->id);
                @endphp

                <div class="row g-3">
                    <div class="col-md-6">
                        <label class="form-label" for="withdrawal_date">{{ __('Withdrawal Date') }} <span class="text-danger">*</span></label>
                        <input id="withdrawal_date" type="date" name="withdrawal_date" class="form-control @error('withdrawal_date') is-invalid @enderror"
                               value="{{ old('withdrawal_date', now()->format('Y-m-d')) }}" required>
                        @error('withdrawal_date')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                    <div class="col-md-6">
                        <label class="form-label" for="amount">{{ __('Amount') }} <span class="text-danger">*</span></label>
                        <input id="amount" type="number" step="0.01" name="amount" class="form-control @error('amount') is-invalid @enderror"
                               value="{{ old('amount') }}" placeholder="0.00" required>
                        @error('amount')<div class="invalid-feedback">{{ $message }}</div>@enderror
                    </div>
                </div>

                <div class="row g-3 mt-1">
                    <div class="col-md-6">
                        <label class="form-label" for="currency_id">{{ __('Currency') }}</label>
                        <select id="currency_id" name="currency_id" class="form-select">
                            @foreach($currencies as $currency)
                                <option value="{{ $currency->id }}" {{ (string) $selectedCurrencyId === (string) $currency->id ? 'selected' : '' }}>
                                    {{ $currency->code }} - {{ $currency->name }}
                                </option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label" for="bank_account">{{ __('Bank Account') }}</label>
                        <input id="bank_account" type="text" name="bank_account" class="form-control"
                               value="{{ old('bank_account') }}" placeholder="{{ __('e.g. Card Sales Account') }}">
                    </div>
                </div>

                <div class="mt-3">
                    <label class="form-label" for="reference">{{ __('Reference') }}</label>
                    <input id="reference" type="text" name="reference" class="form-control"
                           value="{{ old('reference') }}" placeholder="{{ __('Transaction / cheque no.') }}">
                </div>

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

                <div class="mt-4">
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-save me-1"></i>{{ __('Save Withdrawal') }}
                    </button>
                    <a href="{{ route('bank-withdrawals.index') }}" class="btn btn-secondary ms-2">{{ __('Cancel') }}</a>
                </div>
            </form>
        </div>
    </div>
</x-app-layout>
