﻿@extends('layouts.app')

@section('title', 'فئات الأصول')

@section('content')
<div class="container m-auto p-4 py-6">
    <div class="flex justify-between items-center mb-6">
        <h1 class="text-2l font-bold">فئات الأصول</h1>
        
        @can('create', App\Models\AssetCategory::class)
        <a href="{{ route('assets.categories.create') }}" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 p-4 rounded">
            <i class="fas fa-plus ml-1"></i> إضافة فئة جديدة
        </a>
        @endcan
    </div>

    @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="bg-white shadow-md rounded-lg overflow-hidden">
        <table class="min-w-full divide-y divide-gray-200">
            <thead class="bg-gray-50">
                <tr>
                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                        الاسم
                    </th>
                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                        الرمز
                    </th>
                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                        معدل الإهلاك
                    </th>
                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                        العمر الإنتاجي
                    </th>
                    <th scope="col" class="p-6 py-3 text-right text-s font-medium text-gray-500 uppercase tracking-wider">
                        الإجراءات
                    </th>
                </tr>
            </thead>
            <tbody class="bg-white divide-y divide-gray-200">
                @forelse($categories as $category)
                <tr>
                    <td class="p-6 py-4 whitespace-nowrap">
                        <div class="text-sm font-medium text-gray-900">{{ $category->name }}</div>
                    </td>
                    <td class="p-6 py-4 whitespace-nowrap">
                        <div class="text-sm text-gray-500">{{ $category->code ?? '-' }}</div>
                    </td>
                    <td class="p-6 py-4 whitespace-nowrap">
                        <div class="text-sm text-gray-500">{{ $category->depreciation_rate }}%</div>
                    </td>
                    <td class="p-6 py-4 whitespace-nowrap">
                        <div class="text-sm text-gray-500">{{ $category->useful_life }} سنة</div>
                    </td>
                    <td class="p-6 py-4 whitespace-nowrap text-right text-sm font-medium">
                        <div class="flex space-y-2 space-y-reverse">
                            @can('update', $category)
                            <a href="{{ route('assets.categories.edit', $category) }}" class="text-indigo-600 hover:text-indigo-900">
                                <i class="fas fa-edit"></i>
                            </a>
                            @endcan
                            
                            @can('delete', $category)
                            <form action="{{ route('assets.categories.destroy', $category) }}" 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>
                            @endcan
                        </div>
                    </td>
                </tr>
                @empty
                <tr>
                    <td colspan="5" class="p-6 py-4 whitespace-nowrap text-center text-sm font-medium text-gray-500">
                        لا توجد فئات أصول مضافة حتى الآن
                    </td>
                </tr>
                @endforelse
            </tbody>
        </table>
    </div>

    <div class="mt-4">
        {{ $categories->links() }}
    </div>
</div>
@endsection