<!DOCTYPE html>
<html lang="en">
  
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>STORING</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            text-align: center;
            margin-top: 10%;
            transition: background-color 0.5s, color 0.5s;
            font-size: 1.5em; 
        }
        .container {
            display: inline-block;
            padding: 26px; 
            border: 2px solid #ccc;
            border-radius: 30px;
            transition: border-color 0.5s;
        }
        #time {
            font-size: 5.0em; 
        }
        .btn {
            padding: 13px 26px; 
            margin: 6px; 
            font-size: 1.0em; 
            cursor: pointer;
        }
        #darkModeToggle {
            position: fixed;
            bottom: 10px;
            left: 10px;
            padding: 4px 8px; 
            font-size: 0.6em; 
        }
        #footerText {
            position: fixed;
            bottom: 10px;
            right: 10px;
            font-size: 0.4em;
            text-align: center;
        }
        #footerText span {
            display: block;
        }
        .dark-mode {
            background-color: #333;
            color: white;
            font-size: 1.5em; 
        }
        .dark-mode .container {
            border-color: #555;
        }
    </style>
</head>

<body class="dark-mode">
    <div class="container">
        <h1>STORING</h1>
        <div id="time">
            <span class="digit" id="hr">00</span>:<span class="digit" id="min">00</span>:<span class="digit" id="sec">00</span>:<span class="digit" id="count">00</span>
        </div>
        <div id="buttons">
            <button class="btn" id="start">Start</button>
            <button class="btn" id="reset">Reset</button>
            <button class="btn" id="klantContact">Klant Contact Gereed</button>
        </div>
    </div>

    <audio id="beep" src="beep.mp3" preload="auto"></audio>

    <button class="btn" id="darkModeToggle">Donkere Modus</button>
    <div id="footerText">
        <span>Gemaakt door</span>
        <span>Kevin Montfoort</span>
    </div>

    <script>
        let hr = 0, min = 0, sec = 0, count = 0;
        let STORINGInterval;
        let isRunning = false;
        let alerts = [];
        const beepSound = document.getElementById('beep');

        document.getElementById('start').addEventListener('click', startSTORING);
        document.getElementById('reset').addEventListener('click', resetSTORING);
        document.getElementById('klantContact').addEventListener('click', klantContactGereed);

        function startSTORING() {
            if (isRunning) return;
            isRunning = true;
            STORINGInterval = setInterval(runSTORING, 10);
        }

        function resetSTORING() {
            clearInterval(STORINGInterval);
            isRunning = false;
            hr = min = sec = count = 0;
            displayTime();
            alerts = [15 * 60, 60 * 60]; 
        }

        function klantContactGereed() {
            resetSTORING(); 
            alerts = [60 * 60];		
			startSTORING();
        }

        function runSTORING() {
            count++;
            if (count == 100) {
                sec++;
                count = 0;
            }
            if (sec == 60) {
                min++;
                sec = 0;
            }
            if (min == 60) {
                hr++;
                min = 0;
                sec = 0;
            }
            displayTime();
            checkAlerts();
        }

        function displayTime() {
            document.getElementById('hr').textContent = formatTime(hr);
            document.getElementById('min').textContent = formatTime(min);
            document.getElementById('sec').textContent = formatTime(sec);
            document.getElementById('count').textContent = formatTime(count);
        }

        function formatTime(value) {
            return value < 10 ? '0' + value : value;
        }

        function setAlert(minutes) {
            let alertTime = minutes * 60; 
            if (!alerts.includes(alertTime)) {
                alerts.push(alertTime);
            }
        }

        function checkAlerts() {
            let totalSeconds = hr * 3600 + min * 60 + sec;
            if (alerts.includes(totalSeconds)) {
                beepSound.play();
                alerts = alerts.filter(time => time !== totalSeconds);
            }
        }

        alerts = [15 * 60, 60 * 60]; 

        // Donkere modus toggle functie
        document.getElementById('darkModeToggle').addEventListener('click', toggleDarkMode);

        function toggleDarkMode() {
            document.body.classList.toggle('dark-mode');
        }
    </script>
</body>
  
</html>
