{% set repo_label = 'MAC' if folder == 'mac' else 'GUID' if folder == 'guid' else 'GPU' %}
<div class="d-flex justify-content-between align-items-center flex-wrap gap-2 mb-2">
    <div class="small text-muted">
        <i class="bi bi-folder2-open me-1"></i>{{ files|length }}개 파일
    </div>
    <div class="d-flex align-items-center flex-wrap gap-2">
        {% if files and files|length > 0 %}
        <div class="btn-group btn-group-sm" role="group" aria-label="{{ repo_label }} 선택 파일 작업">
            <button type="button" class="btn btn-outline-primary repo-selected-action"
                data-repo="{{ folder }}"
                data-action="{{ url_for('main.download_repository_files', repo_type=folder) }}" disabled>
                <i class="bi bi-download me-1"></i>선택 다운로드
            </button>
            <button type="button" class="btn btn-outline-danger repo-selected-action"
                data-repo="{{ folder }}"
                data-action="{{ url_for('main.delete_repository_files', repo_type=folder) }}"
                data-confirm="{{ repo_label }} 저장소에서 선택한 파일을 삭제하시겠습니까?" disabled>
                <i class="bi bi-trash me-1"></i>선택 삭제
            </button>
        </div>
        {% endif %}
        <form action="{{ url_for('main.archive_repository', repo_type=folder) }}" method="post" class="d-inline">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
            <button type="submit" class="btn btn-outline-secondary btn-sm"
                onclick="return confirm('{{ repo_label }} 저장소의 모든 파일을 아카이브로 이동하시겠습니까?');">
                <i class="bi bi-archive me-1"></i>{{ repo_label }} 아카이브로 이동
            </button>
        </form>
        <form action="{{ url_for('main.upload_workspace_files', target_type=folder) }}" method="post"
            enctype="multipart/form-data" class="d-inline-flex m-0">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
            <input type="hidden" name="duplicate_policy" value="rename">
            <label class="btn btn-outline-success btn-sm mb-0" title="{{ repo_label }} 저장소에 파일 업로드">
                <i class="bi bi-upload me-1"></i>업로드
                <input type="file" name="files" class="d-none workspace-file-upload-input" multiple
                    data-existing-files='{{ files|map(attribute="name")|list|tojson }}'>
            </label>
        </form>
    </div>
</div>
{% if files and files|length > 0 %}
<div class="table-shell">
    <div class="table-responsive bg-white">
        <table class="table table-hover table-sm mb-0 align-middle font-monospace repo-file-table"
            id="{{ table_id }}" data-repo="{{ folder }}" style="font-size: 0.9rem;">
            <thead class="bg-light sticky-top">
                <tr>
                    <th class="text-center" style="width: 44px;">
                        <input type="checkbox" class="form-check-input repo-select-all"
                            data-repo="{{ folder }}" data-table-id="{{ table_id }}" aria-label="{{ repo_label }} 전체 선택">
                    </th>
                    <th class="ps-3" style="cursor:pointer;" onclick="sortTable('{{ table_id }}', 1)">파일명 <i
                            class="bi bi-arrow-down-up small text-muted"></i></th>
                    <th style="cursor:pointer; width: 100px;" onclick="sortTable('{{ table_id }}', 2)">크기 <i
                            class="bi bi-arrow-down-up small text-muted"></i></th>
                    <th style="cursor:pointer; width: 160px;" onclick="sortTable('{{ table_id }}', 3)">날짜 <i
                            class="bi bi-arrow-down-up small text-muted"></i></th>
                    <th class="text-end pe-3" style="width: 96px;">작업</th>
                </tr>
            </thead>
            <tbody>
                {% for file in files %}
                <tr>
                    <td class="text-center">
                        <input type="checkbox" class="form-check-input repo-file-checkbox"
                            data-repo="{{ folder }}" value="{{ file.name }}" aria-label="{{ file.name }} 선택">
                    </td>
                    <td class="ps-3">
                        <i class="bi bi-file-earmark text-secondary me-2"></i>{{ file.name }}
                    </td>
                    <td>{{ (file.size / 1024)|round(1) }} KB</td>
                    <td data-sort="{{ file.mtime }}">{{ file.date }}</td>
                    <td class="text-end pe-3">
                        <div class="d-inline-flex align-items-center gap-2">
                            <button type="button" class="btn btn-xs btn-link text-secondary p-0 btn-view-repo"
                                data-bs-toggle="modal" data-bs-target="#fileViewModal" data-folder="{{ folder }}"
                                data-filename="{{ file.name }}" title="내용 보기">
                                <i class="bi bi-eye"></i>
                            </button>
                            <form action="{{ url_for('main.delete_repository_file', repo_type=folder) }}"
                                method="post" class="d-inline m-0">
                                <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
                                <input type="hidden" name="filename" value="{{ file.name }}">
                                <button type="submit" class="btn btn-xs btn-link text-danger p-0"
                                    title="삭제" onclick="return confirm('{{ file.name }} 파일을 삭제하시겠습니까?');">
                                    <i class="bi bi-trash"></i>
                                </button>
                            </form>
                        </div>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% else %}
<div class="empty-state-card">
    <div class="empty-state-icon">
        <i class="bi bi-folder2-open"></i>
    </div>
    <h6 class="fw-bold mb-2">{{ empty_msg }}</h6>
    <p class="text-muted">Quick Move를 실행하거나 업로드 버튼으로 파일을 추가하면 이곳에서 바로 확인할 수 있습니다.</p>
    <a href="#{{ 'macMoveForm' if folder == 'mac' else 'guidMoveForm' if folder == 'guid' else 'gpuMoveForm' }}"
        class="btn btn-outline-primary btn-sm">
        <i class="bi bi-arrow-down-circle me-1"></i>Quick Move 실행하기
    </a>
</div>
{% endif %}
