
<?php
$statusConfig = [
    'Pickup Requested' => ['bg'=>'bg-purple-100','text'=>'text-purple-800','dot'=>'bg-purple-400','border'=>'border-purple-200','bar'=>'bg-purple-400'],
    'Pending'   => ['bg'=>'bg-yellow-100','text'=>'text-yellow-800','dot'=>'bg-yellow-400','border'=>'border-yellow-200','bar'=>'bg-yellow-400'],
    'Checking'  => ['bg'=>'bg-sky-100',   'text'=>'text-sky-800',   'dot'=>'bg-sky-400',   'border'=>'border-sky-200',   'bar'=>'bg-sky-400'],
    'Repairing' => ['bg'=>'bg-blue-100',  'text'=>'text-blue-800',  'dot'=>'bg-blue-400',  'border'=>'border-blue-200',  'bar'=>'bg-blue-400'],
    'Ready'     => ['bg'=>'bg-green-100', 'text'=>'text-green-800', 'dot'=>'bg-green-400', 'border'=>'border-green-200', 'bar'=>'bg-green-400'],
    'Picked Up' => ['bg'=>'bg-gray-100',  'text'=>'text-gray-700',  'dot'=>'bg-gray-400',  'border'=>'border-gray-200',  'bar'=>'bg-gray-400'],
    'Cancelled' => ['bg'=>'bg-red-100',   'text'=>'text-red-800',   'dot'=>'bg-red-400',   'border'=>'border-red-200',   'bar'=>'bg-red-400'],
];
$nextStatuses = [
    'Pending'   => 'Checking',
    'Checking'  => 'Repairing',
    'Repairing' => 'Ready',
    // 'Ready' → 'Picked Up' hanya boleh lewat form serah terima + invoice issued
];

$invoiceStatusLabel = [
    'draft'     => ['label' => 'Draft',    'cls' => 'bg-amber-50 text-amber-700 border-amber-200'],
    'review'    => ['label' => 'Review',   'cls' => 'bg-indigo-50 text-indigo-700 border-indigo-200'],
    'issued'    => ['label' => 'Issued',   'cls' => 'bg-emerald-50 text-emerald-700 border-emerald-200'],
    'cancelled' => ['label' => 'Batal',    'cls' => 'bg-red-50 text-red-600 border-red-200'],
];

$formatMinutes = function (?int $minutes): string {
    if ($minutes === null) {
        return '-';
    }

    if ($minutes < 60) {
        return $minutes . 'm';
    }

    $hours = intdiv($minutes, 60);
    $remain = $minutes % 60;

    return $hours . 'j ' . $remain . 'm';
};
?>

<?php if($tickets->isEmpty()): ?>

<div class="rounded-2xl bg-white border border-gray-100 shadow-sm flex flex-col items-center
            justify-center py-20 text-center px-4">
    <svg class="w-14 h-14 text-gray-200 mb-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5"
              d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414
                 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
    </svg>
    <p class="text-gray-500 font-medium">Tidak ada tiket ditemukan</p>
    <p class="text-gray-400 text-sm mt-1">Coba ubah filter atau kata kunci pencarian</p>
</div>

<?php else: ?>


<div class="md:hidden space-y-3">
    <?php $__currentLoopData = $tickets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ticket): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
    <?php
        $cfg     = $statusConfig[$ticket->status] ?? ['bg'=>'bg-gray-100','text'=>'text-gray-700','dot'=>'bg-gray-400','border'=>'border-gray-200','bar'=>'bg-gray-400'];
        $isFinal = in_array($ticket->status, ['Cancelled','Picked Up']);
        $next    = $nextStatuses[$ticket->status] ?? null;
        $canApproveRepair = in_array($ticket->status, ['Pending', 'Checking'], true) && ! $ticket->repair_approved_at;
        if ($ticket->status === 'Checking' && ! $ticket->repair_approved_at) {
            $next = null;
        }
        // Invoice status untuk gate serah terima & tombol
        $activeInvoice   = $ticket->invoices->whereNotIn('status', ['cancelled'])->first();
        $hasIssuedInvoice = $ticket->invoices->contains('status', 'issued');
        $invStatusInfo   = $activeInvoice ? ($invoiceStatusLabel[$activeInvoice->status] ?? null) : null;
    ?>
    <div class="bg-white rounded-2xl border <?php echo e($cfg['border']); ?> shadow-sm overflow-hidden">

        
        <div class="h-1.5 <?php echo e($cfg['bar']); ?>"></div>

        <div class="p-4 space-y-3">

            
            <div class="flex items-start justify-between gap-2">
                <div>
                    <p class="font-mono font-bold text-brand-600 text-base tracking-wide">
                        <?php echo e($ticket->ticket_code); ?>

                    </p>
                    <span class="inline-flex items-center gap-1.5 mt-1.5 px-2.5 py-1 rounded-full
                                 text-xs font-semibold <?php echo e($cfg['bg']); ?> <?php echo e($cfg['text']); ?>">
                        <span class="w-1.5 h-1.5 rounded-full <?php echo e($cfg['dot']); ?>"></span>
                        <?php echo e($ticket->status); ?>

                    </span>
                </div>
                <div class="text-right text-xs text-gray-400 flex-shrink-0 pt-0.5">
                    <p><?php echo e($ticket->created_at->format('d M Y')); ?></p>
                    <p><?php echo e($ticket->created_at->format('H:i')); ?></p>
                </div>
            </div>

            
            <div class="grid grid-cols-2 gap-3 border-t border-gray-50 pt-3 text-sm">
                <div class="min-w-0">
                    <p class="text-[10px] font-semibold text-gray-400 uppercase tracking-wider mb-0.5">
                        Pelanggan
                    </p>
                    <p class="font-semibold text-gray-800 truncate"><?php echo e($ticket->customer->name); ?></p>
                    <?php if($ticket->customer->whatsapp): ?>
                    <p class="text-xs text-gray-400 truncate"><?php echo e($ticket->customer->whatsapp); ?></p>
                    <?php endif; ?>
                </div>
                <div class="min-w-0">
                    <p class="text-[10px] font-semibold text-gray-400 uppercase tracking-wider mb-0.5">
                        Perangkat
                    </p>
                    <p class="font-medium text-gray-800 truncate"><?php echo e($ticket->brand ? $ticket->brand.' '.$ticket->model : '—'); ?></p>
                    <p class="text-xs text-gray-400"><?php echo e($ticket->device_type ?? 'Belum diisi'); ?></p>
                </div>
            </div>

            
            <?php if($ticket->status === 'Cancelled' && $ticket->cancel_reason): ?>
            <div class="rounded-lg bg-red-50 border border-red-100 px-3 py-2 text-xs text-red-700">
                <span class="font-semibold">Alasan: </span><?php echo e($ticket->cancel_reason); ?>

            </div>
            <?php endif; ?>

            <?php if($ticket->repair_approved_at): ?>
            <div class="rounded-lg bg-emerald-50 border border-emerald-100 px-3 py-2 text-xs text-emerald-700">
                <span class="font-semibold">Approval Perbaikan:</span>
                <?php echo e($ticket->repair_approved_at->format('d M Y H:i')); ?>

            </div>
            <?php endif; ?>

            <div class="rounded-lg bg-sky-50 border border-sky-100 px-3 py-2 text-xs text-sky-700">
                <p><span class="font-semibold">Diagnosa:</span> <?php echo e($ticket->initial_diagnosis ? \Illuminate\Support\Str::limit($ticket->initial_diagnosis, 90) : 'Belum diisi'); ?></p>
                <p class="mt-1"><span class="font-semibold">Rekomendasi:</span> <?php echo e($ticket->recommended_action ? \Illuminate\Support\Str::limit($ticket->recommended_action, 90) : 'Belum diisi'); ?></p>
            </div>

            <div class="rounded-lg bg-emerald-50 border border-emerald-100 px-3 py-2 text-xs text-emerald-700">
                <p><span class="font-semibold">Final QC:</span> <?php echo e($ticket->final_check_notes ? \Illuminate\Support\Str::limit($ticket->final_check_notes, 90) : 'Belum diisi'); ?></p>
                <?php if(!empty($ticket->final_check_items)): ?>
                <p class="mt-1"><span class="font-semibold">Checklist PASS:</span> <?php echo e(count($ticket->final_check_items)); ?> item</p>
                <?php endif; ?>
            </div>

            <div class="rounded-lg bg-indigo-50 border border-indigo-100 px-3 py-2 text-[11px] text-indigo-700">
                <p class="font-semibold mb-1">SLA Monitor</p>
                <p>Diagnosa → Approval: <?php echo e($formatMinutes($ticket->sla['diag_to_approval'] ?? null)); ?></p>
                <p>Approval → Final QC: <?php echo e($formatMinutes($ticket->sla['approval_to_qc'] ?? null)); ?></p>
                <p>Final QC → Ready: <?php echo e($formatMinutes($ticket->sla['qc_to_ready'] ?? null)); ?></p>
                <p class="font-semibold mt-1">Diagnosa → Ready: <?php echo e($formatMinutes($ticket->sla['diag_to_ready'] ?? null)); ?></p>
            </div>

            
            <div class="border-t border-gray-50 pt-3 space-y-2">

                
                <?php if($ticket->status === 'Ready'): ?>
                    <a href="<?php echo e(route('handover.show', $ticket->id)); ?>"
                       class="flex items-center justify-center gap-2 w-full h-12 rounded-xl
                              bg-green-600 hover:bg-green-700 active:bg-green-800
                              text-white font-semibold text-sm transition shadow-sm">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                        </svg>
                        Serah Terima
                    </a>
                <?php elseif($next): ?>
                    <form method="POST" action="<?php echo e(route('admin.tickets.status', $ticket->id)); ?>">
                        <?php echo csrf_field(); ?> <?php echo method_field('PATCH'); ?>
                        <input type="hidden" name="status" value="<?php echo e($next); ?>">
                        <button type="submit"
                                class="flex items-center justify-center gap-2 w-full h-12 rounded-xl
                                       bg-brand-600 hover:bg-brand-700 active:bg-brand-800
                                       text-white font-semibold text-sm transition shadow-sm">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                      d="M9 5l7 7-7 7"/>
                            </svg>
                            Tandai: <?php echo e($next); ?>

                        </button>
                    </form>
                <?php endif; ?>

                <?php if($canApproveRepair): ?>
                    <form method="POST" action="<?php echo e(route('admin.tickets.approve-repair', $ticket->id)); ?>">
                        <?php echo csrf_field(); ?> <?php echo method_field('PATCH'); ?>
                        <button type="submit"
                                class="flex items-center justify-center gap-2 w-full h-11 rounded-xl
                                       bg-indigo-600 hover:bg-indigo-700 active:bg-indigo-800
                                       text-white font-semibold text-sm transition shadow-sm">
                            Setujui Perbaikan
                        </button>
                    </form>
                <?php endif; ?>

                
                <div class="grid grid-cols-2 gap-2">

                    
                    <a href="<?php echo e(route('tickets.show', $ticket->id)); ?>"
                       class="flex items-center justify-center gap-1.5 h-11 rounded-xl
                              border border-gray-200 text-sm font-medium text-gray-700
                              hover:bg-gray-50 active:bg-gray-100 transition">
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                  d="M15 12a3 3 0 11-6 0 3 3 0 016 0zM2.458 12C3.732 7.943 7.523 5
                                     12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542
                                     7-4.477 0-8.268-2.943-9.542-7z"/>
                        </svg>
                        Detail
                    </a>

                    
                    <?php if(in_array($ticket->status, ['Ready', 'Cancelled']) && ! $hasIssuedInvoice): ?>
                        <a href="<?php echo e(route('admin.invoices.create', ['service_ticket_id' => $ticket->id])); ?>"
                           class="flex items-center justify-center gap-1.5 h-11 rounded-xl
                                  border border-emerald-200 text-sm font-medium text-emerald-700
                                  hover:bg-emerald-50 active:bg-emerald-100 transition">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                      d="M12 4v16m8-8H4"/>
                            </svg>
                            <?php echo e($ticket->status === 'Cancelled' ? 'Invoice Pembatalan' : 'Buat Invoice'); ?>

                        </a>
                    <?php elseif($activeInvoice && $invStatusInfo): ?>
                        <a href="<?php echo e(route('admin.invoices.show', $activeInvoice->id)); ?>"
                           class="flex items-center justify-center gap-1.5 h-11 rounded-xl
                                  border text-sm font-medium transition <?php echo e($invStatusInfo['cls']); ?>">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                      d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586
                                         a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                            </svg>
                            Inv. <?php echo e($invStatusInfo['label']); ?>

                        </a>
                    <?php elseif(! $isFinal): ?>
                        
                        <button type="button"
                                onclick="Alpine.store('cancelModal').open(<?php echo e($ticket->id); ?>, '<?php echo e($ticket->ticket_code); ?>')"
                                class="flex items-center justify-center gap-1.5 h-11 rounded-xl
                                       border border-red-200 text-sm font-medium text-red-600
                                       hover:bg-red-50 active:bg-red-100 transition">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                      d="M6 18L18 6M6 6l12 12"/>
                            </svg>
                            Batalkan
                        </button>
                    <?php else: ?>
                        <a href="<?php echo e(route('nota.show', $ticket->ticket_code)); ?>"
                           class="flex items-center justify-center gap-1.5 h-11 rounded-xl
                                  border border-gray-200 text-sm font-medium text-gray-600
                                  hover:bg-gray-50 active:bg-gray-100 transition">
                            <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                      d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586
                                         a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                            </svg>
                            Nota
                        </a>
                    <?php endif; ?>

                </div>

            </div>
        </div>
    </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
</div>


<div class="hidden md:block bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">

    <div class="overflow-x-auto">
        <table class="w-full text-sm">
            <thead>
                <tr class="bg-gray-50 border-b border-gray-100 text-left">
                    <th class="px-4 py-3 font-semibold text-gray-600 whitespace-nowrap">No. Tiket</th>
                    <th class="px-4 py-3 font-semibold text-gray-600 whitespace-nowrap">Pelanggan</th>
                    <th class="px-4 py-3 font-semibold text-gray-600 whitespace-nowrap">Perangkat</th>
                    <th class="px-4 py-3 font-semibold text-gray-600 whitespace-nowrap">Status</th>
                    <th class="px-4 py-3 font-semibold text-gray-600 whitespace-nowrap">Masuk</th>
                    <th class="px-4 py-3 font-semibold text-gray-600 whitespace-nowrap text-right">Aksi</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-50">
                <?php $__currentLoopData = $tickets; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $ticket): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <?php
                    $cfg     = $statusConfig[$ticket->status] ?? ['bg'=>'bg-gray-100','text'=>'text-gray-700','dot'=>'bg-gray-400'];
                    $isFinal = in_array($ticket->status, ['Cancelled','Picked Up']);
                    $next    = $nextStatuses[$ticket->status] ?? null;
                    $canApproveRepair = in_array($ticket->status, ['Pending', 'Checking'], true) && ! $ticket->repair_approved_at;
                    if ($ticket->status === 'Checking' && ! $ticket->repair_approved_at) {
                        $next = null;
                    }
                    $activeInvoice    = $ticket->invoices->whereNotIn('status', ['cancelled'])->first();
                    $hasIssuedInvoice = $ticket->invoices->contains('status', 'issued');
                    $invStatusInfo    = $activeInvoice ? ($invoiceStatusLabel[$activeInvoice->status] ?? null) : null;
                ?>
                <tr class="hover:bg-gray-50/60 transition">

                    <td class="px-4 py-3.5 whitespace-nowrap">
                        <a href="<?php echo e(route('tickets.show', $ticket->id)); ?>"
                           class="font-mono font-semibold text-brand-600 hover:text-brand-800
                                  hover:underline text-xs tracking-wide">
                            <?php echo e($ticket->ticket_code); ?>

                        </a>
                    </td>

                    <td class="px-4 py-3.5 max-w-[160px]">
                        <p class="font-medium text-gray-800 truncate"><?php echo e($ticket->customer->name); ?></p>
                        <?php if($ticket->customer->whatsapp): ?>
                        <p class="text-xs text-gray-400 truncate"><?php echo e($ticket->customer->whatsapp); ?></p>
                        <?php endif; ?>
                    </td>

                    <td class="px-4 py-3.5 max-w-[180px]">
                        <p class="text-gray-800 truncate"><?php echo e($ticket->brand ? $ticket->brand.' '.$ticket->model : '—'); ?></p>
                        <p class="text-xs text-gray-400"><?php echo e($ticket->device_type ?? 'Belum diisi'); ?></p>
                    </td>

                    <td class="px-4 py-3.5 whitespace-nowrap">
                        <span class="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full
                                     text-xs font-semibold <?php echo e($cfg['bg']); ?> <?php echo e($cfg['text']); ?>">
                            <span class="w-1.5 h-1.5 rounded-full <?php echo e($cfg['dot']); ?>"></span>
                            <?php echo e($ticket->status); ?>

                        </span>
                        <?php if($ticket->repair_approved_at): ?>
                        <p class="text-xs text-emerald-600 mt-0.5">Perbaikan disetujui admin</p>
                        <?php endif; ?>
                        <?php if($ticket->status === 'Cancelled' && $ticket->cancel_reason): ?>
                        <p class="text-xs text-gray-400 mt-0.5 max-w-[160px] truncate"
                           title="<?php echo e($ticket->cancel_reason); ?>">
                            <?php echo e($ticket->cancel_reason); ?>

                        </p>
                        <?php endif; ?>

                        <div class="mt-1.5 space-y-1">
                            <p class="text-[11px] text-sky-700">
                                <span class="font-semibold">Dx:</span>
                                <?php echo e($ticket->initial_diagnosis ? \Illuminate\Support\Str::limit($ticket->initial_diagnosis, 45) : '-'); ?>

                            </p>
                            <p class="text-[11px] text-emerald-700">
                                <span class="font-semibold">QC:</span>
                                <?php echo e($ticket->final_check_notes ? \Illuminate\Support\Str::limit($ticket->final_check_notes, 45) : '-'); ?>

                            </p>
                            <p class="text-[11px] text-indigo-700">
                                <span class="font-semibold">SLA Dx→Ready:</span>
                                <?php echo e($formatMinutes($ticket->sla['diag_to_ready'] ?? null)); ?>

                            </p>
                        </div>
                    </td>

                    <td class="px-4 py-3.5 whitespace-nowrap text-xs text-gray-500">
                        <p><?php echo e($ticket->created_at->format('d M Y')); ?></p>
                        <p class="text-gray-400"><?php echo e($ticket->created_at->format('H:i')); ?></p>
                    </td>

                    <td class="px-4 py-3.5 whitespace-nowrap text-right">
                        <div class="flex items-center justify-end gap-2">

                            <?php if($next): ?>
                            <form method="POST" action="<?php echo e(route('admin.tickets.status', $ticket->id)); ?>">
                                <?php echo csrf_field(); ?> <?php echo method_field('PATCH'); ?>
                                <input type="hidden" name="status" value="<?php echo e($next); ?>">
                                <button type="submit"
                                        class="inline-flex items-center gap-1 text-xs font-medium
                                               px-2.5 py-1.5 rounded-lg border border-brand-200
                                               text-brand-700 hover:bg-brand-50 transition">
                                    <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round"
                                              stroke-width="2" d="M9 5l7 7-7 7"/>
                                    </svg>
                                    <?php echo e($next); ?>

                                </button>
                            </form>
                            <?php endif; ?>

                            <?php if($canApproveRepair): ?>
                            <form method="POST" action="<?php echo e(route('admin.tickets.approve-repair', $ticket->id)); ?>">
                                <?php echo csrf_field(); ?> <?php echo method_field('PATCH'); ?>
                                <button type="submit"
                                        class="inline-flex items-center gap-1 text-xs font-medium px-2.5 py-1.5
                                               rounded-lg border border-indigo-200 text-indigo-700
                                               hover:bg-indigo-50 transition">
                                    Setujui Perbaikan
                                </button>
                            </form>
                            <?php endif; ?>

                            
                            <?php if($ticket->status === 'Ready' && $hasIssuedInvoice): ?>
                            <a href="<?php echo e(route('handover.show', $ticket->id)); ?>"
                               class="inline-flex items-center gap-1 text-xs font-medium px-2.5 py-1.5
                                      rounded-lg border border-green-300 text-green-700
                                      hover:bg-green-50 transition">
                                <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                          d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
                                </svg>
                                Serah Terima
                            </a>
                            <?php elseif($ticket->status === 'Cancelled' && $hasIssuedInvoice && ! $ticket->asset?->sig_exit): ?>
                            <a href="<?php echo e(route('handover.show', $ticket->id)); ?>"
                               class="inline-flex items-center gap-1 text-xs font-medium px-2.5 py-1.5
                                      rounded-lg border border-orange-300 text-orange-700
                                      hover:bg-orange-50 transition">
                                <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                          d="M3 10h10a8 8 0 018 8v2M3 10l6 6m-6-6l6-6"/>
                                </svg>
                                Kembalikan
                            </a>
                            <?php endif; ?>

                            
                            <?php if(in_array($ticket->status, ['Ready', 'Cancelled']) && ! $hasIssuedInvoice && ! $activeInvoice): ?>
                            <a href="<?php echo e(route('admin.invoices.create', ['service_ticket_id' => $ticket->id])); ?>"
                               class="inline-flex items-center gap-1 text-xs font-medium px-2.5 py-1.5
                                      rounded-lg border border-emerald-200 text-emerald-700
                                      hover:bg-emerald-50 transition">
                                <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"/>
                                </svg>
                                <?php echo e($ticket->status === 'Cancelled' ? 'Inv. Batal' : 'Buat Invoice'); ?>

                            </a>
                            <?php elseif($activeInvoice && $invStatusInfo && ! $hasIssuedInvoice): ?>
                            <a href="<?php echo e(route('admin.invoices.show', $activeInvoice->id)); ?>"
                               class="inline-flex items-center gap-1 text-xs font-medium px-2.5 py-1.5
                                      rounded-lg border transition <?php echo e($invStatusInfo['cls']); ?>">
                                <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                          d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586
                                             a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                                </svg>
                                Inv. <?php echo e($invStatusInfo['label']); ?>

                            </a>
                            <?php endif; ?>

                            <a href="<?php echo e(route('tickets.show', $ticket->id)); ?>"
                               class="inline-flex items-center justify-center w-7 h-7 rounded-lg
                                      text-gray-400 hover:text-brand-600 hover:bg-brand-50 transition">
                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                          d="M15 12a3 3 0 11-6 0 3 3 0 016 0zM2.458 12C3.732 7.943 7.523 5
                                             12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542
                                             7-4.477 0-8.268-2.943-9.542-7z"/>
                                </svg>
                            </a>

                            <?php if(! $isFinal): ?>
                            <button type="button"
                                    onclick="Alpine.store('cancelModal').open(<?php echo e($ticket->id); ?>, '<?php echo e($ticket->ticket_code); ?>')"
                                    class="inline-flex items-center gap-1 text-xs font-medium px-2.5 py-1.5
                                           rounded-lg border border-red-200 text-red-600
                                           hover:bg-red-50 transition">
                                <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                          d="M6 18L18 6M6 6l12 12"/>
                                </svg>
                                Batal
                            </button>
                            <?php endif; ?>

                            <?php if($ticket->status === 'Picked Up'): ?>
                            <a href="<?php echo e(route('nota.show', $ticket->ticket_code)); ?>"
                               class="inline-flex items-center gap-1 text-xs font-medium px-2.5 py-1.5
                                      rounded-lg border border-gray-300 text-gray-600
                                      hover:bg-gray-50 transition">
                                <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                          d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586
                                             a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/>
                                </svg>
                                Nota
                            </a>
                            <?php endif; ?>

                        </div>
                    </td>

                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>

</div>


<?php if($tickets->hasPages()): ?>
<div class="mt-3 px-1 flex items-center justify-between text-sm flex-wrap gap-2">
    <p class="text-gray-500 text-xs">
        Menampilkan <?php echo e($tickets->firstItem()); ?>–<?php echo e($tickets->lastItem()); ?>

        dari <?php echo e($tickets->total()); ?>

    </p>
    <div class="flex gap-1 flex-wrap">
        <?php if($tickets->onFirstPage()): ?>
            <span class="px-3 py-1.5 rounded-lg text-gray-300 cursor-not-allowed select-none">‹</span>
        <?php else: ?>
            <a href="<?php echo e($tickets->previousPageUrl()); ?>"
               class="px-3 py-1.5 rounded-lg text-gray-600 hover:bg-white transition">‹</a>
        <?php endif; ?>

        <?php $__currentLoopData = $tickets->getUrlRange(1, $tickets->lastPage()); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $page => $url): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <a href="<?php echo e($url); ?>"
           class="px-3 py-1.5 rounded-lg transition text-xs font-medium
                  <?php echo e($page == $tickets->currentPage()
                      ? 'bg-brand-600 text-white shadow-sm'
                      : 'text-gray-600 hover:bg-white'); ?>">
            <?php echo e($page); ?>

        </a>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

        <?php if($tickets->hasMorePages()): ?>
            <a href="<?php echo e($tickets->nextPageUrl()); ?>"
               class="px-3 py-1.5 rounded-lg text-gray-600 hover:bg-white transition">›</a>
        <?php else: ?>
            <span class="px-3 py-1.5 rounded-lg text-gray-300 cursor-not-allowed select-none">›</span>
        <?php endif; ?>
    </div>
</div>
<?php endif; ?>

<?php endif; ?> 
<?php /**PATH C:\laragon\www\Service-sistem\resources\views/admin/tickets/_list.blade.php ENDPATH**/ ?>