﻿<x-app-layout>
    <x-slot name="header">
        <div class="flex justify-between items-center">
            <h2 class="font-semibold text-l text-gray-800 leading-tight">
                {{ __('صيانة الأصل') }}: {{ $asset->name }}
            </h2>
            <div class="flex space-y-2 space-y-reverse">
                <x-button-link href="{{ route('assets.maintenance.create', $asset->id) }}" class="bg-green-600 hover:bg-green-700">
                    <i class="fas fa-plus ml-1"></i> {{ __('إضافة صيانة جديدة') }}
                </x-button-link>
                <x-button-link href="{{ route('assets.show', $asset->id) }}" class="bg-gray-600 hover:bg-gray-700">
                    <i class="fas fa-arrow-right ml-1"></i> {{ __('العودة للأصل') }}
                </x-button-link>
            </div>
        </div>
    </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('success'))
                    <div class="bg-green-100 border border-green-400 text-green-700 p-4 py-3 rounded relative mb-4" role="alert">
                        <span class="block sm:inline">{{ session('success') }}</span>
                    </div>
                    @endif

                    @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

                    <div class="overflow--auto">
                        <table class="min-w-full bg-white">
                            <thead class="bg-gray-100">
                                <tr>
                                    <th class="py-2 p-4 border-b text-right">{{ __('نوع الصيانة') }}</th>
                                    <th class="py-2 p-4 border-b text-right">{{ __('تاريخ الصيانة') }}</th>
                                    <th class="py-2 p-4 border-b text-right">{{ __('تاريخ الصيانة القادمة') }}</th>
                                    <th class="py-2 p-4 border-b text-right">{{ __('التكلفة') }}</th>
                                    <th class="py-2 p-4 border-b text-right">{{ __('المورد') }}</th>
                                    <th class="py-2 p-4 border-b text-right">{{ __('الحالة') }}</th>
                                    <th class="py-2 p-4 border-b text-right">{{ __('الإجراءات') }}</th>
                                </tr>
                            </thead>
                            <tbody>
                                @forelse($maintenances as $maintenance)
                                <tr class="hover:bg-gray-50">
                                    <td class="py-2 p-4 border-b">{{ $maintenance->maintenance_type }}</td>
                                    <td class="py-2 p-4 border-b">{{ $maintenance->maintenance_date }}</td>
                                    <td class="py-2 p-4 border-b">{{ $maintenance->next_maintenance_date ?? '-' }}</td>
                                    <td class="py-2 p-4 border-b">{{ number_format($maintenance->cost, 2) }}</td>
                                    <td class="py-2 p-4 border-b">{{ $maintenance->supplier ?? '-' }}</td>
                                    <td class="py-2 p-4 border-b">
                                        @if($maintenance->status == 'scheduled')
                                            <span class="p-2 py-1 bg-blue-100 text-blue-800 rounded-full text-s">{{ __('مجدولة') }}</span>
                                        @elseif($maintenance->status == 'in_progress')
                                            <span class="p-2 py-1 bg-yellow-100 text-yellow-800 rounded-full text-s">{{ __('قيد التنفيذ') }}</span>
                                        @elseif($maintenance->status == 'completed')
                                            <span class="p-2 py-1 bg-green-100 text-green-800 rounded-full text-s">{{ __('مكتملة') }}</span>
                                        @elseif($maintenance->status == 'cancelled')
                                            <span class="p-2 py-1 bg-red-100 text-red-800 rounded-full text-s">{{ __('ملغاة') }}</span>
                                        @endif
                                    </td>
                                    <td class="py-2 p-4 border-b">
                                        <div class="flex items-center space-y-2 space-y-reverse">
                                            <a href="{{ route('assets.maintenance.edit', $maintenance->id) }}" class="text-yellow-600 hover:text-yellow-900">
                                                <i class="fas fa-edit"></i>
                                            </a>
                                            <form action="{{ route('assets.maintenance.destroy', $maintenance->id) }}" method="POST" class="inline" onsubmit="return confirm('هل أنت متأكد من حذف هذه الصيانة؟');">
                                                @csrf
                                                @method('DELETE')
                                                <button type="submit" class="text-red-600 hover:text-red-900">
                                                    <i class="fas fa-trash"></i>
                                                </button>
                                            </form>
                                        </div>
                                    </td>
                                </tr>
                                @empty
                                <tr>
                                    <td colspan="7" class="py-4 p-4 border-b text-center text-gray-500">{{ __('لا توجد عمليات صيانة لهذا الأصل') }}</td>
                                </tr>
                                @endforelse
                            </tbody>
                        </table>
                    </div>

                    <div class="mt-4">
                        {{ $maintenances->links() }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>