<?php $__env->startSection('title'); ?><?php echo e($ticket->subject); ?><?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
<div class="container-xxl flex-grow-1 container-p-y">

    
    <div class="d-flex align-items-start justify-content-between mb-3 flex-wrap gap-2">
        <div class="d-flex align-items-center gap-3">
            <a href="<?php echo e(route('admin.tickets.index')); ?>" class="btn btn-icon btn-outline-secondary btn-sm">
                <i class="ti ti-arrow-right"></i>
            </a>
            <div>
                <div class="d-flex align-items-center gap-2 mb-1">
                    <span class="badge bg-label-secondary font-monospace" dir="ltr"><?php echo e($ticket->name); ?></span>
                    <span class="badge bg-label-<?php echo e($ticket->statusColor()); ?>"><?php echo e($ticket->statusLabel()); ?></span>
                </div>
                <h5 class="mb-0"><?php echo e($ticket->subject); ?></h5>
                <small class="text-muted">
                    <?php echo e(optional($ticket->user)->first_name); ?> <?php echo e(optional($ticket->user)->last_name); ?>

                    &nbsp;·&nbsp; <span dir="ltr"><?php echo e(optional($ticket->user)->mobile); ?></span>
                    <?php if($ticket->department): ?>
                        &nbsp;·&nbsp; <?php echo e($ticket->department->name); ?>

                    <?php endif; ?>
                    <?php if($ticket->order): ?>
                        &nbsp;·&nbsp;
                        <a href="<?php echo e(route('admin.orders.show', $ticket->order->order_number)); ?>" dir="ltr">
                            سفارش <?php echo e($ticket->order->order_number); ?>

                        </a>
                    <?php endif; ?>
                </small>
            </div>
        </div>

        <div class="d-flex gap-2 align-items-start">
            
            <form action="<?php echo e(route('admin.tickets.status', $ticket->name)); ?>" method="POST" class="d-flex gap-2">
                <?php echo csrf_field(); ?>
                <select name="status" class="form-select form-select-sm" style="min-width:160px">
                    <?php $__currentLoopData = ['opened'=>'در انتظار پاسخ','replied'=>'پاسخ داده شده','user_replied'=>'پاسخ توسط مشتری','in_progress'=>'در حال بررسی','closed'=>'بسته شده']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $val=>$label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($val); ?>" <?php echo e($ticket->status === $val ? 'selected' : ''); ?>><?php echo e($label); ?></option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
                <button type="submit" class="btn btn-sm btn-outline-primary">اعمال</button>
            </form>

            <form action="<?php echo e(route('admin.tickets.delete', $ticket->name)); ?>" method="POST">
                <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                <button type="submit" class="btn btn-sm btn-outline-danger"
                    onclick="return confirm('تیکت حذف شود؟ این عمل برگشت‌پذیر نیست.')">
                    <i class="ti ti-trash ti-sm"></i>
                </button>
            </form>
        </div>
    </div>

    <?php if(session('success')): ?>
        <div class="alert alert-success alert-dismissible mb-3">
            <?php echo e(session('success')); ?>

            <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
        </div>
    <?php endif; ?>
    <?php if($errors->any()): ?>
        <div class="alert alert-danger mb-3">
            <ul class="mb-0"><?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $e): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><li><?php echo e($e); ?></li><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?></ul>
        </div>
    <?php endif; ?>

    <div class="card">
        <div class="card-body">
            
            <div class="d-flex flex-column gap-3 mb-4">
                <?php $__currentLoopData = $ticket->replies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $reply): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <?php $isAdmin = $reply->isAdmin(); ?>
                    <div class="d-flex <?php echo e($isAdmin ? 'justify-content-start' : 'justify-content-end'); ?>">
                        <div class="p-3 rounded-3 border <?php echo e($isAdmin ? 'bg-label-primary' : 'bg-light'); ?>" style="max-width:75%">
                            <div class="d-flex align-items-center gap-2 mb-2">
                                <span class="badge <?php echo e($isAdmin ? 'bg-primary' : 'bg-secondary'); ?>">
                                    <?php echo e($isAdmin ? 'پشتیبان' : (optional($ticket->user)->first_name . ' ' . optional($ticket->user)->last_name)); ?>

                                </span>
                                <small class="text-muted"><?php echo e($reply->shamsi_created); ?></small>
                            </div>
                            <div style="white-space:pre-wrap;line-height:2"><?php echo e($reply->message); ?></div>
                            <?php if($reply->attachment): ?>
                                <a href="<?php echo e(asset('uploads/tickets/' . $reply->attachment)); ?>" target="_blank"
                                   class="d-inline-flex align-items-center gap-1 mt-2 small">
                                    <i class="ti ti-photo ti-xs"></i> مشاهده تصویر ضمیمه
                                </a>
                            <?php endif; ?>
                        </div>
                    </div>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </div>

            
            <hr>
            <h6 class="mb-3">ارسال پاسخ</h6>
            <form action="<?php echo e(route('admin.tickets.reply', $ticket->name)); ?>" method="POST" enctype="multipart/form-data">
                <?php echo csrf_field(); ?>
                <div class="mb-3">
                    <textarea name="message" rows="5" class="form-control"
                              placeholder="پاسخ خود را بنویسید..."><?php echo e(old('message')); ?></textarea>
                </div>
                <div class="mb-3">
                    <label class="form-label">تصویر ضمیمه (اختیاری)</label>
                    <input type="file" name="attachment" class="form-control" accept="image/*">
                    <div class="form-text">فقط تصویر: JPG، PNG، GIF، WebP — حداکثر ۵ مگابایت</div>
                </div>
                <button type="submit" class="btn btn-primary">
                    <i class="ti ti-send me-1"></i> ارسال پاسخ
                </button>
            </form>
        </div>
    </div>

</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layouts.layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/louishop/public_html/engine/resources/views/admin/tickets/show.blade.php ENDPATH**/ ?>