(() => {
    const Shared = window.FotogenicAI?.Shared;
    if (!Shared?.ui) return;

    const names = Object.freeze([
        'arrow-left',
        'arrow-right',
        'arrow-square-out',
        'arrow-square-up',
        'arrows-clockwise',
        'arrows-out',
        'bell',
        'caret-down',
        'check',
        'check-circle',
        'clock',
        'clock-counter-clockwise',
        'coins',
        'credit-card',
        'download-simple',
        'folder-open',
        'funnel',
        'gear-six',
        'gift',
        'image-square',
        'images',
        'info',
        'list',
        'magic-wand',
        'magnifying-glass',
        'package',
        'pause',
        'pause-circle',
        'play',
		'plus',
        'rows',
        'shield-check',
        'sign-in',
        'sign-out',
        'sliders-horizontal',
        'sparkle',
        'squares-four',
        'stack-simple',
        'stop',
        'stop-circle',
        'trash',
        'upload-simple',
        'user-circle',
        'user-square',
        'warning',
        'warning-circle',
        'x',
    ]);
    const weights = Object.freeze(['regular', 'bold', 'fill']);
    const sizes = Object.freeze([12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 30]);
    const nameSet = new Set(names);
    const weightSet = new Set(weights);
    const sizeSet = new Set(sizes);

    const validate = (name, weight, size) => {
        if (!nameSet.has(name)) throw new TypeError(`Unsupported Fotogenic icon: ${String(name)}`);
        if (!weightSet.has(weight)) throw new TypeError(`Unsupported Fotogenic icon weight: ${String(weight)}`);
        if (!sizeSet.has(size)) throw new TypeError(`Unsupported Fotogenic icon size: ${String(size)}`);
    };

    const update = (node, name, { weight = 'regular', size } = {}) => {
        if (!node || node.nodeType !== 1) throw new TypeError('A Fotogenic icon element is required.');
        validate(name, weight, size);
        names.forEach((candidate) => node.classList.remove(`fotogenic-ai-icon--${candidate}`));
        weights.forEach((candidate) => node.classList.remove(`fotogenic-ai-icon--${candidate}`));
        sizes.forEach((candidate) => node.classList.remove(`fotogenic-ai-icon--size-${candidate}`));
        node.classList.add(
            'fotogenic-ai-icon',
            `fotogenic-ai-icon--${name}`,
            `fotogenic-ai-icon--${weight}`,
            `fotogenic-ai-icon--size-${size}`
        );
        node.setAttribute('aria-hidden', 'true');
        node.dataset.faIcon = name;
        node.dataset.faIconWeight = weight;
        node.dataset.faIconSize = String(size);
        return node;
    };

    const create = (name, options) => update(document.createElement('span'), name, options);

    Shared.ui.icon = Object.freeze({
        create,
        names,
        sizes,
        update,
        weights,
    });
})();
