<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <title>폴더 찾기</title>
    <style>
        body { font-family: 'Malgun Gothic', Arial, sans-serif; font-size:13px; background:#f7f8fc; color:#222;}
        .folder-list { margin:20px; min-width:360px;}
        .folder { margin:4px 0; }
        .folder a { color:#1867c0; text-decoration:none; margin-right:6px; }
        .folder a:hover { text-decoration:underline; }
        .select-btn { background:#159; color:#fff; border:none; border-radius:4px; padding:4px 13px; font-size:13px; cursor:pointer;}
        .up { color:#444; }
        .mount-list { margin:20px; font-weight:bold; }
        .mount-item { margin:4px 0; }
    </style>
    <script>
        function selectFolder(path) {
            if (window.opener && window.opener.setFolderPath) {
                window.opener.setFolderPath(path);
                window.close();
            } else if (window.opener) {
                var inp = window.opener.document.querySelector('input[name=src]:focus, input[name=dest]:focus');
                if (inp) {
                    inp.value = path;
                }
                window.close();
            }
        }
    </script>
</head>
<body>
    <div class="mount-list">
        <div>마운트된 드라이브:</div>
        {% if mounted_drives %}
            {% for drive in mounted_drives %}
                <div class="mount-item">
                    <a href="{{ url_for('browse_folder', base=drive) }}">{{ drive }}</a>
                    <button class="select-btn" onclick="selectFolder('{{ drive }}')">선택</button>
                </div>
            {% endfor %}
        {% else %}
            <div>마운트된 드라이브가 없습니다.</div>
        {% endif %}
    </div>

    <div class="folder-list">
        <div style="font-weight:bold; margin-bottom:10px;">
            경로: <span style="color:#159">{{ base }}</span>
        </div>
        <button class="select-btn" onclick="selectFolder('{{ base }}')">이 폴더 선택</button>
        <div style="margin:10px 0;"></div>
        {% if base != '/' %}
        <div class="folder up">
            <a href="{{ url_for('browse_folder', base=parent) }}">⬆ 상위폴더</a>
        </div>
        {% endif %}
        {% for f in subfolders %}
        <div class="folder">
            <a href="{{ url_for('browse_folder', base=base ~ '/' ~ f) }}">{{ f }}</a>
        </div>
        {% endfor %}
    </div>
</body>
</html>
