@php
    $locale = app()->getLocale();
    $riskColor = [
        'critical' => 'danger',
        'high' => 'warning',
        'medium' => 'info',
        'low' => 'success',
        'blacklisted' => 'dark'
    ];
    $riskLabel = [
        'critical' => $locale == 'ar' ? 'حرج جداً 🔴' : 'Critical 🔴',
        'high' => $locale == 'ar' ? 'مرتفع 🟠' : 'High 🟠',
        'medium' => $locale == 'ar' ? 'متوسط 🟡' : 'Medium 🟡',
        'low' => $locale == 'ar' ? 'منخفض 🟢' : 'Low 🟢',
        'blacklisted' => $locale == 'ar' ? 'محظور 🚫' : 'Blacklisted 🚫'
    ];
@endphp

<div class="bg-[#111] border border-gray-800 rounded-2xl p-6 mb-6">
    <h3 class="text-lg font-bold text-[#d4af37] mb-4">{{ $locale == 'ar' ? 'ملخص تقييم العميل' : 'Customer Risk Assessment' }}</h3>
    
    <div class="grid grid-cols-1 md:grid-cols-4 gap-4">
        <!-- Risk Level -->
        <div class="bg-black/50 border border-gray-700 rounded-xl p-4">
            <div class="text-xs text-gray-500 uppercase">{{ $locale == 'ar' ? 'مستوى المخاطر' : 'Risk Level' }}</div>
            @if($customer->isBlacklisted())
                <div class="text-2xl font-black text-red-500 mt-2">🚫</div>
                <div class="text-xs text-red-400 font-bold mt-1">{{ $locale == 'ar' ? 'محظور' : 'Blacklisted' }}</div>
            @else
                @php $risk = $customer->rating; @endphp
                <div class="text-2xl font-black {{ $riskColor[$risk->risk_level] == 'danger' ? 'text-red-500' : ($riskColor[$risk->risk_level] == 'warning' ? 'text-yellow-500' : ($riskColor[$risk->risk_level] == 'info' ? 'text-blue-500' : 'text-green-500')) }} mt-2">
                    @if($risk->risk_level == 'critical') 🔴 @elseif($risk->risk_level == 'high') 🟠 @elseif($risk->risk_level == 'medium') 🟡 @else 🟢 @endif
                </div>
                <div class="text-xs font-bold mt-1 {{ $riskColor[$risk->risk_level] == 'danger' ? 'text-red-400' : ($riskColor[$risk->risk_level] == 'warning' ? 'text-yellow-400' : ($riskColor[$risk->risk_level] == 'info' ? 'text-blue-400' : 'text-green-400')) }}">
                    {{ $riskLabel[$risk->risk_level] }}
                </div>
            @endif
        </div>

        <!-- Violations Count -->
        <div class="bg-black/50 border border-gray-700 rounded-xl p-4">
            <div class="text-xs text-gray-500 uppercase">{{ $locale == 'ar' ? 'المخالفات' : 'Violations' }}</div>
            @php $violations = $customer->violations()->count(); @endphp
            <div class="text-3xl font-black {{ $violations > 5 ? 'text-red-500' : ($violations > 2 ? 'text-yellow-500' : 'text-white') }} mt-2">
                {{ $violations }}
            </div>
            <div class="text-[10px] text-gray-400 mt-1">{{ $locale == 'ar' ? 'مخالفة مسجلة' : 'recorded violations' }}</div>
        </div>

        <!-- Late Payments -->
        <div class="bg-black/50 border border-gray-700 rounded-xl p-4">
            <div class="text-xs text-gray-500 uppercase">{{ $locale == 'ar' ? 'تأخيرات السداد' : 'Late Payments' }}</div>
            @php $delays = $customer->paymentDelays()->where('status', '!=', 'paid')->count(); @endphp
            <div class="text-3xl font-black {{ $delays > 2 ? 'text-red-500' : ($delays > 0 ? 'text-yellow-500' : 'text-white') }} mt-2">
                {{ $delays }}
            </div>
            <div class="text-[10px] text-gray-400 mt-1">{{ $locale == 'ar' ? 'تأخيرات قائمة' : 'pending delays' }}</div>
        </div>

        <!-- Outstanding Amount -->
        <div class="bg-black/50 border border-gray-700 rounded-xl p-4">
            <div class="text-xs text-gray-500 uppercase">{{ $locale == 'ar' ? 'المبلغ المتأخر' : 'Outstanding' }}</div>
            @php $outstanding = $customer->paymentDelays()->where('status', '!=', 'paid')->sum('delayed_amount'); @endphp
            <div class="text-2xl font-black text-red-400 mt-2">
                {{ number_format($outstanding, 0) }}
            </div>
            <div class="text-[10px] text-gray-400 mt-1">{{ $locale == 'ar' ? 'ر.س' : 'SAR' }}</div>
        </div>
    </div>

    @if($customer->isBlacklisted())
        @php $blacklist = $customer->getActiveBlacklist(); @endphp
        <div class="bg-red-500/10 border border-red-500/30 rounded-lg p-4 mt-4">
            <div class="text-sm font-bold text-red-400 mb-2">{{ $locale == 'ar' ? '⚠️ العميل محظور من قائمة الحظر' : '⚠️ Customer is Blacklisted' }}</div>
            <div class="text-xs text-red-300">
                <div class="mb-1"><strong>{{ $locale == 'ar' ? 'السبب:' : 'Reason:' }}</strong> {{ $blacklist->reason }}</div>
                <div class="mb-1"><strong>{{ $locale == 'ar' ? 'التاريخ:' : 'Date:' }}</strong> {{ $blacklist->blacklisted_from->format('Y-m-d') }}</div>
                @if($blacklist->blacklisted_until)
                    <div><strong>{{ $locale == 'ar' ? 'حتى:' : 'Until:' }}</strong> {{ $blacklist->blacklisted_until->format('Y-m-d') }}</div>
                @endif
            </div>
        </div>
    @endif
</div>
