<?php $__env->startSection('title', 'Ticket #' . $ticket->id); ?>

<?php $__env->startSection('content'); ?>
<div class="max-w-[1100px] mx-auto">
    <div class="flex flex-col md:flex-row md:items-center justify-between gap-6 mb-10">
        <div class="flex items-center gap-4">
            <a href="<?php echo e(route('admin.support_tickets.index')); ?>" class="w-11 h-11 flex items-center justify-center bg-white border border-gray-100 rounded-2xl text-gray-400 hover:text-brand hover:border-brand/20 transition-all duration-300 shadow-sm group">
                <i class="fas fa-chevron-left text-xs group-hover:-translate-x-1 transition-transform"></i>
            </a>
            <div>
                <h1 class="text-2xl font-bold text-gray-900 leading-tight">
                    Ticket #<?php echo e(str_pad($ticket->id, 4, '0', STR_PAD_LEFT)); ?>

                </h1>
                <p class="text-sm text-gray-500 mt-1">
                    <?php echo e($ticket->subject); ?>

                </p>
            </div>
        </div>
        <div class="flex items-center gap-3">
            <form method="POST" action="<?php echo e(route('admin.support_tickets.update_status', $ticket->id)); ?>" class="flex items-center gap-2">
                <?php echo csrf_field(); ?>
                <select 
                    name="status"
                    onchange="this.form.submit()"
                    class="px-3 py-2.5 rounded-xl border border-gray-200 text-xs text-gray-700 bg-white focus:outline-none focus:ring-2 focus:ring-brand/20 focus:border-brand/40"
                >
                    <option value="open" <?php echo e($ticket->status === 'open' ? 'selected' : ''); ?>>Open</option>
                    <option value="pending" <?php echo e($ticket->status === 'pending' ? 'selected' : ''); ?>>Pending</option>
                    <option value="closed" <?php echo e($ticket->status === 'closed' ? 'selected' : ''); ?>>Closed</option>
                </select>
            </form>
        </div>
    </div>

    <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
        <div class="lg:col-span-2 space-y-6">
            <div class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden">
                <div class="px-6 py-4 border-b border-gray-50 flex items-center justify-between">
                    <div>
                        <p class="text-xs font-semibold text-gray-500 uppercase tracking-[0.2em]">Conversation</p>
                        <p class="text-xs text-gray-400 mt-1">
                            Started <?php echo e($ticket->created_at->format('d M Y H:i')); ?>

                        </p>
                    </div>
                </div>
                <div class="p-6 space-y-4 max-h-[520px] overflow-y-auto">
                    <?php $__empty_1 = true; $__currentLoopData = $ticket->messages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $message): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <div class="flex <?php echo e($message->is_admin ? 'justify-end' : 'justify-start'); ?>">
                            <div class="max-w-[80%]">
                                <div class="flex items-center gap-2 mb-1">
                                    <span class="text-[11px] font-semibold text-gray-500">
                                        <?php echo e($message->is_admin ? 'Admin' : ($message->user->name ?? 'Customer')); ?>

                                    </span>
                                    <span class="text-[10px] text-gray-400">
                                        <?php echo e($message->created_at->format('d M, H:i')); ?>

                                    </span>
                                </div>
                                <div class="rounded-2xl px-4 py-3 text-sm leading-relaxed <?php echo e($message->is_admin ? 'bg-emerald-600 text-white rounded-br-sm' : 'bg-gray-50 text-gray-800 rounded-bl-sm'); ?>">
                                    <?php echo e($message->message); ?>

                                </div>
                            </div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <p class="text-sm text-gray-500">No messages yet. Use the form below to reply to this ticket.</p>
                    <?php endif; ?>
                </div>
            </div>

            <div class="bg-white rounded-2xl border border-gray-100 shadow-sm">
                <div class="px-6 py-4 border-b border-gray-50">
                    <p class="text-xs font-semibold text-gray-500 uppercase tracking-[0.2em]">Reply</p>
                </div>
                <form method="POST" action="<?php echo e(route('admin.support_tickets.reply', $ticket->id)); ?>" class="p-6 space-y-4">
                    <?php echo csrf_field(); ?>
                    <div>
                        <textarea
                            name="message"
                            rows="4"
                            class="w-full rounded-2xl border border-gray-200 text-sm px-4 py-3 focus:outline-none focus:ring-2 focus:ring-brand/20 focus:border-brand/40"
                            placeholder="Write a clear and helpful response to the customer..."
                        ><?php echo e(old('message')); ?></textarea>
                        <?php $__errorArgs = ['message'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <p class="text-xs text-red-500 mt-1"><?php echo e($message); ?></p>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>
                    <div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3">
                        <div class="flex items-center gap-2 text-xs text-gray-400">
                            <span class="w-2 h-2 rounded-full bg-emerald-500 animate-pulse"></span>
                            Replies are sent instantly to the customer app and web.
                        </div>
                        <div class="flex items-center gap-2">
                            <select 
                                name="status"
                                class="px-3 py-2 rounded-xl border border-gray-200 text-xs text-gray-700 bg-white focus:outline-none focus:ring-2 focus:ring-brand/20 focus:border-brand/40"
                            >
                                <option value="">Keep status</option>
                                <option value="open">Mark as Open</option>
                                <option value="pending">Mark as Pending</option>
                                <option value="closed">Mark as Closed</option>
                            </select>
                            <button
                                type="submit"
                                class="inline-flex items-center gap-2 px-5 py-2.5 rounded-xl text-xs font-semibold text-white bg-zinc-900 hover:bg-black shadow-sm"
                            >
                                Send Reply
                                <i class="fas fa-paper-plane text-[10px]"></i>
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <div class="space-y-6">
            <div class="bg-white rounded-2xl border border-gray-100 shadow-sm">
                <div class="px-6 py-4 border-b border-gray-50">
                    <p class="text-xs font-semibold text-gray-500 uppercase tracking-[0.2em]">Customer</p>
                </div>
                <div class="p-6 space-y-4">
                    <div class="flex items-center gap-3">
                        <div class="w-10 h-10 rounded-2xl bg-emerald-50 flex items-center justify-center text-emerald-600 text-sm font-bold">
                            <?php echo e(substr($ticket->user->name ?? 'G', 0, 1)); ?>

                        </div>
                        <div>
                            <p class="text-sm font-semibold text-gray-900"><?php echo e($ticket->user->name ?? 'Guest'); ?></p>
                            <p class="text-xs text-gray-500"><?php echo e($ticket->user->email ?? 'No email'); ?></p>
                        </div>
                    </div>
                    <div class="space-y-3 text-xs text-gray-500">
                        <?php if($ticket->user && $ticket->user->phone): ?>
                            <div class="flex items-center gap-2">
                                <i class="fas fa-phone text-[10px] text-gray-400"></i>
                                <a href="tel:<?php echo e($ticket->user->phone); ?>" class="hover:text-brand">
                                    <?php echo e($ticket->user->phone); ?>

                                </a>
                            </div>
                        <?php endif; ?>
                        <div class="flex items-center gap-2">
                            <i class="fas fa-clock text-[10px] text-gray-400"></i>
                            <span>Customer since <?php echo e(optional($ticket->user)->created_at?->format('d M Y')); ?></span>
                        </div>
                    </div>
                    <?php if($ticket->user): ?>
                        <div class="pt-3 border-t border-gray-50">
                            <a 
                                href="<?php echo e(route('admin.customers.show', $ticket->user->id)); ?>"
                                class="inline-flex items-center justify-center gap-2 w-full px-4 py-2.5 rounded-xl border border-gray-200 text-xs font-semibold text-gray-700 hover:bg-gray-50"
                            >
                                View customer profile
                            </a>
                        </div>
                    <?php endif; ?>
                </div>
            </div>

            <?php if($ticket->order): ?>
                <div class="bg-white rounded-2xl border border-gray-100 shadow-sm">
                    <div class="px-6 py-4 border-b border-gray-50">
                        <p class="text-xs font-semibold text-gray-500 uppercase tracking-[0.2em]">Linked Order</p>
                    </div>
                    <div class="p-6 space-y-3 text-sm text-gray-700">
                        <div class="flex items-center justify-between">
                            <span class="text-gray-500 text-xs">Order</span>
                            <a 
                                href="<?php echo e(route('admin.orders.show', $ticket->order->id)); ?>"
                                class="text-xs font-semibold text-brand hover:text-brand/80"
                            >
                                #<?php echo e($ticket->order->order_number ?? $ticket->order->id); ?>

                            </a>
                        </div>
                        <div class="flex items-center justify-between text-xs text-gray-500">
                            <span>Date</span>
                            <span><?php echo e($ticket->order->created_at->format('d M Y, H:i')); ?></span>
                        </div>
                        <div class="flex items-center justify-between text-xs text-gray-500">
                            <span>Status</span>
                            <span class="font-semibold text-gray-800"><?php echo e(ucfirst($ticket->order->status)); ?></span>
                        </div>
                        <div class="flex items-center justify-between text-xs text-gray-500">
                            <span>Total</span>
                            <span class="font-semibold text-gray-900">
                                <?php echo e($currencySymbol ?? '$'); ?><?php echo e(number_format($ticket->order->total, 2)); ?>

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


<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/burhjijr/adminprovendorx.burhanstore.online/resources/views/admin/support_tickets/show.blade.php ENDPATH**/ ?>