@extends('layouts.app')

@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">🔄 {{ \App\Helpers\TranslationHelper::transFromDatabase('Cost Center Movements', __('Cost Center Movements')) }}</h1>
                    <p class="text-gray-600">{{ \App\Helpers\TranslationHelper::transFromDatabase('Review daily entries affecting the center', __('Review daily entries affecting the center')) }}</p>
                </div>
                <div class="flex gap-2">
                    <a href="{{ route('reports.cost-center.movements') }}" class="inline-flex items-center px-4 py-2 bg-gray-600 text-white font-semibold rounded-lg hover:bg-gray-700 transition-all duration-200 shadow-md">
                        <i class="fas fa-redo ml-2"></i>
                        <span>عرض كل الحركات</span>
                    </a>
                    <a href="{{ route('reports.cost-center') }}" 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">
                        <i class="fas fa-arrow-right ml-2"></i>
                        <span>{{ \App\Helpers\TranslationHelper::transFromDatabase('Return', __('Return')) }}</span>
                    </a>
                </div>
            </div>

            <form action="{{ route('reports.cost-center.movements') }}" method="GET" class="bg-white rounded-lg shadow-md p-6 mb-6 border border-gray-200">
                <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
                    <div>
                        <label for="center_id" class="block text-sm font-medium text-gray-700 mb-2">مركز التكلفة</label>
                        <select name="center_id" id="center_id" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
                            <option value="">الكل</option>
                            @foreach($centers as $center)
                            <option value="{{ $center->id }}" {{ request('center_id') == $center->id ? 'selected' : '' }}>{{ $center->name_ar ?: $center->name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div>
                        <label for="date_from" class="block text-sm font-medium text-gray-700 mb-2">من تاريخ</label>
                        <input type="date" name="date_from" id="date_from" value="{{ request('date_from') }}" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
                    </div>
                    <div>
                        <label for="date_to" class="block text-sm font-medium text-gray-700 mb-2">إلى تاريخ</label>
                        <input type="date" name="date_to" id="date_to" value="{{ request('date_to') }}" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
                    </div>
                    <div>
                        <label for="doc_type" class="block text-sm font-medium text-gray-700 mb-2">نوع المستند</label>
                        <select name="doc_type" id="doc_type" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent">
                            <option value="">الكل</option>
                            <option value="App\Models\CustomerInvoice" {{ request('doc_type') == 'App\Models\CustomerInvoice' ? 'selected' : '' }}>فاتورة مبيعات</option>
                            <option value="App\Models\SupplierInvoice" {{ request('doc_type') == 'App\Models\SupplierInvoice' ? 'selected' : '' }}>فاتورة مشتريات</option>
                            <option value="App\Models\TreasuryPayment" {{ request('doc_type') == 'App\Models\TreasuryPayment' ? 'selected' : '' }}>سند صرف</option>
                            <option value="App\Models\TreasuryDeposit" {{ request('doc_type') == 'App\Models\TreasuryDeposit' ? 'selected' : '' }}>سند قبض</option>
                        </select>
                    </div>
                    <div class="flex items-end gap-2">
                        <button type="submit" class="flex-1 bg-blue-600 hover:bg-blue-700 text-white font-semibold py-2 px-4 rounded-lg transition-colors duration-200">
                            <i class="fas fa-search ml-2"></i> تصفية
                        </button>
                        <a href="{{ route('reports.cost-center.movements') }}" class="flex-1 bg-gray-200 hover:bg-gray-300 text-gray-700 font-semibold py-2 px-4 rounded-lg text-center transition-colors duration-200">
                            مسح
                        </a>
                    </div>
                </div>
            </form>
        </div>

        <div class="mb-6 flex gap-2">
            <a href="{{ request()->fullUrlWithQuery(['export' => 'true']) }}" class="inline-flex items-center px-4 py-2 bg-green-600 hover:bg-green-700 text-white font-medium rounded-lg transition-colors duration-200">
                <i class="fas fa-file-excel ml-2"></i> تصدير Excel
            </a>
        </div>

        @if($report->isEmpty())
        <div class="bg-white rounded-xl shadow-lg p-12 text-center border border-gray-200">
            <i class="fas fa-inbox text-gray-400 text-5xl mb-4"></i>
            <p class="text-gray-600 font-medium text-lg">لا توجد حركات للعرض</p>
        </div>
        @else
        <div class="bg-white rounded-xl shadow-lg overflow-hidden border border-gray-200">
            <div class="overflow-x-auto">
                <table class="w-full text-right">
                    <thead class="bg-gray-800 text-white">
                        <tr>
                            <th class="px-6 py-4 font-semibold text-sm">التاريخ</th>
                            <th class="px-6 py-4 font-semibold text-sm">كود المركز</th>
                            <th class="px-6 py-4 font-semibold text-sm">مركز التكلفة</th>
                            <th class="px-6 py-4 font-semibold text-sm">نوع المستند</th>
                            <th class="px-6 py-4 font-semibold text-sm">رقم المستند</th>
                            <th class="px-6 py-4 font-semibold text-sm">البيان</th>
                            <th class="px-6 py-4 font-semibold text-sm text-center">قيمة الحركة</th>
                            <th class="px-6 py-4 font-semibold text-sm">المستخدم</th>
                        </tr>
                    </thead>
                    <tbody class="divide-y divide-gray-200">
                        @foreach($report as $item)
                        <tr class="hover:bg-blue-50 transition-colors duration-150">
                            <td class="px-6 py-4 text-sm text-gray-700">{{ $item->date }}</td>
                            <td class="px-6 py-4 text-sm font-semibold text-gray-600">{{ $item->center_code ?: '-' }}</td>
                            <td class="px-6 py-4 text-sm text-gray-700">{{ $item->center_name ?: '-' }}</td>
                            <td class="px-6 py-4 text-sm text-gray-700">{{ $item->doc_type }}</td>
                            <td class="px-6 py-4 font-mono text-sm font-semibold text-blue-600">{{ $item->doc_number }}</td>
                            <td class="px-6 py-4 text-sm text-gray-700">{{ $item->statement }}</td>
                            <td class="px-6 py-4 text-center">
                                <span class="bg-blue-100 text-blue-800 px-3 py-1 rounded-full text-sm font-bold">
                                    {{ number_format($item->amount, 2) }}
                                </span>
                            </td>
                            <td class="px-6 py-4 text-sm text-gray-700">{{ $item->user }}</td>
                        </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
        </div>
        @endif
    </div>
</div>
@endsection
