<?php $__env->startSection('title', 'Support Ticket | NEX Finserv Admin'); ?>

<?php $__env->startSection('page-title', 'Support Ticket'); ?>

<?php $__env->startSection('page-description', 'Client support conversation'); ?>

<?php $__env->startSection('content'); ?>

<?php $__env->startPush('styles'); ?>
<link rel="stylesheet" href="<?php echo e(asset('admin/css/support-show.css')); ?>">
<?php $__env->stopPush(); ?>

<div class="support-content">


    

    <a
        href="<?php echo e(route('admin.support.index')); ?>"
        class="back-link"
    >
        ← Back to Support
    </a>


    


    

    <div class="ticket-header">

        <div class="ticket-title-row">

            <div class="ticket-main-info">

                <div class="ticket-title">
                    <?php echo e($ticket->subject); ?>

                </div>

                <div class="ticket-client">

                    Client:
                    <strong>
                        <?php echo e($ticket->client->name ?? 'Unknown'); ?>

                    </strong>

                    <?php if($ticket->client): ?>

                        · <?php echo e($ticket->client->email); ?>


                    <?php endif; ?>

                </div>

            </div>


            

            <div>

                <?php if($ticket->status === 'pending'): ?>

                    <span class="status status-pending">

                        <span class="status-dot"></span>

                        Pending

                    </span>

                <?php elseif($ticket->status === 'in_progress'): ?>

                    <span class="status status-progress">

                        <span class="status-dot"></span>

                        In Progress

                    </span>

                <?php else: ?>

                    <span class="status status-closed">

                        <span class="status-dot"></span>

                        Closed

                    </span>

                <?php endif; ?>

            </div>

        </div>


        

        <div class="status-box">

            <form
                method="POST"
                action="<?php echo e(route('admin.support.status', $ticket)); ?>"
            >

                <?php echo csrf_field(); ?>
                <?php echo method_field('PATCH'); ?>

                <label>
                    Ticket Status
                </label>

                <select
                    name="status"
                    class="status-select"
                >

                    <option
                        value="pending"
                        <?php if($ticket->status === 'pending'): echo 'selected'; endif; ?>
                    >
                        Pending
                    </option>

                    <option
                        value="in_progress"
                        <?php if($ticket->status === 'in_progress'): echo 'selected'; endif; ?>
                    >
                        In Progress
                    </option>

                    <option
                        value="closed"
                        <?php if($ticket->status === 'closed'): echo 'selected'; endif; ?>
                    >
                        Closed
                    </option>

                </select>

                <button
                    type="submit"
                    class="status-btn"
                >
                    Update Status
                </button>

            </form>

        </div>

    </div>


    

    <div class="chat-card">


        

        <div class="chat-header">

            <div class="chat-header-left">

                <div class="chat-header-icon">

                    <svg
                        width="16"
                        height="16"
                        viewBox="0 0 24 24"
                        fill="none"
                        stroke="currentColor"
                        stroke-width="2"
                    >
                        <path d="M20 11.5a7.5 7.5 0 0 1-7.5 7.5H7l-4 2v-4.5A7.5 7.5 0 1 1 20 11.5Z"/>
                    </svg>

                </div>

                <div>

                    <div class="chat-header-title">
                        Conversation
                    </div>

                    <div class="chat-header-sub">
                        Client support messages
                    </div>

                </div>

            </div>


            <span class="online-dot"></span>

        </div>


        

        <div
            class="chat-body"
            id="chatBody"
        >

            <?php $__empty_1 = true; $__currentLoopData = $ticket->messages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $message): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>

                <?php

                    $isAdmin =
                        $message->user_id === auth()->id();

                    $clientName =
                        $ticket->client->name ?? 'Client';

                ?>


                <div
                    class="message-row <?php echo e($isAdmin ? 'admin' : 'client'); ?>"
                >

                    <div class="message-wrap">


                        

                        <div
                            class="message-avatar <?php echo e($isAdmin ? 'admin' : 'client'); ?>"
                        >

                            <?php if($isAdmin): ?>

                                A

                            <?php else: ?>

                                <?php echo e(strtoupper(substr($clientName, 0, 1))); ?>


                            <?php endif; ?>

                        </div>


                        

                        <div
                            class="message <?php echo e($isAdmin ? 'admin' : 'client'); ?>"
                        >


                            <div class="message-user">

                                <?php if($isAdmin): ?>

                                    Admin

                                <?php else: ?>

                                    <?php echo e($clientName); ?>


                                <?php endif; ?>

                            </div>


                            <div class="message-content">

                                <?php echo nl2br(e($message->message)); ?>


                            </div>


                            <div class="message-time">

                                <?php echo e($message->created_at
                                    ? $message->created_at->format('d M Y, h:i A')
                                    : ''); ?>


                            </div>


                        </div>

                    </div>

                </div>


            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>


                <div class="empty-chat">

                    <div class="empty-chat-icon">

                        <svg
                            width="21"
                            height="21"
                            viewBox="0 0 24 24"
                            fill="none"
                            stroke="currentColor"
                            stroke-width="2"
                        >

                            <path d="M20 11.5a7.5 7.5 0 0 1-7.5 7.5H7l-4 2v-4.5A7.5 7.5 0 1 1 20 11.5Z"/>

                            <path d="M8 11h.01"/>
                            <path d="M12 11h.01"/>
                            <path d="M16 11h.01"/>

                        </svg>

                    </div>


                    <strong>
                        No messages yet
                    </strong>

                    <span>
                        Start the conversation with the client.
                    </span>

                </div>


            <?php endif; ?>

        </div>


        

        <div class="reply-box">


            <?php if($ticket->status === 'closed'): ?>


                <div class="closed-notice">

                    This ticket is closed.
                    You cannot send a reply.

                </div>


            <?php else: ?>


                <form
                    method="POST"
                    action="<?php echo e(route('admin.support.message', $ticket)); ?>"
                    class="reply-form"
                    id="replyForm"
                >

                    <?php echo csrf_field(); ?>


                    <div class="reply-input-wrap">

                        <textarea
                            name="message"
                            id="replyMessage"
                            class="reply-textarea"
                            placeholder="Type your reply..."
                            required
                            maxlength="2000"
                            autocomplete="off"
                        ></textarea>

                    </div>


                    <button
                        type="submit"
                        class="send-btn"
                        id="sendBtn"
                    >

                        <svg
                            class="send-icon"
                            viewBox="0 0 24 24"
                            fill="none"
                            stroke="currentColor"
                            stroke-width="2"
                        >

                            <path d="M22 2L11 13"/>

                            <path d="M22 2L15 22L11 13L2 9L22 2Z"/>

                        </svg>

                        <span class="send-text">
                            Send
                        </span>

                    </button>

                </form>


            <?php endif; ?>


        </div>

    </div>

</div>

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


<?php $__env->startPush('scripts'); ?>

<script>

document.addEventListener(
    'DOMContentLoaded',
    function () {

        /*
        |--------------------------------------------------------------------------
        | Scroll chat to bottom
        |--------------------------------------------------------------------------
        */

        const chatBody =
            document.getElementById('chatBody');

        if (chatBody) {

            chatBody.scrollTop =
                chatBody.scrollHeight;

        }


        /*
        |--------------------------------------------------------------------------
        | Enter = Send
        | Shift + Enter = New Line
        |--------------------------------------------------------------------------
        */

        const textarea =
            document.getElementById('replyMessage');

        const form =
            document.getElementById('replyForm');

        if (textarea && form) {

            textarea.addEventListener(
                'keydown',
                function (event) {

                    if (
                        event.key === 'Enter' &&
                        !event.shiftKey
                    ) {

                        event.preventDefault();

                        if (
                            textarea.value.trim() !== ''
                        ) {

                            form.submit();

                        }

                    }

                }
            );

        }


        /*
        |--------------------------------------------------------------------------
        | Prevent double submit
        |--------------------------------------------------------------------------
        */

        if (form) {

            form.addEventListener(
                'submit',
                function () {

                    const button =
                        document.getElementById('sendBtn');

                    if (button) {

                        button.disabled = true;

                        button.style.opacity = '0.65';

                        button.style.cursor = 'not-allowed';

                    }

                }
            );

        }

    }
);

</script>

<?php $__env->stopPush(); ?>
<?php echo $__env->make('admin.layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\emi-card\resources\views/admin/support/show.blade.php ENDPATH**/ ?>