<div class="table-scroller">
    <table class="table ticket-table">
        <thead>
            <tr>
                <th class="ticket-col"><?php echo app('translator')->get('Ticket'); ?></th>
                <th class="requester-col"><?php echo app('translator')->get('Requester'); ?></th>
                <th class="status-col"><?php echo app('translator')->get('Status'); ?></th>
                <th class="last-message-col"><?php echo app('translator')->get('Last Message'); ?></th>
                <th class="action-col"></th>
            </tr>
        </thead>
        <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $supportTickets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $index => $ticket): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr data-ticket="<?php echo e($ticket->ticket_number); ?>" class="ticketDetails
                    <?php if($ticket->ticketStatus->is_awaiting  && $ticket->assign_staff_id > 0): ?> assign_ticket <?php elseif($ticket->ticketStatus->is_awaiting): ?> awaiting_ticket <?php endif; ?>"
                    >
                    <td class="ticket-col">
                        <div class="ticket-board">
                            <div class="ticket-board-content">
                                <p class="ticket-board-title">
                                    <span class="animated-circle priorityName" data-hsl_color="<?php echo e(json_encode($ticket->priority->converted_color)); ?>">
                                    </span>
                                    <?php echo e(__($ticket->subject)); ?>

                                </p>
                                <div class="ticket-board-list">
                                    <p class="ticket-board-type">
                                        <?php echo e(__($ticket->department?->name)); ?>

                                    </p>
                                    <p class="ticket-board-id fw-bold">
                                        #<?php echo e($ticket->ticket_number); ?>

                                    </p>
                                    <?php if($ticket->admin): ?>
                                        <a href="<?php echo e(route('admin.agent.overview', $ticket->admin->id)); ?>" class="ticket-board-assign text--base">
                                            <i class="fa fa-user-check"></i>
                                            <?php echo e($ticket->admin->name); ?>

                                        </a>
                                    <?php endif; ?>

                                    <?php if(count($ticket->tags)): ?>
                                        <div class="ticket-board-tags">
                                            <?php $__currentLoopData = $ticket->tags; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $tag): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <span class="tag-style tagStyle" data-converted_color="<?php echo e(json_encode($tag->converted_color)); ?>"><?php echo e(__($tag->name)); ?></span>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td class="requester-col">
                        <div class="mini-profile">
                            <div class="mini-profile-img">
                                <img src="<?php echo e(getImage(getFilePath('userProfile') . '/' . $ticket->user->image, avatar: true)); ?>" alt="image">
                            </div>
                            <div class="mini-profile-content">
                                <a href="<?php echo e(route('admin.customer.overview', $ticket->user_id)); ?>" class="name"><?php echo e($ticket->user->fullname); ?></a>
                                <p class="email"><?php echo e($ticket->user->email); ?></p>
                            </div>
                        </div>
                    </td>
                    <td class="status-col">
                        <span class="badge statusName" data-ticket_number="<?php echo e($ticket->ticket_number); ?>" data-hsl_color="<?php echo e(json_encode($ticket->ticketStatus->converted_color)); ?>"><?php echo e(__($ticket->ticketStatus->name)); ?></span>
                    </td>
                    <td class="last-message-col">

                        <?php
                            $lastReply = $ticket->replies->last();
                        ?>

                        <?php if($lastReply): ?>
                            <?php echo e(diffForHumans($lastReply->created_at)); ?>

                        <?php else: ?>
                            ----
                        <?php endif; ?>

                    </td>
                    <td class="action-col">
                        <div class="dropdown ticket-dropdown">
                            <button class="ticket-dropdown-btn" data-bs-toggle="dropdown" aria-expanded="false" data-bs-auto-close="outside">
                                <i class="fa fa-ellipsis-v"></i>
                            </button>
                            <div class="dropdown-menu ticket-dropdown-body">
                                <div class="dropdown-menu-block">
                                    <div class="accordion ticket-accordion ticketParent" id="ticket-parent<?php echo e($index); ?>" data-ticket="<?php echo e($ticket->id); ?>">
                                        <div class="accordion-item">
                                            <h2 class="accordion-header">
                                                <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#ticket-actions" aria-expanded="true" aria-controls="ticket-actions">
                                                    <?php echo app('translator')->get('Set Priority'); ?>
                                                </button>
                                            </h2>
                                            <div id="ticket-actions" class="accordion-collapse collapse show" data-bs-parent="#ticket-parent<?php echo e($index); ?>">
                                                <div class="accordion-body">
                                                    <?php $__currentLoopData = $priorities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $priority): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <div class="ticket-dropdown-item">
                                                            <span class="animated-circle" data-hsl_color="<?php echo e(json_encode($priority->converted_color)); ?>"></span>
                                                            <p class="title updateTicket" data-priority="<?php echo e($priority->id); ?>">
                                                                <?php echo e(__($priority->name)); ?></p>
                                                        </div>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="accordion-item">
                                            <h2 class="accordion-header">
                                                <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#ticket-status" aria-expanded="false" aria-controls="ticket-status">
                                                    <?php echo app('translator')->get('Set Status'); ?>
                                                </button>
                                            </h2>
                                            <div id="ticket-status" class="accordion-collapse collapse" data-bs-parent="#ticket-parent<?php echo e($index); ?>">
                                                <div class="accordion-body">
                                                    <?php $__currentLoopData = $statuses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        <div class="ticket-dropdown-item">
                                                            <p class="title statusColor updateTicket" data-status="<?php echo e($status->id); ?>" data-color="<?php echo e($status->color); ?>">
                                                                <?php echo e(__($status->name)); ?></p>
                                                        </div>
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="accordion-item">
                                            <h2 class="accordion-header">
                                                <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#ticket-folders" aria-expanded="false" aria-controls="ticket-folders">
                                                    <?php echo app('translator')->get('Folders'); ?>
                                                </button>
                                            </h2>
                                            <div id="ticket-folders" class="accordion-collapse collapse" data-bs-parent="#ticket-parent<?php echo e($index); ?>">
                                                <div class="accordion-body">
                                                    <?php if(in_array(request()->folder, ['draft', 'spam', 'trash'])): ?>
                                                        <div class="ticket-dropdown-item">
                                                            <p class="title updateTicket" data-folder="<?php echo e(Status::TICKET_PRIMARY); ?>">
                                                                <?php echo app('translator')->get('Move to Primary'); ?></p>
                                                        </div>
                                                    <?php endif; ?>
                                                    <?php if(request()->folder != 'draft'): ?>
                                                        <div class="ticket-dropdown-item">
                                                            <p class="title updateTicket" data-folder="<?php echo e(Status::TICKET_DRAFT); ?>">
                                                                <?php echo app('translator')->get('Move to Draft'); ?></p>
                                                        </div>
                                                    <?php endif; ?>
                                                    <?php if(request()->folder != 'spam'): ?>
                                                        <div class="ticket-dropdown-item">
                                                            <p class="title updateTicket" data-folder="<?php echo e(Status::TICKET_SPAM); ?>">
                                                                <?php echo app('translator')->get('Move to Spam'); ?></p>
                                                        </div>
                                                    <?php endif; ?>
                                                    <?php if(request()->folder != 'trash'): ?>
                                                        <div class="ticket-dropdown-item">
                                                            <p class="title updateTicket" data-folder="<?php echo e(Status::TICKET_TRASH); ?>">
                                                                <?php echo app('translator')->get('Move to Trash'); ?></p>
                                                        </div>
                                                    <?php endif; ?>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </td>
                </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr>
                    <td colspan="100%">
                        <?php if (isset($component)) { $__componentOriginal785b8965d65806a202a14875024d2012 = $component; } ?>
<?php if (isset($attributes)) { $__attributesOriginal785b8965d65806a202a14875024d2012 = $attributes; } ?>
<?php $component = Illuminate\View\AnonymousComponent::resolve(['view' => 'components.empty-message','data' => ['message' => 'No ticket found']] + (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag ? $attributes->all() : [])); ?>
<?php $component->withName('empty-message'); ?>
<?php if ($component->shouldRender()): ?>
<?php $__env->startComponent($component->resolveView(), $component->data()); ?>
<?php if (isset($attributes) && $attributes instanceof Illuminate\View\ComponentAttributeBag): ?>
<?php $attributes = $attributes->except(\Illuminate\View\AnonymousComponent::ignoredParameterNames()); ?>
<?php endif; ?>
<?php $component->withAttributes(['message' => 'No ticket found']); ?>
<?php echo $__env->renderComponent(); ?>
<?php endif; ?>
<?php if (isset($__attributesOriginal785b8965d65806a202a14875024d2012)): ?>
<?php $attributes = $__attributesOriginal785b8965d65806a202a14875024d2012; ?>
<?php unset($__attributesOriginal785b8965d65806a202a14875024d2012); ?>
<?php endif; ?>
<?php if (isset($__componentOriginal785b8965d65806a202a14875024d2012)): ?>
<?php $component = $__componentOriginal785b8965d65806a202a14875024d2012; ?>
<?php unset($__componentOriginal785b8965d65806a202a14875024d2012); ?>
<?php endif; ?>
                    </td>
                </tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>

<?php if($supportTickets->hasPages()): ?>
    <div class="pagination-wrapper">
        <?php echo e(paginateLinks($supportTickets)); ?>

    </div>
<?php endif; ?>

<div id="confirmationModal" class="modal custom--modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title"><?php echo app('translator')->get('Confirmation Alert!'); ?></h5>
                <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                    <i class="las la-times"></i>
                </button>
            </div>
            <form method="POST" class="confirmationForm">
                <?php echo csrf_field(); ?>
                <input type="hidden" name="list_page" value="1">
                <div class="modal-body">
                    <p class="question"></p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn--dark btn--sm" data-bs-dismiss="modal"><?php echo app('translator')->get('No'); ?></button>
                    <button type="submit" class="btn btn--primary btn--sm" data-bs-dismiss="modal"><?php echo app('translator')->get('Yes'); ?></button>
                </div>
            </form>
        </div>
    </div>
</div>


<?php $__env->startPush('script'); ?>
    <script>
        (function($) {
            "use strict";
            $('.animated-circle[data-hsl_color]').each(function() {
                const jsonString = $(this).attr('data-hsl_color');
                try {
                    const hsl = JSON.parse(jsonString);
                    const hslString = `${hsl.h} ${hsl.s}% ${hsl.l}%`;
                    $(this).css('--circle-color', hslString);
                } catch (e) {
                    console.error('Invalid HSL data:', jsonString);
                }
            });

            $('.statusColor').each(function() {
                let color = $(this).data('color');
                $(this).css('color', '#' + color);
            });

            $('.updateTicket').on('click', function() {
                let modal = $('#confirmationModal');
                let action = `<?php echo e(route('admin.ticket.update', '')); ?>`;

                let priority = $(this).data('priority');
                let status = $(this).data('status');
                let folder = $(this).data('folder');

                let ticketId = $(this).closest('.ticketParent').data('ticket');

                let question = '';
                if (priority) {
                    question = `<?php echo app('translator')->get('Are you sure to change priority to'); ?> <b>${$(this).text().trim()}</b>?`;
                } else if (status) {
                    question = `<?php echo app('translator')->get('Are you sure to change status to'); ?> <b>${$(this).text().trim()}</b>?`;
                } else if (folder) {
                    let lastWord = $(this).text().trim().split(' ').pop();
                    question = `<?php echo app('translator')->get('Are you sure to move ticket to'); ?> <b>${lastWord}</b>?`;
                }

                modal.find('form').attr('action', action + '/' + ticketId);
                modal.find('form').find('input[name="priority"]').remove();
                modal.find('form').find('input[name="status"]').remove();
                modal.find('form').find('input[name="folder"]').remove();

                if (priority) {
                    modal.find('form').append(`<input type="hidden" name="priority" value="${priority}">`);
                }
                if (status) {
                    modal.find('form').append(`<input type="hidden" name="status" value="${status}">`);
                }
                if (folder) {
                    modal.find('form').append(`<input type="hidden" name="folder" value="${folder}">`);
                }

                modal.find('.question').html(question);
                modal.modal('show');
            });

            $('.confirmationForm').on('submit', function(e) {
                e.preventDefault();
                var form = $(this);
                var action = form.attr('action');
                var data = form.serialize();

                $.ajax({
                    url: action,
                    method: 'POST',
                    data: data,
                    success: function(response) {
                        if (response.status === 'error') {
                            notify('error', response.message);
                            return;
                        }
                        notify('success', response.message);

                        if (response.data && response.data.status) {
                            const tickerNumber = response.data.ticket.ticket_number;
                            const hslColor = response.data.status.converted_color;
                            const $badge = $(`.statusName[data-ticket_number="${tickerNumber}"]`);
                            $badge.text(response.data.status.name);
                            $badge.attr('data-hsl_color', JSON.stringify(hslColor));
                            const hslString = `${hslColor.h} ${hslColor.s}% ${hslColor.l}%`;
                            $badge.css('--badge-color', hslString);
                        }

                        if (response.data && response.data.folder) {
                            const tickerNumber = response.data.ticket.ticket_number;
                            const $badge = $(`.statusName[data-ticket_number="${tickerNumber}"]`);
                            $badge.closest('tr').remove();
                        }
                    }
                });
            });

            let route = `<?php echo e(route('admin.ticket.details', '')); ?>`;

            $('.ticketDetails').on('click', function(e) {
                if ($(e.target).closest('.action-col').length) {
                    return;
                }
                let ticketNumber = $(this).data('ticket');
                window.location.href = route + '/' + ticketNumber;
            });

            $('.statusName').each(function() {
                const jsonString = $(this).attr('data-hsl_color');
                try {
                    const hsl = JSON.parse(jsonString);
                    const hslString = `${hsl.h} ${hsl.s}% ${hsl.l}%`;
                    $(this).css('--badge-color', hslString);
                } catch (e) {
                    console.error('Invalid HSL data:', jsonString);
                }
            });

            $('.tagStyle').each(function() {
                const jsonString = $(this).attr('data-converted_color');
                try {
                    const hsl = JSON.parse(jsonString);
                    const hslString = `${hsl.h} ${hsl.s}% ${hsl.l}%`;
                    $(this).css('--tag-color', hslString);
                } catch (e) {
                    console.error('Invalid HSL data:', jsonString);
                }
            });

            $('.listTable tr.awaiting_ticket').first().find('td').css('background-color', 'hsl(var(--danger) / .1) !important');
            $('.listTable tr.awaiting_ticket').eq(1).find('td').css('background-color', 'hsl(var(--danger) / 0.085) !important');
            $('.listTable tr.awaiting_ticket').eq(2).find('td').css('background-color', 'hsl(var(--danger) / 0.07) !important');
            $('.listTable tr.awaiting_ticket').eq(3).find('td').css('background-color', 'hsl(var(--danger) / 0.05) !important');
            
        })(jQuery);
    </script>
<?php $__env->stopPush(); ?>
<?php /**PATH C:\laragon\www\projects\custom_viserdesk\Files\core\resources\views/admin/ticket/list_table.blade.php ENDPATH**/ ?>