@extends('layouts.admin')

@section('title', 'مشاهده تیکت')

@section('content')
<div class="row clearfix">
    <!-- Ticket Info -->
    <div class="col-lg-4 col-md-12 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <h2>
                    اطلاعات تیکت #{{ $supportTicket->id }}
                </h2>
            </div>
            <div class="body">
                <ul class="list-group">
                    <li class="list-group-item">کاربر: {{ $supportTicket->user ? $supportTicket->user->full_name : 'حذف شده' }}</li>
                    <li class="list-group-item">ایمیل: {{ $supportTicket->user ? $supportTicket->user->email : '-' }}</li>
                    <li class="list-group-item">موضوع: {{ $supportTicket->subject }}</li>
                    <li class="list-group-item">دسته‌بندی: {{ $supportTicket->category }}</li>
                    <li class="list-group-item">تاریخ ایجاد: {{ $supportTicket->created_at->format('Y/m/d H:i') }}</li>
                </ul>

                <form action="{{ route('admin.support-tickets.update', $supportTicket->id) }}" method="POST" class="m-t-20">
                    @csrf
                    @method('PUT')
                    <div class="form-group">
                        <label>تغییر اولویت</label>
                        <select name="priority" class="form-control show-tick">
                            <option value="low" {{ $supportTicket->priority == 'low' ? 'selected' : '' }}>پایین</option>
                            <option value="medium" {{ $supportTicket->priority == 'medium' ? 'selected' : '' }}>متوسط</option>
                            <option value="high" {{ $supportTicket->priority == 'high' ? 'selected' : '' }}>بالا</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <label>تغییر وضعیت</label>
                        <select name="status" class="form-control show-tick">
                            <option value="open" {{ $supportTicket->status == 'open' ? 'selected' : '' }}>باز</option>
                            <option value="in_progress" {{ $supportTicket->status == 'in_progress' ? 'selected' : '' }}>در حال بررسی</option>
                            <option value="resolved" {{ $supportTicket->status == 'resolved' ? 'selected' : '' }}>حل شده</option>
                            <option value="closed" {{ $supportTicket->status == 'closed' ? 'selected' : '' }}>بسته شده</option>
                        </select>
                    </div>
                    <button type="submit" class="btn btn-primary waves-effect">بروزرسانی وضعیت</button>
                </form>
            </div>
        </div>
    </div>

    <!-- Messages -->
    <div class="col-lg-8 col-md-12 col-sm-12 col-xs-12">
        <div class="card">
            <div class="header">
                <h2>
                    گفتگو
                </h2>
            </div>
            <div class="body">
                <ul class="list-unstyled">
                    @foreach($supportTicket->messages as $message)
                    <li class="media m-b-20" style="border-bottom: 1px solid #eee; padding-bottom: 10px;">
                        <div class="media-body">
                            <h5 class="media-heading">
                                @if($message->is_admin_reply)
                                    <span class="text-primary">پشتیبان ({{ $message->admin ? $message->admin->full_name : 'Admin' }})</span>
                                @else
                                    <span class="text-success">کاربر</span>
                                @endif
                                <small class="pull-left text-muted">{{ $message->created_at->format('Y/m/d H:i') }}</small>
                            </h5>
                            <p>
                                {!! nl2br(e($message->message)) !!}
                            </p>
                        </div>
                    </li>
                    @endforeach
                </ul>

                <hr>

                <!-- Reply Form -->
                <h4>ارسال پاسخ</h4>
                <form action="{{ route('admin.support-tickets.update', $supportTicket->id) }}" method="POST">
                    @csrf
                    @method('PUT')
                    <div class="form-group">
                        <div class="form-line">
                            <textarea name="message" rows="4" class="form-control no-resize" placeholder="پاسخ خود را بنویسید..." required></textarea>
                        </div>
                    </div>
                    <button type="submit" class="btn btn-primary waves-effect">ارسال پاسخ</button>
                </form>
            </div>
        </div>
    </div>
</div>
@endsection
