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

    <div class="card shadow-sm">
        <div class="card-body">
            <form action="{{ route('employee-payments.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="employee_id">{{ __('Employee') }}</label>
                        <select id="employee_id" name="employee_id" class="form-select" required>
                            @foreach($employees as $employee)
                                <option value="{{ $employee->id }}">{{ $employee->name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="col-md-6">
                        <label class="form-label" for="payment_date">{{ __('Payment Date') }}</label>
                        <input id="payment_date" type="date" name="payment_date" class="form-control" value="{{ old('payment_date', now()->format('Y-m-d')) }}" required>
                    </div>
                </div>

                <div class="row g-3 mt-3">
                    <div class="col-md-4">
                        <label class="form-label" for="payment_type">{{ __('Payment Type') }} <span class="text-danger">*</span></label>
                        <select id="payment_type" name="payment_type" class="form-select" required>
                            <option value="">{{ __('Select Type') }}</option>
                            <option value="salary" {{ old('payment_type') === 'salary' ? 'selected' : '' }}>{{ __('Salary') }}</option>
                            <option value="advance" {{ old('payment_type') === 'advance' ? 'selected' : '' }}>{{ __('Advance') }}</option>
                            <option value="adjustment" {{ old('payment_type') === 'adjustment' ? 'selected' : '' }}>{{ __('Adjustment') }}</option>
                        </select>
                        @error('payment_type')<div class="text-danger small">{{ $message }}</div>@enderror
                    </div>
                    <div class="col-md-4">
                        <label class="form-label" for="period">{{ __('Period') }} <span class="text-danger">*</span></label>
                        <select id="period" name="period" class="form-select" required>
                            <option value="">{{ __('Select Period') }}</option>
                            <option value="daily" {{ old('period') === 'daily' ? 'selected' : '' }}>{{ __('Daily') }}</option>
                            <option value="weekly" {{ old('period') === 'weekly' ? 'selected' : '' }}>{{ __('Weekly') }}</option>
                            <option value="monthly" {{ old('period') === 'monthly' ? 'selected' : '' }}>{{ __('Monthly') }}</option>
                        </select>
                        @error('period')<div class="text-danger small">{{ $message }}</div>@enderror
                    </div>
                    <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="row g-3 mt-3">
                    <div class="col-md-6">
                        <label class="form-label" for="method">{{ __('Method') }}</label>
                        <select id="method" name="method" class="form-select">
                            <option value="cash">{{ __('Cash') }}</option>
                            <option value="card">{{ __('Card') }}</option>
                        </select>
                    </div>
                    <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>

                <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-3">
                    <button type="submit" class="btn btn-primary">{{ __('Save Payment') }}</button>
                    <a href="{{ route('employee-payments.index') }}" class="btn btn-secondary">{{ __('Cancel') }}</a>
                </div>
            </form>
        </div>
    </div>
</x-app-layout>
