import ClimateChart from "./ClimateChart";

const ROOT_URL: string = "climate/";
const CHART_DOM_ID: string = "myChart";

function createClimateChart() {
    const pathname = window.location.pathname;
    let minutesDisplayed = 60;
    const argsStart = pathname.search(/\?minute-span=/);
    if (argsStart !== -1) {
        const parsedMins = Number(pathname[12]);
        if (!isNaN(parsedMins) && parsedMins > 0) {
            minutesDisplayed = parsedMins;
        }
    }
    return new ClimateChart(ROOT_URL, CHART_DOM_ID, minutesDisplayed);
}

const overlay = document.createElement('div');
overlay.innerText = 'Loading data...';
overlay.className = 'overlay';
document.getRootNode().appendChild(overlay);

const climateChart = createClimateChart();
climateChart.onLoaded(() => {
    overlay.classList.add('hidden');
})