<div>
    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(session()->has('doc_message')): ?>
        <div class="mb-4 p-3 bg-green-100 text-green-800 rounded-lg text-sm"><?php echo e(session('doc_message')); ?></div>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

    <div class="flex justify-between items-center mb-4">
        <h3 class="text-lg font-semibold">📁 Expediente Digital (<?php echo e($documentos->count()); ?> docs)</h3>
        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('procesos.edit')): ?>
        <button wire:click="abrirUpload" class="px-3 py-1.5 bg-indigo-600 text-white rounded-md text-sm hover:bg-indigo-700">
            📤 Subir Documentos
        </button>
        <?php endif; ?>
    </div>

    
    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($documentos->count() > 0): ?>
    <div class="overflow-hidden rounded-lg border border-gray-200">
        <table class="min-w-full divide-y divide-gray-200">
            <thead class="bg-gray-50">
                <tr>
                    <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase">#</th>
                    <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase">Tipo</th>
                    <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase">Archivo</th>
                    <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase">Tamaño</th>
                    <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase">Subido por</th>
                    <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase">Fecha</th>
                    <th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase">Acciones</th>
                </tr>
            </thead>
            <tbody class="bg-white divide-y divide-gray-200">
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $documentos; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $doc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <tr class="hover:bg-gray-50">
                    <td class="px-3 py-2 text-sm font-mono font-semibold text-gray-600"><?php echo e($doc->consecutivo_formateado); ?></td>
                    <td class="px-3 py-2 text-sm"><?php echo e($doc->tipo_label); ?></td>
                    <td class="px-3 py-2">
                        <div class="text-sm font-medium text-gray-800"><?php echo e($doc->nombre_original); ?></div>
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($doc->notas): ?>
                        <div class="text-xs text-gray-400"><?php echo e($doc->notas); ?></div>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                    </td>
                    <td class="px-3 py-2 text-xs text-gray-500"><?php echo e($doc->tamano_humano); ?></td>
                    <td class="px-3 py-2 text-xs text-gray-500"><?php echo e($doc->usuario->name ?? '—'); ?></td>
                    <td class="px-3 py-2 text-xs text-gray-500"><?php echo e($doc->created_at->format('d/m/Y H:i')); ?></td>
                    <td class="px-3 py-2 text-sm space-x-1">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($doc->es_pdf || $doc->es_imagen): ?>
                        <button wire:click="preview(<?php echo e($doc->id); ?>)" class="text-blue-600 hover:text-blue-800" title="Vista previa">👁</button>
                        <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <a href="<?php echo e($doc->url); ?>" target="_blank" download class="text-green-600 hover:text-green-800" title="Descargar">⬇️</a>
                        <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('procesos.edit')): ?>
                        <button wire:click="confirmDelete(<?php echo e($doc->id); ?>)" class="text-red-600 hover:text-red-800" title="Eliminar">🗑</button>
                        <?php endif; ?>
                    </td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
            </tbody>
        </table>
    </div>
    <?php else: ?>
    <div class="text-center text-gray-400 py-8 bg-gray-50 rounded-lg">
        📂 No hay documentos en este expediente.
    </div>
    <?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($showUploadModal): ?>
    <div class="fixed inset-0 z-50 overflow-y-auto" aria-modal="true">
        <div class="flex items-center justify-center min-h-screen p-4">
            <div class="fixed inset-0 bg-gray-500 bg-opacity-75" wire:click="$set('showUploadModal', false)"></div>
            <div class="relative bg-white rounded-lg shadow-xl w-full max-w-lg p-6">
                <h3 class="text-lg font-semibold mb-4">📤 Subir Documentos</h3>
                <div class="space-y-4">
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Tipo de Documento *</label>
                        <select wire:model="tipo_documento" class="w-full text-sm border-gray-300 rounded-md shadow-sm">
                            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__currentLoopData = $tiposDocumento; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $label): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <option value="<?php echo e($key); ?>"><?php echo e($label); ?></option>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        </select>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Archivos * (múltiples permitidos)</label>
                        <input type="file" wire:model="archivos" multiple
                            accept=".pdf,.doc,.docx,.xls,.xlsx,.jpg,.jpeg,.png,.gif,.txt,.csv"
                            class="w-full text-sm text-gray-500 file:mr-4 file:py-2 file:px-4 file:rounded file:border-0 file:text-sm file:font-semibold file:bg-indigo-50 file:text-indigo-700 hover:file:bg-indigo-100">
                        <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__errorArgs = ['archivos.*'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> <span class="text-red-500 text-xs"><?php echo e($message); ?></span> <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                        <div wire:loading wire:target="archivos" class="text-xs text-indigo-600 mt-1">⏳ Subiendo archivos...</div>
                    </div>
                    <div>
                        <label class="block text-sm font-medium text-gray-700 mb-1">Notas</label>
                        <input type="text" wire:model="notas" placeholder="Opcional" class="w-full text-sm border-gray-300 rounded-md shadow-sm">
                    </div>
                </div>
                <div class="flex justify-end gap-3 mt-4">
                    <button wire:click="$set('showUploadModal', false)" class="px-4 py-2 bg-gray-200 rounded-md text-sm">Cancelar</button>
                    <button wire:click="subirDocumentos" wire:loading.attr="disabled"
                        class="px-4 py-2 bg-indigo-600 text-white rounded-md text-sm hover:bg-indigo-700 disabled:opacity-50">
                        <span wire:loading.remove wire:target="subirDocumentos">Subir</span>
                        <span wire:loading wire:target="subirDocumentos">⏳ Guardando...</span>
                    </button>
                </div>
            </div>
        </div>
    </div>
    <?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($showPreviewModal && $previewDoc): ?>
    <div class="fixed inset-0 z-50 overflow-y-auto" aria-modal="true">
        <div class="flex items-center justify-center min-h-screen p-4">
            <div class="fixed inset-0 bg-gray-500 bg-opacity-75" wire:click="$set('showPreviewModal', false)"></div>
            <div class="relative bg-white rounded-lg shadow-xl w-full max-w-4xl" style="height: 85vh;">
                <div class="flex justify-between items-center p-4 border-b">
                    <div>
                        <h3 class="font-semibold"><?php echo e($previewDoc->tipo_label); ?> — #<?php echo e($previewDoc->consecutivo_formateado); ?></h3>
                        <p class="text-sm text-gray-500"><?php echo e($previewDoc->nombre_original); ?></p>
                    </div>
                    <div class="flex gap-2">
                        <a href="<?php echo e($previewDoc->url); ?>" target="_blank" download
                            class="px-3 py-1 bg-green-100 text-green-700 rounded text-sm hover:bg-green-200">⬇️ Descargar</a>
                        <button wire:click="$set('showPreviewModal', false)"
                            class="px-3 py-1 bg-gray-200 text-gray-700 rounded text-sm hover:bg-gray-300">✕ Cerrar</button>
                    </div>
                </div>
                <div class="p-4" style="height: calc(85vh - 70px);">
                    <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($previewDoc->es_pdf): ?>
                    <iframe src="<?php echo e($previewDoc->url); ?>" class="w-full h-full rounded border"></iframe>
                    <?php elseif($previewDoc->es_imagen): ?>
                    <div class="flex items-center justify-center h-full">
                        <img src="<?php echo e($previewDoc->url); ?>" alt="<?php echo e($previewDoc->nombre_original); ?>" class="max-h-full max-w-full object-contain rounded">
                    </div>
                    <?php else: ?>
                    <div class="flex items-center justify-center h-full text-gray-400">
                        Vista previa no disponible para este tipo de archivo.
                        <a href="<?php echo e($previewDoc->url); ?>" target="_blank" download class="ml-2 text-indigo-600 hover:underline">Descargar</a>
                    </div>
                    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
                </div>
            </div>
        </div>
    </div>
    <?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($showDeleteModal): ?>
    <div class="fixed inset-0 z-50 overflow-y-auto" aria-modal="true">
        <div class="flex items-center justify-center min-h-screen p-4">
            <div class="fixed inset-0 bg-gray-500 bg-opacity-75"></div>
            <div class="relative bg-white rounded-lg shadow-xl p-6 max-w-md">
                <h3 class="text-lg font-semibold text-red-600 mb-2">¿Eliminar documento?</h3>
                <p class="text-sm text-gray-600 mb-4">Se eliminará permanentemente el archivo del expediente.</p>
                <div class="flex justify-end gap-3">
                    <button wire:click="$set('showDeleteModal', false)" class="px-4 py-2 bg-gray-200 rounded-md text-sm">Cancelar</button>
                    <button wire:click="delete" class="px-4 py-2 bg-red-600 text-white rounded-md text-sm">Eliminar</button>
                </div>
            </div>
        </div>
    </div>
    <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
</div><?php /**PATH /home/evolucionamos/public_html/yber-dev/resources/views/livewire/documentos/documento-manager.blade.php ENDPATH**/ ?>