@extends('layouts.account', ['title' => $ticket->ticket_number.' | RaseedNow'])

@section('account_content')
    <div class="kd-page-head has-action">
        <h1>{{ $ticket->subject }}</h1>
        <a class="kd-secondary" href="{{ route('account.tickets') }}">كل التذاكر</a>
    </div>

    <div class="kd-two-col">
        <section class="kd-card">
            <div class="kd-card-head"><h2>{{ $ticket->ticket_number }}</h2><p>{{ $ticket->status }} / {{ $ticket->priority }}</p></div>
            <div class="kd-list">
                @foreach($ticket->messages as $message)
                    <div @class(['kd-ticket-message', 'is-admin' => $message->sender_type === 'admin'])>
                        <div>
                            <strong>{{ $message->sender_type === 'admin' ? 'فريق الدعم' : ($message->sender?->display_name ?? $message->sender?->name ?? 'العميل') }}</strong>
                            <span>{{ $message->created_at->format('Y-m-d H:i') }}</span>
                        </div>
                        <p>{{ $message->body }}</p>
                    </div>
                @endforeach
            </div>
        </section>

        <section class="kd-card">
            <div class="kd-card-head"><h2>رد جديد</h2></div>
            <form method="POST" action="{{ route('account.support.reply', $ticket) }}" class="kd-form">
                @csrf
                <label>
                    <span>رسالتك</span>
                    <textarea name="message" rows="7" @disabled(in_array($ticket->status, ['resolved', 'closed'], true)) required></textarea>
                </label>
                <button class="kd-primary" type="submit" @disabled(in_array($ticket->status, ['resolved', 'closed'], true))>إرسال الرد</button>
            </form>
        </section>
    </div>
@endsection
