@extends('layouts.admin')

@section('title', 'Ticket #' . $ticket->id)

@section('content')
    <a href="{{ route('admin.tickets') }}" class="btn btn-outline-light mb-2">Back to tickets</a>
    <section class="user-page-card">
        <div class="d-flex flex-wrap justify-content-between gap-1 mb-2">
            <div><h1 class="loot-section-title mb-25">{{ $ticket->subject }}</h1><p class="loot-muted mb-0">{{ $ticket->user->username }} / {{ $ticket->category }} / {{ $ticket->priority }}</p></div>
            <span class="loot-status success">{{ ucfirst($ticket->status) }}</span>
        </div>
        <div class="ticket-thread">
            @foreach($ticket->messages as $message)
                <div class="ticket-message {{ $message->is_admin ? 'admin' : '' }}">
                    <strong>{{ $message->is_admin ? 'Admin' : $message->user->username }}</strong>
                    <p>{{ $message->message }}</p>
                    <small>{{ $message->created_at->diffForHumans() }}</small>
                </div>
            @endforeach
        </div>
        <form method="POST" action="{{ route('admin.tickets.reply', $ticket) }}" class="mt-2">
            @csrf
            <div class="row">
                <div class="col-md-3 mb-1">
                    <label class="form-label">Status</label>
                    <select name="status" class="form-select">
                        @foreach(['open', 'pending', 'closed'] as $status)<option value="{{ $status }}" @selected($ticket->status === $status)>{{ ucfirst($status) }}</option>@endforeach
                    </select>
                </div>
                <div class="col-md-9 mb-1">
                    <label class="form-label">Reply</label>
                    <textarea name="message" class="form-control" rows="3" required></textarea>
                </div>
            </div>
            <button class="btn btn-loot">Send reply</button>
        </form>
    </section>
@endsection
