(function () { "use strict"; const dataService = window.TarotDataService || {}; const { DAY_IN_MS, getDateKey, getDecanForDate, getMoonPhaseName, calcPlanetaryHoursForDayAndLocation } = window.TarotCalc; const nowUiHelpers = window.NowUiHelpers || {}; if ( typeof nowUiHelpers.findNextDecanTransition !== "function" || typeof nowUiHelpers.findNextMoonPhaseTransition !== "function" || typeof nowUiHelpers.formatCountdown !== "function" || typeof nowUiHelpers.getSignStartDate !== "function" || typeof nowUiHelpers.getDisplayTarotName !== "function" || typeof nowUiHelpers.setNowCardImage !== "function" || typeof nowUiHelpers.renderNowPlanetPositions !== "function" || typeof nowUiHelpers.updateNowStats !== "function" ) { throw new Error("NowUiHelpers module must load before ui-now.js"); } let moonCountdownCache = null; let decanCountdownCache = null; function joinSabianPhrases(phrases) { const parts = (Array.isArray(phrases) ? phrases : []) .map((phrase) => String(phrase || "").trim()) .filter(Boolean); if (!parts.length) { return "--"; } return parts.join(" "); } function renderNowStatsFromSnapshot(elements, stats) { if (elements.nowStatsPlanetsEl) { nowUiHelpers.renderNowPlanetPositions( elements.nowStatsPlanetsEl, Array.isArray(stats?.planetPositions) ? stats.planetPositions : [] ); } if (elements.nowStatsSabianEl) { const sunSabianSymbol = stats?.sunSabianSymbol || null; const moonSabianSymbol = stats?.moonSabianSymbol || null; elements.nowStatsSabianEl.textContent = joinSabianPhrases([ moonSabianSymbol?.phrase, sunSabianSymbol?.phrase ]); } } function applyNowSnapshot(elements, snapshot, timeFormat) { const timestamp = snapshot?.timestamp ? new Date(snapshot.timestamp) : new Date(); const dayKey = String(snapshot?.dayKey || getDateKey(timestamp)); const currentHour = snapshot?.currentHour || null; if (currentHour?.planet) { elements.nowHourEl.textContent = `${currentHour.planet.symbol} ${currentHour.planet.name}`; if (elements.nowHourTarotEl) { const hourCardName = currentHour.planet?.tarot?.majorArcana || ""; const hourTrumpNumber = currentHour.planet?.tarot?.number; elements.nowHourTarotEl.textContent = hourCardName ? nowUiHelpers.getDisplayTarotName(hourCardName, hourTrumpNumber) : "--"; } elements.nowCountdownEl.textContent = nowUiHelpers.formatCountdown(currentHour.msRemaining, timeFormat); if (elements.nowHourNextEl) { const nextPlanet = currentHour.nextHourPlanet; elements.nowHourNextEl.textContent = nextPlanet ? `> ${nextPlanet.name}` : "> --"; } nowUiHelpers.setNowCardImage( elements.nowHourCardEl, currentHour.planet?.tarot?.majorArcana, "Current planetary hour card", currentHour.planet?.tarot?.number ); } else { elements.nowHourEl.textContent = "--"; elements.nowCountdownEl.textContent = "--"; if (elements.nowHourTarotEl) { elements.nowHourTarotEl.textContent = "--"; } if (elements.nowHourNextEl) { elements.nowHourNextEl.textContent = "> --"; } nowUiHelpers.setNowCardImage(elements.nowHourCardEl, null, "Current planetary hour card"); } const moon = snapshot?.moon || null; const illuminationFraction = Number(moon?.illuminationFraction || 0); const moonTarot = moon?.tarot?.majorArcana || "The High Priestess"; elements.nowMoonEl.textContent = moon ? `${moon.phase} (${Math.round(illuminationFraction * 100)}%)` : "--"; elements.nowMoonTarotEl.textContent = moon ? nowUiHelpers.getDisplayTarotName(moonTarot, moon?.tarot?.number) : "--"; nowUiHelpers.setNowCardImage( elements.nowMoonCardEl, moon?.tarot?.majorArcana, "Current moon phase card", moon?.tarot?.number ); if (elements.nowMoonCountdownEl) { if (moon?.countdown) { elements.nowMoonCountdownEl.textContent = nowUiHelpers.formatCountdown(moon.countdown.msRemaining, timeFormat); if (elements.nowMoonNextEl) { elements.nowMoonNextEl.textContent = `> ${moon.countdown.nextPhase}`; } } else { elements.nowMoonCountdownEl.textContent = "--"; if (elements.nowMoonNextEl) { elements.nowMoonNextEl.textContent = "> --"; } } } const decanInfo = snapshot?.decan || null; if (decanInfo?.sign) { const signMajorName = nowUiHelpers.getDisplayTarotName( decanInfo.sign?.tarot?.majorArcana, decanInfo.sign?.tarot?.number ); const signDegree = Number.isFinite(Number(decanInfo.signDegree)) ? Number(decanInfo.signDegree).toFixed(1) : "0.0"; elements.nowDecanEl.textContent = `${decanInfo.sign.symbol} ${decanInfo.sign.name} · ${signMajorName} (${signDegree}°)`; if (decanInfo.decan?.tarotMinorArcana) { elements.nowDecanTarotEl.textContent = nowUiHelpers.getDisplayTarotName(decanInfo.decan.tarotMinorArcana); nowUiHelpers.setNowCardImage(elements.nowDecanCardEl, decanInfo.decan.tarotMinorArcana, "Current decan card"); } else { const signTarotName = decanInfo.sign?.tarot?.majorArcana || "--"; elements.nowDecanTarotEl.textContent = signTarotName === "--" ? "--" : nowUiHelpers.getDisplayTarotName(signTarotName, decanInfo.sign?.tarot?.number); nowUiHelpers.setNowCardImage( elements.nowDecanCardEl, decanInfo.sign?.tarot?.majorArcana, "Current decan card", decanInfo.sign?.tarot?.number ); } if (elements.nowDecanCountdownEl) { if (decanInfo.countdown) { elements.nowDecanCountdownEl.textContent = nowUiHelpers.formatCountdown(decanInfo.countdown.msRemaining, timeFormat); if (elements.nowDecanNextEl) { elements.nowDecanNextEl.textContent = `> ${nowUiHelpers.getDisplayTarotName(decanInfo.countdown.nextLabel)}`; } } else { elements.nowDecanCountdownEl.textContent = "--"; if (elements.nowDecanNextEl) { elements.nowDecanNextEl.textContent = "> --"; } } } } else { elements.nowDecanEl.textContent = "--"; elements.nowDecanTarotEl.textContent = "--"; nowUiHelpers.setNowCardImage(elements.nowDecanCardEl, null, "Current decan card"); if (elements.nowDecanCountdownEl) { elements.nowDecanCountdownEl.textContent = "--"; } if (elements.nowDecanNextEl) { elements.nowDecanNextEl.textContent = "> --"; } } renderNowStatsFromSnapshot(elements, snapshot?.stats || {}); return { dayKey, skyRefreshKey: String(snapshot?.skyRefreshKey || "") }; } async function updateNowPanel(referenceData, geo, elements, timeFormat = "minutes") { if (!referenceData || !geo || !elements) { return { dayKey: getDateKey(new Date()), skyRefreshKey: "" }; } const snapshot = await dataService.fetchNowSnapshot?.(geo, new Date()); return applyNowSnapshot(elements, snapshot || {}, timeFormat); } window.TarotNowUi = { updateNowPanel }; })();