﻿<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">
                    
                    @if(session('error'))
                    <div class="bg-red-100 border border-red-400 text-red-700 p-4 py-3 rounded relative mb-4" role="alert">
                        <span class="block sm:inline">{{ session('error') }}</span>
                    </div>
                    @endif

                    <form action="{{ route('assets.depreciations.update', $depreciation) }}" method="POST">
                        @csrf
                        @method('PUT')
                        
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                            <div>
                                <x-label for="asset_id" :value="__('الأصل')" />
                                <div class="block mt-1 w-full py-2 p-3 border border-gray-300 bg-gray-100 rounded-md">
                                    {{ $depreciation->asset->name }} ({{ $depreciation->asset->asset_code }})
                                </div>
                                <p class="text-sm text-gray-500 mt-1">{{ __('لا يمكن تغيير الأصل بعد إنشاء الإهلاك') }}</p>
                            </div>

                            <div>
                                <x-label for="depreciation_date" :value="__('تاريخ الإهلاك')" />
                                <x-input id="depreciation_date" type="date" name="depreciation_date" :value="old('depreciation_date', $depreciation->depreciation_date->format('Y-m-d'))" required class="block mt-1 w-full" />
                                @error('depreciation_date')
                                <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>
                        </div>

                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                            <div>
                                <x-label for="depreciation_amount" :value="__('مبلغ الإهلاك')" />
                                <x-input id="depreciation_amount" type="number" step="0.01" name="depreciation_amount" :value="old('depreciation_amount', $depreciation->depreciation_amount)" required class="block mt-1 w-full" />
                                @error('depreciation_amount')
                                <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <div>
                                <x-label for="notes" :value="__('ملاحظات')" />
                                <textarea id="notes" name="notes" rows="3"
                                    class="block mt-1 w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50">{{ old('notes', $depreciation->notes) }}</textarea>
                                @error('notes')
                                <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>
                        </div>

                        <div class="flex items-center justify-between mt-8">
                            <x-button-link href="{{ route('assets.depreciations.index') }}" class="bg-gray-600 hover:bg-gray-700">
                                {{ __('إلغاء') }}
                            </x-button-link>
                            
                            <x-button type="submit" class="bg-green-600 hover:bg-green-700">
                                {{ __('حفظ التغييرات') }}
                            </x-button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
