/*!
 * KoliBri - The accessible HTML-Standard
 */
import { Log, getDocument, isTestMode, setColorContrastAnalysis, setExperimentalMode } from "../schema";
import { Env } from "@stencil/core";
import { getWindow } from "../schema";
const initMeta = () => {
    try {
        const document = getDocument();
        if (!document || typeof document.querySelector !== 'function') {
            return;
        }
        const meta = document.querySelector('meta[name="kolibri"]');
        if (meta && meta.hasAttribute('content')) {
            const content = meta.getAttribute('content');
            if (typeof content === 'string') {
                setExperimentalMode(content.includes('experimental-mode=true'));
                setColorContrastAnalysis(content.includes('color-contrast-analysis=true'));
            }
        }
    }
    catch (_a) {
    }
};
const getKoliBri = () => {
    let kolibri = getWindow().KoliBri;
    if (kolibri === undefined) {
        kolibri = {};
        Object.defineProperty(getWindow(), 'KoliBri', {
            value: kolibri,
            writable: false,
        });
    }
    return kolibri;
};
export { getKoliBri };
export const initKoliBri = () => {
    initMeta();
    Log.debug(`
,--. ,--.         ,--. ,--. ,-----.           ,--.
|  .'   /  ,---.  |  | \`--' |  |) /_  ,--.--. \`--'
|  .   '  | .-. | |  | ,--. |  .-.  \\ |  .--' ,--.
|  |\\   \\ | '-' | |  | |  | |  '--' / |  |    |  |
\`--' \`--´  \`---´  \`--' \`--' \`------´  \`--'    \`--'
🚹 The accessible HTML-Standard | 👉 https://public-ui.github.io | ${Env.kolibriVersion}
	`, {
        forceLog: true,
    });
};
export const renderDevAdvice = () => {
    if (getKoliBri().adviceShown !== true) {
        Object.defineProperty(getKoliBri(), 'adviceShown', {
            get: function () {
                return true;
            },
        });
        Log.debug(`
You are using the KoliBri component library. If you have any suggestions for improvement or find a problem, please contact us:

Ticket: https://github.com/public-ui/kolibri/issues/new/choose (for privacy reasons, please use email)
Email: kolibri@itzbund.de
`);
    }
};
let nonce = () => Math.floor(Math.random() * 16777215).toString(16);
if (isTestMode()) {
    nonce = () => 'nonce';
}
export { nonce };
export const createUniqueId = (prefix) => `${prefix}-${nonce()}`;
export const createRelatedUniqueId = (baseId, suffix) => {
    const separatorIndex = baseId.lastIndexOf('-');
    if (separatorIndex === -1)
        return `${baseId}-${suffix}`;
    const lastSegment = baseId.slice(separatorIndex + 1);
    const isNonce = lastSegment === 'nonce' || /^[0-9a-f]+$/.test(lastSegment);
    return isNonce ? `${baseId.slice(0, separatorIndex)}-${suffix}-${lastSegment}` : `${baseId}-${suffix}`;
};
//# sourceMappingURL=dev.utils.js.map
