import { showNotification } from "../notification.js"; import { refreshHud } from "../hud.js"; export async function loadMine(buildingId) { const actionsTab = document.getElementById("tab-actions"); if (!actionsTab) return; actionsTab.innerHTML = `
" + data.error + "
"; return; } const minutesLeft = Math.floor(data.next_cycle_in_seconds / 60); const secondsLeft = data.next_cycle_in_seconds % 60; const resourceRows = data.available .map((r) => { const icon = resourceIcon(r.resource); const label = resourceLabel(r.resource); return ( "Abgebaut
" + "Fehler beim Laden der Mineninfo.
"; } } document.addEventListener("click", async (e) => { const btn = e.target.closest("#mine-collect-btn"); if (!btn || btn.disabled) return; const buildingId = btn.dataset.building; btn.disabled = true; btn.textContent = "Wird abgeholt..."; try { const res = await fetch("/api/mine/" + buildingId + "/collect", { method: "POST", }); if (!res.ok) throw new Error("API Fehler"); const data = await res.json(); if (data.error) { showNotification( data.ready_in_display ? "Die Mine ist noch nicht bereit.\nBereit in: " + data.ready_in_display : data.error, "Mine", "⛏️", ); await renderMineStatus(buildingId); return; } const lines = data.collected .map( (c) => resourceLabel(c.resource) + ": +" + c.amount, ) .join("\n"); showNotification("Erfolgreich abgeholt!\n\n" + lines, "Mine", "⛏️"); await renderMineStatus(buildingId); await refreshHud(); } catch (err) { console.error("Abholen Fehler:", err); showNotification( "Fehler beim Abholen. Bitte erneut versuchen.", "Fehler", "⚠️", ); await renderMineStatus(buildingId); } }); let countdownInterval = null; function startCountdown(buildingId) { if (countdownInterval) clearInterval(countdownInterval); countdownInterval = setInterval(() => { const el = document.getElementById("mine-countdown"); if (!el) { clearInterval(countdownInterval); return; } let secs = parseInt(el.dataset.seconds, 10) - 1; if (secs < 0) secs = 0; el.dataset.seconds = secs; el.textContent = Math.floor(secs / 60) + "m " + (secs % 60) + "s"; if (secs === 0) { clearInterval(countdownInterval); renderMineStatus(buildingId); } }, 1000); } function resourceIcon(resource) { if (resource === "iron") { return ( "" ); } if (resource === "gold") { return ( "" ); } if (resource === "wood") { return ( "" ); } if (resource === "stone") { return ( "" ); } const map = { copper: "🟤", silver: "⚪", }; return map[resource] || "📦"; } function resourceLabel(resource) { const map = { gold: "Gold", copper: "Kupfer", silver: "Silber", iron: "Eisen", stone: "Stein", wood: "Holz", }; return map[resource] || resource; }