<?php
// mostrar_soporte.php
session_start();
include '../includes/session_control.php';
include '../db/db.php';

$id = intval($_GET['id'] ?? 0);
if (!$id) die('ID inválido.');

$dir = __DIR__ . "/../archivoDigital/soporteMovimiento/{$id}/";
if (!is_dir($dir)) die('No hay archivos de soporte.');

$files = array_diff(scandir($dir), ['.', '..']);
?>
<!DOCTYPE html>
<html lang="es">

<head>
    <meta charset="UTF-8">
    <title>Soporte Movimiento #<?= $id ?></title>
    <style>
        img {
            max-width: 200px;
            margin: 10px;
        }

        a.archivo {
            display: block;
            margin: 5px 0;
            color: #333;
        }
    </style>
</head>

<body>
    <h2>Archivos de soporte para transferencia #<?= $id ?></h2>
    <?php foreach ($files as $f): ?>
        <?php
        $rutaRelativa = "../archivoDigital/soporteMovimiento/{$id}/" . rawurlencode($f);
        $ext = strtolower(pathinfo($f, PATHINFO_EXTENSION));
        // Si es imagen, mostrar miniatura; sino, mostrar enlace al PDF
        if (in_array($ext, ['png', 'jpg', 'jpeg', 'gif'])): ?>
            <a href="<?= $rutaRelativa ?>" target="_blank">
                <img src="<?= $rutaRelativa ?>" alt="<?= htmlspecialchars($f) ?>">
            </a>
        <?php else: ?>
            <a class="archivo" href="<?= $rutaRelativa ?>" target="_blank">
                📄 <?= htmlspecialchars($f) ?>
            </a>
        <?php endif; ?>
    <?php endforeach; ?>
</body>

</html>