<?php $__env->startSection('title', $ticket->number); ?>
<?php $__env->startSection('content'); ?>

<?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session('success')): ?>
<div class="mb-4 p-4 bg-green-50 border border-green-200 rounded-2xl text-green-800 text-sm">
    <?php echo e(session('success')); ?>

</div>
<?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>


<div class="flex items-center gap-3 mb-5">
    <a href="<?php echo e(route('portal.index')); ?>"
       class="w-9 h-9 flex items-center justify-center rounded-full bg-white border border-gray-200 text-gray-500 shadow-sm flex-shrink-0">
        <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2.5">
            <path stroke-linecap="round" stroke-linejoin="round" d="M15 19l-7-7 7-7"/>
        </svg>
    </a>
    <div class="flex-1 min-w-0">
        <div class="flex items-center gap-2 flex-wrap">
            <span class="font-mono font-bold text-blue-600 text-sm"><?php echo e($ticket->number); ?></span>
            <span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium"
                  style="background-color: <?php echo e($ticket->status->color); ?>20; color: <?php echo e($ticket->status->color); ?>">
                <?php echo e($ticket->status->name); ?>

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


<?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($ticket->status->is_final && !$ticket->satisfaction_score): ?>
<div class="bg-blue-50 border border-blue-200 rounded-2xl p-4 mb-4">
    <h3 class="text-sm font-semibold text-blue-900 mb-3">¿Cómo fue la atención?</h3>
    <form method="POST" action="<?php echo e(route('portal.satisfaction', $ticket)); ?>">
        <?php echo csrf_field(); ?>
        <div class="flex gap-2 mb-3">
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php for($i = 1; $i <= 5; $i++): ?>
            <button type="button"
                    onclick="document.getElementById('scoreInput').value='<?php echo e($i); ?>';
                             document.querySelectorAll('.star-btn').forEach((b,j) => {
                                 b.classList.toggle('bg-yellow-400', j < <?php echo e($i); ?>);
                                 b.classList.toggle('bg-gray-100', j >= <?php echo e($i); ?>);
                             });"
                    class="star-btn flex-1 py-2 text-base bg-gray-100 rounded-xl transition">
                <?php echo e($i); ?>⭐
            </button>
            <?php endfor; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        </div>
        <input type="hidden" name="score" id="scoreInput" value="">
        <textarea name="comment" rows="2" placeholder="Comentario opcional..."
                  class="w-full rounded-xl border-gray-200 text-sm px-3 py-2 mb-3 bg-white"></textarea>
        <button type="submit"
                class="w-full py-2.5 bg-blue-600 text-white text-sm font-semibold rounded-xl">
            Enviar calificación
        </button>
    </form>
</div>
<?php elseif($ticket->satisfaction_score): ?>
<div class="bg-green-50 border border-green-200 rounded-2xl p-3 mb-4 flex items-center gap-2 text-sm text-green-800">
    <span>✓</span> Calificaste esta atención con <strong><?php echo e($ticket->satisfaction_score); ?>/5</strong> estrellas.
</div>
<?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>


<div class="bg-white rounded-2xl border border-gray-100 shadow-sm p-4 mb-4">
    <h2 class="text-base font-bold text-gray-900 mb-2"><?php echo e($ticket->title); ?></h2>
    <p class="text-sm text-gray-600 whitespace-pre-wrap leading-relaxed"><?php echo e($ticket->description); ?></p>
    <div class="flex items-center gap-3 mt-3 pt-3 border-t border-gray-50 text-xs text-gray-400 flex-wrap">
        <span style="color: <?php echo e($ticket->priority->color); ?>" class="font-medium">
            ● <?php echo e($ticket->priority->name); ?>

        </span>
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($ticket->category): ?>
        <span><?php echo e($ticket->category->name); ?></span>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($ticket->sla_resolution_due && !$ticket->status->is_final): ?>
        <span>SLA: <?php echo e($ticket->sla_remaining); ?></span>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>
</div>


<?php $ticketAttachments = $ticket->attachments->whereNull('comment_id'); ?>
<?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($ticketAttachments->count()): ?>
<div class="bg-white rounded-2xl border border-gray-100 shadow-sm p-4 mb-4">
    <h3 class="text-xs font-semibold text-gray-500 uppercase tracking-wide mb-3">Archivos adjuntos</h3>
    <div class="space-y-2">
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $ticketAttachments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $att): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
        <a href="<?php echo e(asset('storage/' . $att->path)); ?>" target="_blank"
           class="flex items-center gap-3 p-3 rounded-xl bg-gray-50 hover:bg-blue-50 transition">
            <div class="w-8 h-8 rounded-lg bg-blue-100 flex items-center justify-center flex-shrink-0">
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(str_contains($att->mime_type, 'image')): ?>
                    <svg class="h-4 w-4 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
                <?php else: ?>
                    <svg class="h-4 w-4 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"/></svg>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
            <div class="flex-1 min-w-0">
                <p class="text-sm font-medium text-gray-800 truncate"><?php echo e($att->original_name); ?></p>
                <p class="text-xs text-gray-400"><?php echo e($att->human_size); ?></p>
            </div>
            <svg class="h-4 w-4 text-gray-300 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2">
                <path stroke-linecap="round" stroke-linejoin="round" d="M4 16v1a3 3 0 003 3h10a3 3 0 003-3v-1m-4-4l-4 4m0 0l-4-4m4 4V4"/>
            </svg>
        </a>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>
</div>
<?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>


<div class="bg-white rounded-2xl border border-gray-100 shadow-sm mb-4">
    <div class="px-4 py-3 border-b border-gray-50">
        <h3 class="text-sm font-semibold text-gray-700">Conversación</h3>
    </div>

    <div class="divide-y divide-gray-50">
        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $ticket->comments->where('is_internal', false); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $comment): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
        <div class="px-4 py-4 <?php echo e($comment->user_id === auth()->id() ? '' : 'bg-gray-50'); ?>">
            <div class="flex items-center gap-2 mb-2">
                <div class="w-7 h-7 rounded-full flex items-center justify-center text-xs font-bold flex-shrink-0
                    <?php echo e($comment->user_id === auth()->id() ? 'bg-blue-100 text-blue-700' : 'bg-gray-200 text-gray-600'); ?>">
                    <?php echo e(strtoupper(substr($comment->user->name, 0, 1))); ?>

                </div>
                <span class="text-sm font-medium text-gray-800">
                    <?php echo e($comment->user_id === auth()->id() ? 'Tú' : $comment->user->name); ?>

                </span>
                <span class="text-xs text-gray-400 ml-auto"><?php echo e($comment->created_at->diffForHumans()); ?></span>
            </div>
            <p class="text-sm text-gray-700 leading-relaxed pl-9"><?php echo e($comment->body); ?></p>

            
            <?php $commentAtts = $ticket->attachments->where('comment_id', $comment->id); ?>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($commentAtts->count()): ?>
            <div class="pl-9 mt-2 space-y-1">
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $commentAtts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $att): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <a href="<?php echo e(asset('storage/' . $att->path)); ?>" target="_blank"
                   class="inline-flex items-center gap-2 text-xs text-blue-600 bg-blue-50 px-3 py-1.5 rounded-lg hover:bg-blue-100 transition">
                    <svg class="h-3.5 w-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"/></svg>
                    <?php echo e($att->original_name); ?> (<?php echo e($att->human_size); ?>)
                </a>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </div>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
        </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
        <div class="px-4 py-10 text-center text-sm text-gray-400">
            Sin mensajes aún. Puedes escribirnos si tienes más información.
        </div>
        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
    </div>

    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(!$ticket->status->is_final): ?>
    <div class="px-4 py-4 border-t border-gray-50 bg-gray-50 rounded-b-2xl">
        <form method="POST" action="<?php echo e(route('portal.comment', $ticket)); ?>" enctype="multipart/form-data">
            <?php echo csrf_field(); ?>
            <textarea name="body" rows="3"
                      placeholder="Escribe un mensaje o información adicional..."
                      class="w-full rounded-xl border-gray-200 text-sm px-3 py-2.5 mb-3 bg-white focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none"></textarea>

            
            <label class="flex items-center gap-2 text-xs text-gray-500 cursor-pointer mb-3 hover:text-blue-600 transition w-fit">
                <svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" stroke-width="2">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M15.172 7l-6.586 6.586a2 2 0 102.828 2.828l6.414-6.586a4 4 0 00-5.656-5.656l-6.415 6.585a6 6 0 108.486 8.486L20.5 13"/>
                </svg>
                <span id="comment-file-label">Adjuntar archivo (opcional)</span>
                <input type="file" name="attachments[]" multiple accept=".jpg,.jpeg,.png,.gif,.pdf,.doc,.docx,.xls,.xlsx,.txt,.zip"
                       class="hidden" onchange="document.getElementById('comment-file-label').textContent = this.files.length + ' archivo(s)'">
            </label>

            <button type="submit"
                    class="w-full py-3 bg-blue-600 text-white text-sm font-semibold rounded-xl hover:bg-blue-700 transition">
                Enviar mensaje
            </button>
        </form>
    </div>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
</div>

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

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