{{--
 * 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/>
 * /Δ\
--}}

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo Reset</title>
    @vite(['resources/css/app.css', 'resources/js/app.js'])
  </head>
  <body class="bg-gray-900 text-gray-100 font-mono p-6">

    <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>

  </body>
</html>
