@extends('layouts.app')

@section('title', 'إدارة الإيداعات')

@section('content')
<div class="min-h-screen bg-gradient-to-br from-slate-50 to-slate-100 py-8 px-4 md:px-8">
    <div class="max-w-7xl mx-auto">
        <div class="mb-8">
            <div class="flex items-center justify-between mb-6">
                <div>
                    <h1 class="text-3xl font-bold text-gray-900 mb-2">إدارة الإيداعات</h1>
                    <p class="text-gray-600">إدارة وتتبع إيداعات الخزينة والعمليات المالية</p>
                </div>
                @can('treasury.deposit.create')
                <a href="{{ route('treasury.deposits.create') }}" class="inline-flex items-center px-6 py-3 bg-gradient-to-r from-blue-600 to-blue-700 text-white font-semibold rounded-lg hover:from-blue-700 hover:to-blue-800 transition-all duration-200 shadow-lg hover:shadow-xl transform hover:scale-105">
                    <i class="fas fa-plus ml-2"></i>
                    <span>إضافة إيداع جديد</span>
                </a>
                @endcan
            </div>

            @if(session('success'))
            <div class="bg-green-50 border-l-4 border-green-500 p-4 mb-6 rounded-r-lg">
                <div class="flex">
                    <div class="flex-shrink-0">
                        <i class="fas fa-check-circle text-green-500 text-xl"></i>
                    </div>
                    <div class="mr-3">
                        <p class="text-green-700 font-medium">{{ session('success') }}</p>
                    </div>
                </div>
            </div>
            @endif
        </div>

        <div class="bg-white rounded-xl shadow-lg overflow-hidden border border-gray-200">
            <div class="overflow-x-auto">
                <table class="w-full">
                    <thead class="bg-gradient-to-r from-gray-800 to-gray-900 text-white">
                        <tr>
                            <th class="px-6 py-4 text-right font-semibold text-sm">#</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">رقم الإيداع</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">الخزينة</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">الفرع</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">المبلغ</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">التاريخ</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">النوع</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">الحساب</th>
                            <th class="px-6 py-4 text-right font-semibold text-sm">الحالة</th>
                            <th class="px-6 py-4 text-center font-semibold text-sm">الإجراءات</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        @forelse($deposits as $deposit)
                        <tr class="hover:bg-blue-50 transition-colors duration-150 border-b border-gray-100">
                            <td class="px-6 py-4 text-gray-600 font-medium">{{ $loop->iteration }}</td>
                            <td class="px-6 py-4">
                                <div class="font-semibold text-gray-900">{{ $deposit->reference_number }}</div>
                                <div class="text-xs text-gray-500">#{{ $deposit->id }}</div>
                            </td>
                            <td class="px-6 py-4 text-gray-700">{{ $deposit->treasury->name ?? 'غير محدد' }}</td>
                            <td class="px-6 py-4 text-gray-700">{{ $deposit->branch->name ?? 'غير محدد' }}</td>
                            <td class="px-6 py-4">
                                <div class="font-semibold text-gray-900">{{ number_format($deposit->amount, 2) }} ر.س</div>
                            </td>
                            <td class="px-6 py-4 text-gray-700">{{ $deposit->deposit_date->format('Y-m-d') }}</td>
                            <td class="px-6 py-4">
                                @if($deposit->deposit_type == 'cash')
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-700">
                                    <i class="fas fa-money-bill ml-1"></i>
                                    نقداً
                                </span>
                                @elseif($deposit->deposit_type == 'check')
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-100 text-blue-700">
                                    <i class="fas fa-file-invoice ml-1"></i>
                                    شيك
                                </span>
                                @elseif($deposit->deposit_type == 'bank_transfer')
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-purple-100 text-purple-700">
                                    <i class="fas fa-exchange-alt ml-1"></i>
                                    تحويل بنكي
                                </span>
                                @else
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-gray-100 text-gray-700">
                                    <i class="fas fa-ellipsis-h ml-1"></i>
                                    أخرى
                                </span>
                                @endif
                            </td>
                            <td class="px-6 py-4 text-gray-700">{{ $deposit->account ? $deposit->account->name : 'غير محدد' }}</td>
                            <td class="px-6 py-4">
                                @if($deposit->status == 'pending')
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-yellow-100 text-yellow-700">
                                    <span class="w-2 h-2 bg-yellow-500 rounded-full ml-2"></span>
                                    قيد الانتظار
                                </span>
                                @elseif($deposit->status == 'approved')
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-700">
                                    <span class="w-2 h-2 bg-green-500 rounded-full ml-2"></span>
                                    معتمد
                                </span>
                                @elseif($deposit->status == 'rejected')
                                <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-red-100 text-red-700">
                                    <span class="w-2 h-2 bg-red-500 rounded-full ml-2"></span>
                                    مرفوض
                                </span>
                                @endif
                            </td>
                            <td class="px-6 py-4">
                                <div class="flex items-center justify-center gap-1">
                                    @can('treasury.deposit.view')
                                    <a href="{{ route('treasury.deposits.show', $deposit->id) }}" class="inline-flex items-center px-3 py-2 rounded-lg bg-blue-100 text-blue-600 hover:bg-blue-200 transition-all duration-150 text-sm font-medium whitespace-nowrap" title="عرض التفاصيل">
                                        <i class="fas fa-eye mr-1"></i>
                                        <span>عرض</span>
                                    </a>
                                    @endcan

                                    @can('treasury.deposit.edit')
                                    @if($deposit->status == 'pending')
                                    <a href="{{ route('treasury.deposits.edit', $deposit->id) }}" class="inline-flex items-center px-3 py-2 rounded-lg bg-amber-100 text-amber-600 hover:bg-amber-200 transition-all duration-150 text-sm font-medium whitespace-nowrap" title="تعديل">
                                        <i class="fas fa-edit mr-1"></i>
                                        <span>تعديل</span>
                                    </a>
                                    @endif
                                    @endcan

                                    @can('treasury.deposit.approve')
                                    @if($deposit->status == 'pending')
                                    <form action="{{ route('treasury.deposits.approve', $deposit->id) }}" method="POST" class="inline">
                                        @csrf
                                        <button type="submit" class="inline-flex items-center px-3 py-2 rounded-lg bg-green-100 text-green-600 hover:bg-green-200 transition-all duration-150 text-sm font-medium whitespace-nowrap" title="اعتماد" onclick="return confirm('هل أنت متأكد من اعتماد هذا الإيداع؟')">
                                            <i class="fas fa-check mr-1"></i>
                                            <span>اعتمد</span>
                                        </button>
                                    </form>
                                    
                                    <form action="{{ route('treasury.deposits.reject', $deposit->id) }}" method="POST" class="inline">
                                        @csrf
                                        <button type="submit" class="inline-flex items-center px-3 py-2 rounded-lg bg-red-100 text-red-600 hover:bg-red-200 transition-all duration-150 text-sm font-medium whitespace-nowrap" title="رفض" onclick="return confirm('هل أنت متأكد من رفض هذا الإيداع؟')">
                                            <i class="fas fa-times mr-1"></i>
                                            <span>رفض</span>
                                        </button>
                                    </form>
                                    @endif
                                    @endcan

                                    @can('treasury.deposit.delete')
                                    @if($deposit->status == 'pending')
                                    <form action="{{ route('treasury.deposits.destroy', $deposit->id) }}" method="POST" class="inline">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="inline-flex items-center px-3 py-2 rounded-lg bg-red-100 text-red-600 hover:bg-red-200 transition-all duration-150 text-sm font-medium whitespace-nowrap" title="حذف" onclick="return confirm('هل أنت متأكد من حذف هذا الإيداع؟')">
                                            <i class="fas fa-trash mr-1"></i>
                                            <span>حذف</span>
                                        </button>
                                    </form>
                                    @endif
                                    @endcan
                                </div>
                            </td>
                        </tr>
                        @empty
                        <tr>
                            <td colspan="10" class="px-6 py-12 text-center">
                                <div class="flex flex-col items-center justify-center">
                                    <i class="fas fa-inbox text-gray-400 text-4xl mb-3"></i>
                                    <p class="text-gray-600 font-medium">لا توجد إيداعات حالياً</p>
                                    <p class="text-gray-500 text-sm mt-1">ابدأ بإضافة إيداع جديد</p>
                                </div>
                            </td>
                        </tr>
                        @endforelse
                    </tbody>
                </table>
            </div>

            <div class="px-6 py-4 bg-gray-50 border-t border-gray-200">
                <div class="flex justify-center">
                    {{ $deposits->links() }}
                </div>
            </div>
        </div>
    </div>
</div>
@endsection