{{--
 * Blade Template
 *
 * @version     1.0.$Revision:$
 * @version     SVN: $Id:$
 * @package     bplan-base/globals
 * @subpackage  Blades
 * @author      Wassilios Meletiadis <wassilios.meletiadis@bplan-solutions.de>
 * @author      Emilio Cannarozzo <emilio.cannarozzo@bplan-solutions.de>
 * @copyright   Copyright (C) 2025, 2026 bplan-solutions GmbH & Co. KG <https://www.bplan-solutions.de/>
 * /?\
--}}

@extends('layouts.app')

@section('content')
<div class="bg-black text-green-400 font-mono p-4 rounded-lg">
    <pre id="console" class="whitespace-pre-wrap"></pre>
</div>

<script>
    let lastLine = 0;
    let done = false;

    async function pollLog() {
        if (done) return;

        const res = await fetch("{{ route('demo.reset.progress') }}?lastLine=" + lastLine);
        const data = await res.json();

        if (data.lines.length > 0) {
            const consoleEl = document.getElementById("console");
            data.lines.forEach(line => {
                consoleEl.textContent += line + "\n";
                if (line.includes("### DONE ###")) {
                    done = true;
                }
            });
            lastLine = data.lastLine;
            consoleEl.scrollTop = consoleEl.scrollHeight; // Auto-Scroll
        }
    }

    // Starten, dann poll starten
    fetch("{{ route('demo.reset.start') }}").then(() => {
        setInterval(pollLog, 1000);
    });
</script>
@endsection
