<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>LOGPile - BMC Log Analyzer</title>
    <link rel="stylesheet" href="/static/css/style.css">
</head>
<body>
    <header>
        <div class="app-header-row">
            <div class="app-header-brand">
                <h1>LOGPile <span class="header-domain">mchus.pro</span></h1>
                <p>Анализатор диагностических данных BMC/IPMI</p>
            </div>
            <div id="header-log-meta" class="header-log-meta hidden">
                <div class="header-actions">
                    <button id="clear-btn" class="hidden" onclick="clearData()">Очистить данные</button>
                    <button id="header-raw-btn" class="hidden" onclick="exportData('json')">Export Raw Data</button>
                    <button id="header-reanimator-btn" class="hidden" onclick="exportData('reanimator')">Экспорт Reanimator</button>
                    <button id="restart-btn" onclick="restartApp()">Перезапуск</button>
                    <button id="exit-btn" onclick="exitApp()">Выход</button>
                </div>
            </div>
        </div>
    </header>

    <main>
        <section id="upload-section">
            <div class="source-switch" role="tablist" aria-label="Источник данных">
                <button type="button" class="source-switch-btn active" data-source-type="archive">Архив</button>
                <button type="button" class="source-switch-btn" data-source-type="api">API</button>
                <button type="button" class="source-switch-btn" data-source-type="convert">Convert</button>
            </div>

            <div id="archive-source-content">
                <div class="upload-area" id="drop-zone">
                    <p>Перетащите архив, TXT/LOG или JSON snapshot сюда</p>
                    <input type="file" id="file-input" accept="application/gzip,application/x-gzip,application/x-tar,application/zip,application/json,text/plain,.ahs,.json,.tar,.tar.gz,.tgz,.sds,.zip,.txt,.log" hidden>
                    <button type="button" onclick="document.getElementById('file-input').click()">Выберите файл</button>
                    <p class="hint">Поддерживаемые форматы: ahs, tar.gz, tar, tgz, sds, zip, json, txt, log</p>
                </div>
                <div id="upload-status"></div>
                <div id="parsers-info" class="parsers-info"></div>
            </div>

            <div id="api-source-content" class="api-placeholder hidden">
                <form id="api-connect-form" novalidate>
                    <h3>Подключение к BMC API</h3>
                    <div id="api-form-errors" class="form-errors hidden"></div>

                    <div class="api-form-grid">
                        <label class="api-form-field" for="api-host">
                            <span>Host</span>
                            <input id="api-host" name="host" type="text" placeholder="10.0.0.10 или bmc.example.local">
                            <span class="field-error" data-error-for="host"></span>
                        </label>

                        <label class="api-form-field" for="api-port">
                            <span>Порт</span>
                            <input id="api-port" name="port" type="number" min="1" max="65535" value="443" placeholder="443">
                            <span class="field-error" data-error-for="port"></span>
                        </label>

                        <label class="api-form-field" for="api-username">
                            <span>Username</span>
                            <input id="api-username" name="username" type="text" placeholder="admin">
                            <span class="field-error" data-error-for="username"></span>
                        </label>

                        <label class="api-form-field" id="api-password-field" for="api-password">
                            <span>Пароль</span>
                            <input id="api-password" name="password" type="password" autocomplete="current-password">
                            <span class="field-error" data-error-for="password"></span>
                        </label>
                    </div>

                    <div class="api-form-actions">
                        <button id="api-connect-btn" type="button">Подключиться</button>
                    </div>
                    <div id="api-connect-status" class="api-connect-status"></div>
                    <div id="api-probe-options" class="api-probe-options hidden">
                        <div id="api-host-off-warning" class="api-host-off-warning hidden">
                            &#9888; Host выключен — данные инвентаря могут быть неполными
                        </div>
                        <label class="api-form-checkbox" for="api-debug-payloads">
                            <input id="api-debug-payloads" name="debug_payloads" type="checkbox">
                            <span>Сбор расширенных данных для диагностики</span>
                        </label>
                        <div class="api-form-actions">
                            <button id="api-collect-btn" type="submit">Собрать</button>
                        </div>
                    </div>
                </form>

                <section id="api-job-status" class="job-status hidden" aria-live="polite">
                    <div class="job-status-header">
                        <h4>Статус задачи сбора</h4>
                        <div class="job-status-actions">
                            <button id="skip-hung-btn" type="button" class="hidden" title="Прервать зависшие запросы и перейти к анализу собранных данных">Пропустить зависшие</button>
                            <button id="cancel-job-btn" type="button">Отменить</button>
                        </div>
                    </div>
                    <div class="job-status-meta">
                        <div><span class="meta-label">jobId:</span> <code id="job-id-value">-</code></div>
                        <div>
                            <span class="meta-label">Статус:</span>
                            <span id="job-status-value" class="job-status-badge">Queued</span>
                        </div>
                        <div><span class="meta-label">Этап:</span> <span id="job-progress-value">Сбор данных...</span></div>
                        <div><span class="meta-label">ETA:</span> <span id="job-eta-value">-</span></div>
                    </div>
                    <div class="job-progress" aria-label="Прогресс задачи">
                        <div id="job-progress-bar" class="job-progress-bar" style="width: 0%">0%</div>
                    </div>
                    <div id="job-active-modules" class="job-active-modules hidden">
                        <p class="meta-label">Активные модули:</p>
                        <div id="job-active-modules-list" class="job-module-chips"></div>
                    </div>
                    <div id="job-debug-info" class="job-debug-info hidden">
                        <p class="meta-label">Redfish debug:</p>
                        <div id="job-debug-summary" class="job-debug-summary"></div>
                        <div id="job-phase-telemetry" class="job-phase-telemetry"></div>
                    </div>
                    <div class="job-status-logs">
                        <p class="meta-label">Журнал шагов:</p>
                        <ul id="job-logs-list"></ul>
                    </div>
                </section>
            </div>

            <div id="convert-source-content" class="api-placeholder hidden">
                <h3>Пакетная выгрузка Reanimator</h3>
                <p>Выберите папку с файлами поддерживаемого типа. Для каждого файла будет создан отдельный экспорт Reanimator.</p>
                <div class="api-form-actions">
                    <input type="file" id="convert-folder-input" webkitdirectory directory multiple hidden>
                    <button id="convert-folder-btn" type="button" onclick="document.getElementById('convert-folder-input').click()">Выбрать папку</button>
                    <button id="convert-run-btn" type="button">Конвертировать в Reanimator</button>
                </div>
                <div id="convert-progress" class="convert-progress hidden" aria-live="polite">
                    <div class="convert-progress-meta">
                        <span id="convert-progress-label">Подготовка...</span>
                        <span id="convert-progress-value">0%</span>
                    </div>
                    <div class="convert-progress-track">
                        <div id="convert-progress-bar" class="convert-progress-bar" style="width: 0%"></div>
                    </div>
                </div>
                <div id="convert-folder-summary" class="api-connect-status"></div>
                <div id="convert-status" class="api-connect-status"></div>
            </div>
        </section>

        <section id="data-section" class="hidden">
            <section class="result-panel">
                <div class="audit-viewer-shell">
                    <iframe
                        id="audit-viewer-frame"
                        class="audit-viewer-frame"
                        title="Reanimator chart viewer"
                        loading="eager"
                        scrolling="no"
                        referrerpolicy="same-origin">
                    </iframe>
                </div>
            </section>
        </section>
    </main>

    <footer>
        <div class="footer-buttons">
        </div>
        <div class="footer-info">
            <p>Автор: <a href="https://mchus.pro" target="_blank">mchus.pro</a> | <a href="https://git.mchus.pro/mchus/logpile" target="_blank">Git Repository</a>{{if .AppVersion}} | v{{.AppVersion}}{{end}}</p>
        </div>
    </footer>

    <script src="/static/js/app.js"></script>
</body>
</html>
