﻿<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-l text-gray-800 leading-tight">
            {{ __('إضافة خزينة جديدة') }}
        </h2>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7l m-auto sm:p-6 lg:p-8">
            <div class="bg-white overflow-hidden shadow-sm sm:rounded-lg">
                <div class="p-6 bg-white border-b border-gray-200">
                    <form method="POST" action="{{ route('treasury.treasuries.store') }}">
                        @csrf

                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                            <!-- اسم الخزينة -->
                            <div>
                                <x-label for="name" :value="__('اسم الخزينة')" />
                                <x-input id="name" class="block mt-1 w-full" type="text" name="name" :value="old('name')" required autofocus />
                                @error('name')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- كود الخزينة -->
                            <div>
                                <x-label for="code" :value="__('كود الخزينة')" />
                                <x-input id="code" class="block mt-1 w-full" type="text" name="code" :value="old('code')" required />
                                @error('code')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- الفرع -->
                            <div>
                                <x-label for="branch_id" :value="__('الفرع')" />
                                <select id="branch_id" name="branch_id" class="rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 block mt-1 w-full" required>
                                    <option value="">اختر الفرع</option>
                                    @foreach ($branches as $branch)
                                        <option value="{{ $branch->id }}" {{ old('branch_id') == $branch->id ? 'selected' : '' }}>
                                            {{ $branch->name }}
                                        </option>
                                    @endforeach
                                </select>
                                @error('branch_id')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- المسؤول -->
                            <div>
                                <x-label for="responsible_user_id" :value="__('المسؤول')" />
                                <select id="responsible_user_id" name="responsible_user_id" class="rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 block mt-1 w-full">
                                    <option value="">اختر المسؤول</option>
                                    @foreach ($users as $user)
                                        <option value="{{ $user->id }}" {{ old('responsible_user_id') == $user->id ? 'selected' : '' }}>
                                            {{ $user->name }}
                                        </option>
                                    @endforeach
                                </select>
                                @error('responsible_user_id')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- الموقع -->
                            <div>
                                <x-label for="location" :value="__('الموقع')" />
                                <x-input id="location" class="block mt-1 w-full" type="text" name="location" :value="old('location')" />
                                @error('location')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- الرصيد الافتتاحي -->
                            <div>
                                <x-label for="initial_balance" :value="__('الرصيد الافتتاحي')" />
                                <x-input id="initial_balance" class="block mt-1 w-full" type="number" step="0.01" name="initial_balance" :value="old('initial_balance', 0)" required />
                                @error('initial_balance')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- الوصف -->
                            <div class="col-span-2">
                                <x-label for="description" :value="__('الوصف')" />
                                <textarea id="description" name="description" rows="3" class="rounded-md shadow-sm border-gray-300 focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 block mt-1 w-full">{{ old('description') }}</textarea>
                                @error('description')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- الحالة -->
                            <div class="col-span-2">
                                <label for="is_active" class="inline-flex items-center mt-3">
                                    <input id="is_active" type="checkbox" name="is_active" value="1" class="rounded border-gray-300 text-indigo-600 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" {{ old('is_active', true) ? 'checked' : '' }}>
                                    <span class="mr-2 text-sm text-gray-600">{{ __('نشط') }}</span>
                                </label>
                            </div>
                        </div>

                        <div class="flex items-center justify-end mt-4">
                            <a href="{{ route('treasury.treasuries.index') }}" class="inline-flex items-center p-4 py-2 bg-gray-300 border border-transparent rounded-md font-semibold text-s text-black 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 ml-4">
                                {{ __('إلغاء') }}
                            </a>
                            <x-button>
                                {{ __('حفظ') }}
                            </x-button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
