import { buildCustomEvent } from "../../../utils/event-utils.js";
const dispatchNumberFormatEvent = async (formatter, element)=>{
    const event = buildCustomEvent('atomic/numberFormat', formatter);
    const tagName = element.parentElement?.tagName.toLowerCase();
    if (tagName?.includes('atomic-')) await customElements.whenDefined(tagName);
    if (element.parentElement && 'updateComplete' in element.parentElement) await element.parentElement.updateComplete;
    else if ('componentOnReady' in element.parentElement) await element.parentElement.componentOnReady();
    const handled = !element.dispatchEvent(event);
    if (!handled) throw new Error('The Atomic number format component was not handled, as it is not a child of a compatible component');
};
const defaultNumberFormatter = (value, languages)=>value.toLocaleString(languages);
const defaultCurrencyFormatter = (currency)=>(value, languages)=>value.toLocaleString(languages, {
            style: 'currency',
            currency
        });
export { defaultCurrencyFormatter, defaultNumberFormatter, dispatchNumberFormatEvent };
