{{define "backups_flash"}}
{{if .Backup}}{{if .Backup.FlashSuccess}}
<div class="flash flash-success">{{.Backup.FlashSuccess}}</div>
{{end}}{{end}}
{{if .Backup}}{{if .Backup.FlashError}}
<div class="flash flash-error">{{.Backup.FlashError}}</div>
{{end}}{{end}}
{{end}}

{{define "backups_empty"}}
<div class="backup-empty-state">
    <div class="backup-empty-icon">&#128737;</div>
    <h3>Biztonsági mentés nincs beállítva</h3>
    <p>A biztonsági mentés funkció nem aktív.<br>
    Kérjük, vegye fel a kapcsolatot a Felhom csapattal a beállításhoz.</p>
</div>
{{end}}

{{define "restore_banner"}}
<!-- Part B: async restore progress banner — polls /api/backup/restore-status; neutral while running,
     red only on failure (exception-color principle). Hidden until a restore op is seen. -->
<div id="restore-banner" class="flash" style="display:none"></div>
{{end}}

{{define "restore_banner_js"}}
// Part B: restore-progress banner. Polls the async restore op-status every 3s. Shows a neutral
// "in progress" while running (including on a fresh page load mid-op), success on completion, and the
// error state ONLY on failure. Stops polling when idle after a terminal result was shown.
(function(){
    var banner = document.getElementById('restore-banner');
    if (!banner) return;
    var sawRunning = false;
    function opLabel(op){ return op === 'tier2-restore' ? 'Fájl-visszaállítás'
                        : op === 'offbox-restore' ? 'Távoli visszaállítás' : 'Visszaállítás'; }
    function render(st){
        if (st.running) {
            sawRunning = true;
            banner.className = 'flash';
            banner.style.display = 'block';
            banner.textContent = opLabel(st.op) + ' folyamatban' + (st.stack ? ': ' + st.stack : '') + '…';
            return;
        }
        if (st.last && sawRunning) {
            banner.style.display = 'block';
            if (st.last.ok) {
                banner.className = 'flash flash-success';
                banner.textContent = st.last.message || (opLabel(st.last.op) + ' kész.');
            } else {
                banner.className = 'flash flash-error';
                banner.textContent = st.last.message || (opLabel(st.last.op) + ' sikertelen.');
            }
        }
    }
    function poll(){
        fetch('/api/backup/restore-status', {headers: {'Accept':'application/json'}})
            .then(function(r){ return r.json(); })
            .then(function(j){ if (j && j.data) render(j.data); })
            .catch(function(){});
    }
    poll();
    setInterval(poll, 3000);
})();
{{end}}
