@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">
        <div class="mb-8 flex justify-between items-center">
            <h1 class="text-3xl font-bold text-gray-900">تفاصيل العمولة</h1>
            <a href="{{ route('sales.commissions.index') }}" class="inline-flex items-center px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700">
                <i class="fas fa-arrow-right ml-2"></i> العودة
            </a>
        </div>

        <div class="bg-white rounded-xl shadow-lg border border-gray-200 overflow-hidden">
            <div class="p-6 grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <label class="text-sm text-gray-500">المندوب</label>
                    <p class="text-lg font-semibold">{{ $commission->salesRepresentative->employee->user->name ?? '---' }}</p>
                </div>
                <div>
                    <label class="text-sm text-gray-500">رقم الفاتورة</label>
                    <p class="text-lg font-semibold text-blue-600">
                        <a href="{{ route('customer-invoices.show', $commission->customerInvoice) }}">{{ $commission->customerInvoice->invoice_number }}</a>
                    </p>
                </div>
                <div>
                    <label class="text-sm text-gray-500">مبلغ العمولة</label>
                    <p class="text-2xl font-bold text-gray-900">{{ number_format($commission->amount, 2) }}</p>
                </div>
                <div>
                    <label class="text-sm text-gray-500">الحالة الحالية</label>
                    <div class="mt-1">
                        @php
                            $statusLabels = [
                                'pending' => 'معلق',
                                'earned' => 'مكتسب',
                                'paid' => 'مدفوع',
                                'cancelled' => 'ملغي',
                            ];
                        @endphp
                        <span class="px-3 py-1 rounded-full text-sm font-bold bg-blue-50 text-blue-700 border border-blue-200">
                            {{ $statusLabels[$commission->status] ?? $commission->status }}
                        </span>
                    </div>
                </div>
            </div>

            <div class="bg-gray-50 p-6 border-t border-gray-200">
                <h3 class="text-lg font-semibold mb-4">تحديث الحالة</h3>
                <form action="{{ route('sales.commissions.update-status', $commission) }}" method="POST" class="flex items-end gap-4">
                    @csrf
                    @method('PATCH')
                    <div class="flex-grow">
                        <select name="status" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500">
                            <option value="pending" {{ $commission->status == 'pending' ? 'selected' : '' }}>معلق</option>
                            <option value="earned" {{ $commission->status == 'earned' ? 'selected' : '' }}>مكتسب</option>
                            <option value="paid" {{ $commission->status == 'paid' ? 'selected' : '' }}>مدفوع</option>
                            <option value="cancelled" {{ $commission->status == 'cancelled' ? 'selected' : '' }}>ملغي</option>
                        </select>
                    </div>
                    <button type="submit" class="px-6 py-2 bg-blue-600 text-white font-bold rounded-lg hover:bg-blue-700">تحديث</button>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection
