@extends('layouts.account', ['title' => 'التذاكر | RaseedNow'])

@section('account_content')
    <div class="kd-page-head">
        <h1>التذاكر</h1>
    </div>

    <div class="kd-stats-grid four">
        <div class="kd-stat-card"><span>الإجمالي</span><strong>{{ $tickets->total() }}</strong></div>
        <div class="kd-stat-card"><span>مفتوحة</span><strong>{{ $user->supportTickets()->where('status', 'open')->count() }}</strong></div>
        <div class="kd-stat-card"><span>قيد المعالجة</span><strong>{{ $user->supportTickets()->where('status', 'in_progress')->count() }}</strong></div>
        <div class="kd-stat-card"><span>تم الحل</span><strong>{{ $user->supportTickets()->whereIn('status', ['resolved', 'closed'])->count() }}</strong></div>
    </div>

    <div class="kd-two-col">
        <section class="kd-card">
            <div class="kd-card-head"><h2>تذاكري</h2></div>
            <div class="kd-list">
                @forelse($tickets as $ticket)
                    <a href="{{ route('account.support.show', $ticket) }}" class="kd-list-row stacked">
                        <strong>{{ $ticket->ticket_number }} — {{ $ticket->subject }}</strong>
                        <span>{{ $ticket->status }} / {{ $ticket->priority }} / {{ $ticket->last_activity_at?->diffForHumans() }}</span>
                    </a>
                @empty
                    <div class="kd-empty"><h3>لا توجد تذاكر</h3><p>لم تقم بإنشاء أي تذاكر بعد.</p></div>
                @endforelse
            </div>
        </section>

        <section class="kd-card">
            <div class="kd-card-head"><h2>إنشاء أول تذكرة</h2></div>
            <form method="POST" action="{{ route('account.support.store') }}" class="kd-form">
                @csrf
                <label><span>عنوان التذكرة</span><input name="subject" required></label>
                <label><span>الأولوية</span><select name="priority"><option value="normal">عادية</option><option value="high">مرتفعة</option><option value="low">منخفضة</option></select></label>
                <label><span>الرسالة</span><textarea name="message" rows="5" required></textarea></label>
                <button class="kd-primary" type="submit">إنشاء تذكرة</button>
            </form>
        </section>
    </div>
@endsection
