import { getLocale, i18n } from "./i18n";
const ERROR_MESSAGE_CLASS = "error-message";
const BLUR_CLASS = "blur";
const COMPACT_ERROR_I18N_KEY = {
    NO_ACCESS_TOKEN: "ui:error.compact.no_token",
    INVALID_ACCESS_TOKEN: "ui:error.compact.invalid_token",
    STORE_UNAVAILABLE: "ui:error.compact.no_data",
    STORE_CREATION_FAILED: "",
    SOCKET_CONNECTION_FAILED: "ui:error.compact.no_connection",
    SENSECLOUD_CONNECTION_FAILED: "ui:error.compact.no_connection",
    CONTROLLER_CONNECTION_FAILED: "ui:error.compact.no_connection",
    HISTORIC_DATA_FAILED: "ui:error.compact.data_error",
    BACK_DOOR_CHECK_FAILED: "ui:error.compact.data_error",
    CONSOLE_INFO: "ui:error.compact.generic",
};
export const getCompactErrorMessage = (messageKey, locale) => {
    var _a;
    const key = messageKey !== null && messageKey !== void 0 ? messageKey : "CONSOLE_INFO";
    const i18nKey = (_a = COMPACT_ERROR_I18N_KEY[key]) !== null && _a !== void 0 ? _a : COMPACT_ERROR_I18N_KEY.CONSOLE_INFO;
    return i18n.t(i18nKey, { lng: getLocale(locale) });
};
const removeExistingErrorMessage = (container) => {
    const existingError = container.querySelector(`.${ERROR_MESSAGE_CLASS}`);
    if (existingError !== null) {
        existingError.remove();
    }
};
export const applyErrorMessage = (container, message) => {
    // Ensure only one overlay message exists at a time.
    removeExistingErrorMessage(container);
    const errorMessageElement = document.createElement("div");
    errorMessageElement.append(message);
    errorMessageElement.classList.add(ERROR_MESSAGE_CLASS);
    container.append(errorMessageElement);
    // Blur all sibling content while keeping the error text crisp.
    Array.from(container.children).forEach((child) => {
        if (!child.classList.contains(ERROR_MESSAGE_CLASS)) {
            child.classList.add(BLUR_CLASS);
            return;
        }
        if (child.classList.contains(ERROR_MESSAGE_CLASS)) {
            child.classList.remove(BLUR_CLASS);
        }
    });
};
export const clearErrorMessage = (container) => {
    // Restore original visuals and remove the temporary error overlay.
    Array.from(container.children).forEach((child) => {
        if (!child.classList.contains(ERROR_MESSAGE_CLASS)) {
            child.classList.remove(BLUR_CLASS);
        }
        if (child.classList.contains(ERROR_MESSAGE_CLASS)) {
            child.remove();
        }
    });
};
//# sourceMappingURL=error-message.js.map
