import constants from "../util/constants";

register("renderOverlay", () => {
    if (!constants.onboarding.main) {
        showTitle("§4READ THE FUCKING USAGE GUIDE", "-bling. stop pinging me with stupid questions", 5000);
        ChatLib.chat("§d[BlingBling Addons] §fWelcome to BlingBling Addons!");
        ChatLib.chat("§d[BlingBling Addons] §fTo change settings, run §d/bling§f, or §d/b");
        ChatLib.chat("§d[BlingBling Addons] §fFor help, run §d/b§f and go to the §6Usage§f tab");
        constants.onboarding.main = true;
        constants.save();
    }
});
const currentTitle = {
    title: null,
    subtitle: null,
    time: null
};

let started = null;

const _drawTitle = (title, subtitle) => {
    const [x, y] = [
        Renderer.screen.getWidth() / 2,
        Renderer.screen.getHeight() / 2
    ];

    Renderer.translate(x, y);
    Renderer.scale(4, 4);
    Renderer.drawStringWithShadow(title, -(Renderer.getStringWidth(title) / 2), -10);

    Renderer.translate(x, y);
    Renderer.scale(2, 2);
    Renderer.drawStringWithShadow(subtitle, -(Renderer.getStringWidth(subtitle) / 2), 5);
};

const showTitle = (title, subtitle, ms) => {
    currentTitle.title = title;
    currentTitle.subtitle = subtitle;
    currentTitle.time = ms;
};
register("renderOverlay", () => {
    if (!currentTitle.time) return;
    if (!started) started = Date.now();

    const remainingTime = currentTitle.time - (Date.now() - started);

    if (remainingTime <= 0) {
        currentTitle.title = null;
        currentTitle.subtitle = null;
        currentTitle.time = null;
        started = null;
        return;
    }

    _drawTitle(currentTitle.title, currentTitle.subtitle);
});
