@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-4xl mx-auto">
        <!-- Header -->
        <div class="mb-8 flex items-center justify-between">
            <div>
                <h1 class="text-3xl font-bold text-gray-900 mb-2">🤝 كشف حساب شريك موحد</h1>
                <p class="text-gray-600">اختر شريك (عميل ومورد) لعرض بيان حسابه الموحد</p>
            </div>
            <a href="{{ route('reports.sales.index') }}" class="inline-flex items-center px-6 py-3 bg-gray-600 text-white rounded-lg hover:bg-gray-700">
                <i class="fas fa-arrow-right mr-2"></i>
                عودة
            </a>
        </div>

        <!-- Partner Selection Form -->
        <div class="bg-white rounded-xl shadow-lg p-8 border border-gray-200">
            <form method="GET" class="space-y-6">
                <div>
                    <label class="block text-lg font-semibold text-gray-900 mb-4">اختر الشريك</label>
                    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
                        @forelse($customers as $customer)
                            <a href="{{ route('reports.sales.partner-statement', ['customerId' => $customer->id]) }}" class="p-6 bg-gradient-to-br from-indigo-50 to-indigo-100 border-2 border-indigo-200 rounded-lg hover:shadow-lg transition-all hover:border-indigo-400 cursor-pointer group">
                                <div class="flex items-start">
                                    <div class="w-12 h-12 bg-indigo-600 rounded-full flex items-center justify-center flex-shrink-0 group-hover:bg-indigo-700 transition-colors">
                                        <i class="fas fa-handshake text-white text-lg"></i>
                                    </div>
                                    <div class="mr-4 flex-1">
                                        <h3 class="font-semibold text-gray-900 group-hover:text-indigo-600 transition-colors">{{ $customer->name }}</h3>
                                        <p class="text-xs text-gray-600 mt-1">مورد: {{ $customer->linkedSupplier->name ?? \App\Models\Supplier::where('linked_customer_id', $customer->id)->value('name') ?? '-' }}</p>
                                    </div>
                                    <i class="fas fa-chevron-left text-indigo-600 group-hover:translate-x-1 transition-transform mt-1"></i>
                                </div>
                            </a>
                        @empty
                            <div class="col-span-full py-12 text-center">
                                <i class="fas fa-info-circle text-5xl text-gray-300 mb-4 block"></i>
                                <p class="text-gray-500 text-lg">لا يوجد عملاء مرتبطين بموردين حالياً</p>
                                <p class="text-sm text-gray-400">يمكنك ربط العميل بمورد من خلال شاشة تعديل بيانات العميل</p>
                            </div>
                        @endforelse
                    </div>
                </div>

                @if($customers->count() > 0)
                    <div class="pt-4 border-t border-gray-200">
                        <p class="text-sm text-gray-600 mb-4">أو اختر من القائمة:</p>
                        <div class="flex gap-2">
                            <select name="customerId" class="flex-1 px-4 py-3 border-2 border-gray-300 rounded-lg focus:outline-none focus:border-indigo-500 focus:ring-2 focus:ring-indigo-200">
                                <option value="">-- اختر من القائمة --</option>
                                @foreach($customers as $customer)
                                    <option value="{{ $customer->id }}">{{ $customer->name }} (مرتبط بـ: {{ $customer->linkedSupplier->name ?? \App\Models\Supplier::where('linked_customer_id', $customer->id)->value('name') ?? '-' }})</option>
                                @endforeach
                            </select>
                            <button type="submit" formaction="{{ route('reports.sales.partner-statement') }}" class="px-6 py-3 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors font-medium">
                                عرض
                            </button>
                        </div>
                    </div>
                @endif
            </form>
        </div>
    </div>
</div>
@endsection
