<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Custom Dashboard</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- Interact.js for drag/resize -->
<script src="https://cdn.jsdelivr.net/npm/interactjs/dist/interact.min.js"></script>

<style>
body {
    margin: 0;
    font-family: Arial, sans-serif;
    overflow: hidden;
    background: #111;
    color: #fff;
}

/* Background system */
#bgVideo, #bgImage {
    position: fixed;
    top: 0; left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: -2;
}

#dashboard {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px;
}

/* Section base */
.section {
    background: rgba(255,255,255,0.05);
    border-radius: 12px;
    padding: 10px;
    min-width: 200px;
    min-height: 150px;
    position: relative;
    backdrop-filter: blur(8px);
    transition: 0.2s;
}

.section:hover {
    transform: scale(1.02);
}

/* Header */
.section-header {
    font-weight: bold;
    margin-bottom: 5px;
}

/* Widget iframe */
.section iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Controls */
.controls {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 999;
}

button {
    margin: 3px;
    padding: 6px 10px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

/* Layout modes */
.grid .section {
    flex: 1 1 calc(25% - 20px);
}

.list .section {
    flex: 1 1 100%;
}

.free {
    position: relative;
}

.free .section {
    position: absolute;
}
</style>
</head>

<body>

<!-- Background -->
<video id="bgVideo" autoplay muted loop style="display:none;"></video>
<img id="bgImage" style="display:none;">

<!-- Controls -->
<div class="controls">
    <button onclick="setLayout('grid')">Grid</button>
    <button onclick="setLayout('list')">List</button>
    <button onclick="setLayout('free')">Widget Mode</button>
    <button onclick="changeBg()">Change Background</button>
</div>

<!-- Dashboard -->
<div id="dashboard" class="grid">

    <!-- Example Section -->
    <div class="section draggable" data-x="0" data-y="0">
        <div class="section-header">YouTube</div>
        <iframe src="https://www.youtube.com/embed/dQw4w9WgXcQ"></iframe>
    </div>

    <div class="section draggable">
        <div class="section-header">Custom HTML</div>
        <div>
            <h3>Hello 👋</h3>
            <p>This is a custom widget.</p>
        </div>
    </div>

</div>

<!-- Sounds -->
<audio id="hoverSound" src="hover.mp3"></audio>
<audio id="clickSound" src="click.mp3"></audio>

<script>
const dashboard = document.getElementById("dashboard");

/* Layout switching */
function setLayout(mode) {
    dashboard.className = mode;
}

/* Background system */
function changeBg() {
    const type = prompt("image / video / slideshow?");
    
    if (type === "image") {
        let url = prompt("Image URL:");
        bgImage.src = url;
        bgImage.style.display = "block";
        bgVideo.style.display = "none";
    }

    if (type === "video") {
        let url = prompt("Video URL:");
        bgVideo.src = url;
        bgVideo.style.display = "block";
        bgImage.style.display = "none";
    }

    if (type === "slideshow") {
        let urls = prompt("Comma-separated image URLs:").split(",");
        let i = 0;
        bgImage.style.display = "block";
        bgVideo.style.display = "none";

        setInterval(() => {
            bgImage.src = urls[i];
            i = (i + 1) % urls.length;
        }, 5000);
    }
}

/* Drag + Resize */
interact('.draggable')
.draggable({
    listeners: {
        move(event) {
            let target = event.target;
            let x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx;
            let y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;

            target.style.transform = `translate(${x}px, ${y}px)`;

            target.setAttribute('data-x', x);
            target.setAttribute('data-y', y);
        }
    }
})
.resizable({
    edges: { left: true, right: true, bottom: true, top: true }
})
.on('resizemove', function (event) {
    let target = event.target;
    target.style.width = event.rect.width + 'px';
    target.style.height = event.rect.height + 'px';
});

/* Hover sound */
document.querySelectorAll(".section").forEach(el => {
    el.addEventListener("mouseenter", () => {
        document.getElementById("hoverSound").play();
    });

    el.addEventListener("click", () => {
        document.getElementById("clickSound").play();
    });
});

/* Per-section styling */
document.querySelectorAll(".section").forEach(el => {
    el.addEventListener("dblclick", () => {
        let colour = prompt("Background colour (e.g. red, #222):");
        let glow = prompt("Glow? (yes/no)");

        el.style.background = colour;

        if (glow === "yes") {
            el.style.boxShadow = "0 0 20px " + colour;
        }
    });
});
</script>

</body>
</html>