@extends('layouts.app')

@section('content')
<div class="top-bar d-flex justify-content-between align-items-center">
    <h2 class="mb-0">ملف المستخدم: {{ $user->name }}</h2>
    <div>
        <a href="{{ route('users.index') }}" class="btn btn-secondary">
            <i class="fas fa-arrow-right"></i>
            رجوع
        </a>
        <a href="{{ route('users.edit', $user) }}" class="btn btn-primary">
            <i class="fas fa-edit"></i>
            تعديل
        </a>
    </div>
</div>

<div class="row g-4">
    <div class="col-md-4">
        <div class="stat-card">
            <h6 class="text-muted">الاسم</h6>
            <h4>{{ $user->name }}</h4>
        </div>
    </div>
    <div class="col-md-4">
        <div class="stat-card">
            <h6 class="text-muted">البريد الإلكتروني</h6>
            <h4">{{ $user->email }}</h4>
        </div>
    </div>
    <div class="col-md-4">
        <div class="stat-card">
            <h6 class="text-muted">الدور</h6>
            <h4>
                @if($user->role === 'admin')
                    <span class="badge bg-danger">مدير</span>
                @else
                    <span class="badge bg-secondary">مستخدم</span>
                @endif
            </h4>
        </div>
    </div>
</div>

<div class="row g-4 mt-2">
    <div class="col-md-6">
        <div class="stat-card" style="border-right: 4px solid #27ae60;">
            <h6 class="text-muted">رصيد الدولار</h6>
            <h3 class="text-success">$ {{ number_format($user->balance_usd, 2) }}</h3>
        </div>
    </div>
    <div class="col-md-6">
        <div class="stat-card" style="border-right: 4px solid #3498db;">
            <h6 class="text-muted">رصيد الليرة</h6>
            <h3 class="text-primary">£ {{ number_format($user->balance_syr, 0) }}</h3>
        </div>
    </div>
</div>

<div class="row g-4 mt-2">
    <div class="col-md-6">
        <div class="form-card">
            <h5 class="mb-4"><i class="fas fa-plus-circle text-success"></i> إضافة رصيد</h5>
            <form action="{{ route('users.balance', $user) }}" method="POST">
                @csrf
                @method('PATCH')
                <input type="hidden" name="type" value="add">
                <div class="mb-3">
                    <label class="form-label">العملة</label>
                    <select name="currency" class="form-select" required>
                        <option value="USD">دولار (USD)</option>
                        <option value="SYR">ليرة (SYR)</option>
                    </select>
                </div>
                <div class="mb-3">
                    <label class="form-label">المبلغ</label>
                    <input type="number" name="amount" class="form-control" step="0.01" min="1" required>
                </div>
                <button type="submit" class="btn btn-success w-100">
                    <i class="fas fa-plus"></i>
                    إضافة
                </button>
            </form>
        </div>
    </div>
    <div class="col-md-6">
        <div class="form-card">
            <h5 class="mb-4"><i class="fas fa-minus-circle text-danger"></i> خصم رصيد</h5>
            <form action="{{ route('users.balance', $user) }}" method="POST">
                @csrf
                @method('PATCH')
                <input type="hidden" name="type" value="subtract">
                <div class="mb-3">
                    <label class="form-label">العملة</label>
                    <select name="currency" class="form-select" required>
                        <option value="USD">دولار (USD)</option>
                        <option value="SYR">ليرة (SYR)</option>
                    </select>
                </div>
                <div class="mb-3">
                    <label class="form-label">المبلغ</label>
                    <input type="number" name="amount" class="form-control" step="0.01" min="1" required>
                </div>
                <button type="submit" class="btn btn-danger w-100">
                    <i class="fas fa-minus"></i>
                    خصم
                </button>
            </form>
        </div>
    </div>
</div>

<div class="table-container mt-4">
    <h5 class="mb-3">إحصائيات المستخدم</h5>
    <div class="row g-3">
        <div class="col-md-4">
            <div class="p-3 bg-light rounded">
                <p class="text-muted mb-1">إجمالي الحوالات</p>
                <h4>{{ $user->transfers()->count() }}</h4>
            </div>
        </div>
        <div class="col-md-4">
            <div class="p-3 bg-light rounded">
                <p class="text-muted mb-1">حوالات معلقة</p>
                <h4>{{ $user->transfers()->where('status', 'pending')->count() }}</h4>
            </div>
        </div>
        <div class="col-md-4">
            <div class="p-3 bg-light rounded">
                <p class="text-muted mb-1">حوالات مكتملة</p>
                <h4>{{ $user->transfers()->where('status', 'completed')->count() }}</h4>
            </div>
        </div>
    </div>
</div>
@endsection
