@extends('layouts.app')

@section('content')
<div class="top-bar d-flex justify-content-between align-items-center">
    <h2 class="mb-0">لوحة التحكم</h2>
    <a href="{{ route('transfers.create') }}" class="btn btn-primary">
        <i class="fas fa-plus-circle"></i>
        حوالة جديدة
    </a>
</div>

<div class="row g-4 mb-4">
    <div class="col-md-3">
        <div class="stat-card total">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <p class="text-muted mb-1">إجمالي الحوالات</p>
                    <h3 class="mb-0">{{ $totalTransfers }}</h3>
                </div>
                <div class="icon">
                    <i class="fas fa-exchange-alt"></i>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="stat-card pending">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <p class="text-muted mb-1">حوالات معلقة</p>
                    <h3 class="mb-0">{{ $pendingTransfers }}</h3>
                </div>
                <div class="icon">
                    <i class="fas fa-clock"></i>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-3">
        <div class="stat-card completed">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <p class="text-muted mb-1">حوالات مكتملة</p>
                    <h3 class="mb-0">{{ $completedTransfers }}</h3>
                </div>
                <div class="icon">
                    <i class="fas fa-check-circle"></i>
                </div>
            </div>
        </div>
    </div>
    @if($isAdmin)
    <div class="col-md-3">
        <div class="stat-card" style="border-right: 4px solid #9b59b6;">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <p class="text-muted mb-1">رصيدك USD</p>
                    <h3 class="mb-0 text-success">$ {{ number_format($totalBalanceUSD, 2) }}</h3>
                </div>
                <div class="icon" style="background: rgba(155, 89, 182, 0.15); color: #9b59b6;">
                    <i class="fas fa-wallet"></i>
                </div>
            </div>
        </div>
    </div>
    @endif
</div>

<div class="row g-4 mb-4">
    <div class="col-md-6">
        <div class="stat-card" style="border-right: 4px solid #27ae60;">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <p class="text-muted mb-1">المبالغ بالدولار</p>
                    <h3 class="mb-0 text-success">$ {{ number_format($totalAmountUSD, 2) }}</h3>
                </div>
                <div class="icon" style="background: rgba(39, 174, 96, 0.15); color: #27ae60;">
                    <i class="fas fa-dollar-sign"></i>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="stat-card" style="border-right: 4px solid #3498db;">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <p class="text-muted mb-1">المبالغ بالليرة</p>
                    <h3 class="mb-0 text-primary">£ {{ number_format($totalAmountSYR, 0) }}</h3>
                </div>
                <div class="icon" style="background: rgba(52, 152, 219, 0.15); color: #3498db;">
                    <i class="fas fa-coins"></i>
                </div>
            </div>
        </div>
    </div>
</div>

@if(!$isAdmin)
<div class="row g-4 mb-4">
    <div class="col-md-6">
        <div class="stat-card" style="border-right: 4px solid #27ae60;">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <p class="text-muted mb-1">رصيدك بالدولار</p>
                    <h3 class="mb-0 text-success">$ {{ number_format($totalBalanceUSD, 2) }}</h3>
                </div>
                <div class="icon" style="background: rgba(39, 174, 96, 0.15); color: #27ae60;">
                    <i class="fas fa-wallet"></i>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-6">
        <div class="stat-card" style="border-right: 4px solid #3498db;">
            <div class="d-flex justify-content-between align-items-center">
                <div>
                    <p class="text-muted mb-1">رصيدك بالليرة</p>
                    <h3 class="mb-0 text-primary">£ {{ number_format($totalBalanceSYR, 0) }}</h3>
                </div>
                <div class="icon" style="background: rgba(52, 152, 219, 0.15); color: #3498db;">
                    <i class="fas fa-coins"></i>
                </div>
            </div>
        </div>
    </div>
</div>
@endif

<div class="table-container">
    <h4 class="page-title">آخر الحوالات</h4>
    <div class="table-responsive">
        <table class="table table-hover">
            <thead>
                <tr>
                    <th>#</th>
                    <th>المرسل</th>
                    <th>المستلم</th>
                    <th>المبلغ</th>
                    <th>الحالة</th>
                    <th>التاريخ</th>
                    <th>الإجراءات</th>
                </tr>
            </thead>
            <tbody>
                @forelse($recentTransfers as $transfer)
                    <tr>
                        <td>{{ $transfer->id }}</td>
                        <td>
                            <div>{{ $transfer->sender_name }}</div>
                            <small class="text-muted">{{ $transfer->sender_phone }}</small>
                        </td>
                        <td>
                            <div>{{ $transfer->recipient_name }}</div>
                            <small class="text-muted">{{ $transfer->recipient_phone }}</small>
                        </td>
                        <td>
                            <strong>{{ $transfer->amount }}</strong>
                            <span class="text-muted">{{ $transfer->currency }}</span>
                        </td>
                        <td>
                            @if($transfer->status == 'pending')
                                <span class="status-badge status-pending">معلقة</span>
                            @elseif($transfer->status == 'completed')
                                <span class="status-badge status-completed">مكتملة</span>
                            @else
                                <span class="status-badge status-cancelled">ملغاة</span>
                            @endif
                        </td>
                        <td>{{ $transfer->created_at->format('Y-m-d') }}</td>
                        <td>
                            <a href="{{ route('transfers.show', $transfer) }}" class="btn btn-sm btn-outline-primary">
                                <i class="fas fa-eye"></i>
                            </a>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="7" class="text-center text-muted py-4">
                            <i class="fas fa-inbox fa-2x mb-2"></i>
                            <p class="mb-0">لا توجد حوالات بعد</p>
                        </td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
    @if($recentTransfers->count() > 0)
        <div class="text-center mt-3">
            <a href="{{ route('transfers.index') }}" class="btn btn-link">عرض جميع الحوالات</a>
        </div>
    @endif
</div>
@endsection
