﻿<x-app-layout>
    <x-slot name="header">
        <h2 class="font-semibold text-l text-gray-800 leading-tight">
            {{ __('تعديل صيانة') }}: {{ $asset->name }}
        </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.maintenance.update', $maintenance->id) }}" method="POST">
                        @csrf
                        @method('PUT')
                        
                        <div class="grid grid-cols-1 md:grid-cols-2 gap-6 mb-6">
                            <!-- نوع الصيانة -->
                            <div>
                                <x-label for="maintenance_type" :value="__('نوع الصيانة')" />
                                <x-input id="maintenance_type" class="block mt-1 w-full" type="text" name="maintenance_type" :value="old('maintenance_type', $maintenance->maintenance_type)" required />
                                @error('maintenance_type')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- تاريخ الصيانة -->
                            <div>
                                <x-label for="maintenance_date" :value="__('تاريخ الصيانة')" />
                                <x-input id="maintenance_date" class="block mt-1 w-full" type="date" name="maintenance_date" :value="old('maintenance_date', $maintenance->maintenance_date)" required />
                                @error('maintenance_date')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- تاريخ الصيانة القادمة -->
                            <div>
                                <x-label for="next_maintenance_date" :value="__('تاريخ الصيانة القادمة (اختياري)')" />
                                <x-input id="next_maintenance_date" class="block mt-1 w-full" type="date" name="next_maintenance_date" :value="old('next_maintenance_date', $maintenance->next_maintenance_date)" />
                                @error('next_maintenance_date')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

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

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

                            <!-- الحالة -->
                            <div>
                                <x-label for="status" :value="__('الحالة')" />
                                <select id="status" name="status" 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="scheduled" {{ old('status', $maintenance->status) == 'scheduled' ? 'selected' : '' }}>{{ __('مجدولة') }}</option>
                                    <option value="in_progress" {{ old('status', $maintenance->status) == 'in_progress' ? 'selected' : '' }}>{{ __('قيد التنفيذ') }}</option>
                                    <option value="completed" {{ old('status', $maintenance->status) == 'completed' ? 'selected' : '' }}>{{ __('مكتملة') }}</option>
                                    <option value="cancelled" {{ old('status', $maintenance->status) == 'cancelled' ? 'selected' : '' }}>{{ __('ملغاة') }}</option>
                                </select>
                                @error('status')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>

                            <!-- القائم بالصيانة -->
                            <div>
                                <x-label for="performed_by" :value="__('القائم بالصيانة (اختياري)')" />
                                <x-input id="performed_by" class="block mt-1 w-full" type="text" name="performed_by" :value="old('performed_by', $maintenance->performed_by)" />
                                @error('performed_by')
                                    <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                                @enderror
                            </div>
                        </div>

                        <!-- الوصف -->
                        <div class="mb-6">
                            <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', $maintenance->description) }}</textarea>
                            @error('description')
                                <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                            @enderror
                        </div>

                        <!-- الإجراءات المتخذة -->
                        <div class="mb-6">
                            <x-label for="actions_taken" :value="__('الإجراءات المتخذة (اختياري)')" />
                            <textarea id="actions_taken" name="actions_taken" 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('actions_taken', $maintenance->actions_taken) }}</textarea>
                            @error('actions_taken')
                                <p class="text-red-500 text-s mt-1">{{ $message }}</p>
                            @enderror
                        </div>

                        <div class="flex items-center justify-end mt-4">
                            <x-button type="submit" class="ml-3 bg-primary-600 hover:bg-primary-700">
                                {{ __('حفظ التغييرات') }}
                            </x-button>
                            <x-button-link href="{{ route('assets.maintenance.index', $asset->id) }}" class="bg-gray-600 hover:bg-gray-700">
                                {{ __('إلغاء') }}
                            </x-button-link>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
