import { runTests, ConsoleRenderer } from "./third_party/test.js";
import { RealWeatherApi } from "./api.js";
import { WeatherComponent } from "./weather.js";
import { SettingsComponent } from "./settings.js";

declare const require: (id: string) => any;

function main() {
    const params = new URLSearchParams(window.location.search);
    const tenantId = params.get("tenantId") || "";
    const account = params.get("account") || "";
    const orderId = params.get("orderId") || "";

    const api = new RealWeatherApi();
    const weatherComponent = new WeatherComponent(api, tenantId, account, orderId);
    const settingsComponent = new SettingsComponent(api, tenantId, account);

    m.route(document.body, "/", {
        "/": weatherComponent,
        "/settings": settingsComponent,
    });
}

if (typeof process !== 'undefined' && process.versions != null && process.versions.node != null) {
    (globalThis as any).m = require("./third_party/mithril.js");
    runTests(new ConsoleRenderer());
} else {
    main();
}
