<?php
// List View (folders, images, other files)
?>
<div id="listView" style="display:none;">
    <table class="table table-hover align-middle">
        <tbody>

        <!-- Folders -->
        <?php foreach ($folders as $f): ?>
            <tr>
                <td style="width:80px;">
                    <div class="icon" style="font-size:32px;">📁</div>
                </td>
                <td>
                    <a href="?path=<?= urlencode(trim($path . '/' . $f, '/')) ?>">
                        <?= htmlspecialchars($f) ?>
                    </a>
                </td>
                <td class="text-end">
                    <button class="btn btn-sm btn-outline-secondary"
                            data-bs-toggle="modal"
                            data-bs-target="#renameModal"
                            data-item="<?= htmlspecialchars($f) ?>">
                        Rename
                    </button>

                    <a href="delete.php?path=<?= urlencode($path) ?>&item=<?= urlencode($f) ?>"
                       class="btn btn-sm btn-outline-danger"
                       onclick="return confirm('Delete folder and all contents?');">
                        Delete
                    </a>
                </td>
            </tr>
        <?php endforeach; ?>

        <!-- Images -->
        <?php foreach ($images as $img): ?>
            <?php
                // Use the same source as grid view
                $thumb = "serve.php?path=" . urlencode($path) . "&file=" . urlencode($img);
            ?>
            <tr>
                <td style="width:80px;">
                    <img src="<?= $thumb ?>"
                         alt=""
                         style="width:80px; height:80px; object-fit:cover; border-radius:6px;">
                </td>
                <td>
                    <a href="view.php?path=<?= urlencode($path) ?>&file=<?= urlencode($img) ?>">
                        <?= htmlspecialchars($img) ?>
                    </a>
                </td>
                <td class="text-end">
                    <button class="btn btn-sm btn-outline-secondary"
                            data-bs-toggle="modal"
                            data-bs-target="#renameModal"
                            data-item="<?= htmlspecialchars($img) ?>">
                        Rename
                    </button>

                    <a href="delete.php?path=<?= urlencode($path) ?>&item=<?= urlencode($img) ?>"
                       class="btn btn-sm btn-outline-danger"
                       onclick="return confirm('Delete this file?');">
                        Delete
                    </a>
                </td>
            </tr>
        <?php endforeach; ?>

        <!-- Other Files -->
        <?php foreach ($others as $o): ?>
            <tr>
                <td style="width:80px;">
                    <div class="icon" style="font-size:32px;">📄</div>
                </td>
                <td>
                    <a href="serve.php?path=<?= urlencode($path) ?>&file=<?= urlencode($o) ?>">
                        <?= htmlspecialchars($o) ?>
                    </a>
                </td>
                <td class="text-end">
                    <button class="btn btn-sm btn-outline-secondary"
                            data-bs-toggle="modal"
                            data-bs-target="#renameModal"
                            data-item="<?= htmlspecialchars($o) ?>">
                        Rename
                    </button>

                    <a href="delete.php?path=<?= urlencode($path) ?>&item=<?= urlencode($o) ?>"
                       class="btn btn-sm btn-outline-danger"
                       onclick="return confirm('Delete this file?');">
                        Delete
                    </a>
                </td>
            </tr>
        <?php endforeach; ?>

        </tbody>
    </table>
</div>
