﻿<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('إنشاء إيداع بنكي جديد') }}
        </h2>
    </x-slot>

    <div class="py-4">
        <div class="max-w-7xl m-auto sm:px-6 lg:px-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-4 bg-white border-b border-gray-200">
                    <form method="POST" action="{{ route('banking.deposits.store') }}" class="space-y-3">
                        @csrf

                        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                            <!-- الحساب البنكي -->
                            <div>
                                <x-input-label for="bank_account_id" :value="__('الحساب البنكي')" />
                                <select id="bank_account_id" name="bank_account_id" class="select2 mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500" required>
                                    <option value="">{{ __('اختر الحساب البنكي') }}</option>
                                    @foreach($bankAccounts as $account)
                                        @if($account->chartOfAccount && $account->chartOfAccount->is_parent == 0)
                                            <option value="{{ $account->id }}" {{ old('bank_account_id') == $account->id ? 'selected' : '' }}>
                                                {{ $account->bank->name }} - {{ $account->account_name }} - {{ $account->account_number }} ({{ $account->chartOfAccount->code }})
                                            </option>
                                        @endif
                                    @endforeach
                                </select>
                                <x-input-error :messages="$errors->get('bank_account_id')" class="mt-2" />
                            </div>

                            <!-- التاريخ -->
                            <div>
                                <x-input-label for="deposit_date" :value="__('تاريخ الإيداع')" />
                                <x-text-input id="deposit_date" class="block mt-1 w-full" type="date" name="deposit_date" :value="old('deposit_date', date('Y-m-d'))" required />
                                <x-input-error :messages="$errors->get('deposit_date')" class="mt-2" />
                            </div>

                            <!-- المبلغ -->
                            <div>
                                <x-input-label for="amount" :value="__('المبلغ')" />
                                <x-text-input id="amount" class="block mt-1 w-full" type="number" step="0.01" name="amount" :value="old('amount')" required />
                                <x-input-error :messages="$errors->get('amount')" class="mt-2" />
                            </div>

                            <!-- رقم الإيداع -->
                            <div>
                                <x-input-label for="deposit_number" :value="__('رقم الإيداع')" />
                                <x-text-input id="deposit_number" class="block mt-1 w-full" type="text" name="deposit_number" :value="old('deposit_number', $depositNumber ?? '')" required readonly />
                                <x-input-error :messages="$errors->get('deposit_number')" class="mt-2" />
                            </div>

                            <!-- رقم المرجع -->
                            <div>
                                <x-input-label for="reference_number" :value="__('رقم المرجع')" />
                                <x-text-input id="reference_number" class="block mt-1 w-full" type="text" name="reference_number" :value="old('reference_number')" />
                                <x-input-error :messages="$errors->get('reference_number')" class="mt-2" />
                            </div>

                            <!-- طريقة الإيداع -->
                            <div>
                                <x-input-label for="deposit_method" :value="__('طريقة الإيداع')" />
                                <select id="deposit_method" name="deposit_method" class="select2 mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500" required>
                                    <option value="">{{ __('اختر طريقة الإيداع') }}</option>
                                    <option value="cash" {{ old('deposit_method') == 'cash' ? 'selected' : '' }}>{{ __('نقدي') }}</option>
                                    <option value="check" {{ old('deposit_method') == 'check' ? 'selected' : '' }}>{{ __('شيك') }}</option>
                                    <option value="transfer" {{ old('deposit_method') == 'transfer' ? 'selected' : '' }}>{{ __('تحويل بنكي') }}</option>
                                    <option value="other" {{ old('deposit_method') == 'other' ? 'selected' : '' }}>{{ __('أخرى') }}</option>
                                </select>
                                <x-input-error :messages="$errors->get('deposit_method')" class="mt-2" />
                            </div>

                            <!-- اسم المودع -->
                            <div>
                                <x-input-label for="depositor_name" :value="__('اسم المودع')" />
                                <x-text-input id="depositor_name" class="block mt-1 w-full" type="text" name="depositor_name" :value="old('depositor_name')" />
                                <x-input-error :messages="$errors->get('depositor_name')" class="mt-2" />
                            </div>

                            <!-- الحساب المصدر -->
                            <div>
                                <x-input-label for="chart_of_account_id" :value="__('الحساب المصدر')" />
                                <select id="chart_of_account_id" name="chart_of_account_id" class="select2 mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500" required>
                                    <option value="">{{ __('اختر الحساب المصدر') }}</option>
                                    @foreach($accounts as $account)
                                        <option value="{{ $account->id }}" {{ old('chart_of_account_id') == $account->id ? 'selected' : '' }}>
                                            {{ $account->name }} ({{ $account->code }})
                                        </option>
                                    @endforeach
                                </select>
                                <x-input-error :messages="$errors->get('chart_of_account_id')" class="mt-2" />
                            </div>

                            <!-- مركز التكلفة -->
                            <div>
                                <x-input-label for="cost_center_id" :value="__('مركز التكلفة')" />
                                <select id="cost_center_id" name="cost_center_id" class="select2 mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">
                                    <option value="">{{ __('اختر مركز التكلفة (اختياري)') }}</option>
                                    @foreach($costCenters as $costCenter)
                                        <option value="{{ $costCenter->id }}" {{ old('cost_center_id') == $costCenter->id ? 'selected' : '' }}>
                                            {{ $costCenter->name }} ({{ $costCenter->code }})
                                        </option>
                                    @endforeach
                                </select>
                                <x-input-error :messages="$errors->get('cost_center_id')" class="mt-2" />
                            </div>

                            <!-- الوصف -->
                            <div class="lg:col-span-2">
                                <x-input-label for="description" :value="__('الوصف')" />
                                <textarea id="description" name="description" rows="1" class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500">{{ old('description') }}</textarea>
                                <x-input-error :messages="$errors->get('description')" class="mt-2" />
                            </div>

                            <!-- المرفقات -->
                            <div>
                                <x-input-label for="attachments" :value="__('المرفقات')" />
                                <input id="attachments" type="file" name="attachments[]" multiple class="mt-1 block w-full text-sm">
                                <x-input-error :messages="$errors->get('attachments')" class="mt-2" />
                            </div>
                        </div>

                        <div class="flex items-center justify-end mt-2">
                            <x-primary-button class="ms-3">
                                {{ __('حفظ') }}
                            </x-primary-button>
                            <a href="{{ route('banking.deposits.index') }}" class="inline-flex items-center p-4 py-2 bg-gray-300 border border-transparent rounded-md font-semibold text-s text-gray-800 uppercase tracking-widest hover:bg-gray-400 active:bg-gray-500 focus:outline-none focus:border-gray-500 focus:ring ring-gray-300 disabled:opacity-25 transition ease-in-out duration-150">
                                {{ __('إلغاء') }}
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
