/* STENCIL IMPORTS */
import { h } from "@stencil/core";
export const renderFormItems = (componentType = "gxg-combo-box-item", options, group = "undefined-group", callback) => {
    if (options.length) {
        const items = [];
        options.forEach(option => {
            let item;
            switch (componentType) {
                case "gxg-form-checkbox":
                    item = (h("gxg-form-checkbox", { checkboxId: option.id, checked: option.checked, disabled: option.disabled, label: option.label, value: option.value, onChange: callback ? callback : null, iconName: option.iconName, part: `${group}-${option.id}` }));
                    items.push(item);
                    break;
                case "gxg-combo-box-item":
                    item = (h("gxg-combo-box-item", { value: option.id, icon: option.iconName, part: `${group}-${option.id}` }, option.label));
                    items.push(item);
                    break;
                case "gxg-form-radio":
                    item = (h("gxg-form-radio", { radioId: option.id, checked: option.checked, disabled: option.disabled, label: option.label, value: option.value, name: group, part: `${group}-${option.id}` }));
                    items.push(item);
                    break;
                default:
                    break;
            }
        });
        return items;
    }
    return null;
};
/**
 * @param gxOptions An array of GxOptions's
 * @returns The first option in the array that is 'selected'. If no one found it returns null.
 */
export const getSelectedGxOption = (gxOptions, onlyId = true) => {
    if ((gxOptions === null || gxOptions === void 0 ? void 0 : gxOptions.length) > 0) {
        let found = null;
        for (let i = 0; i < gxOptions.length; i++) {
            if (gxOptions[i].selected) {
                found = gxOptions[i];
                break;
            }
        }
        if (found && onlyId) {
            return found.id;
        }
        else if (!found && onlyId) {
            return gxOptions[0].id;
        }
        return found;
    }
};
/**
 * @param gxOptions An array of GxOptions's
 * @returns The value of the selected item, or the first item, if no one is selected.
 */
export const getSelectedItem = (gxOptions) => {
    const found = gxOptions.find(item => item.selected);
    if (found) {
        return found.id;
    }
    else {
        return gxOptions[0].id;
    }
};
export const setSelectedItem = (gxOptions, selectedItemId) => gxOptions.map(item => (Object.assign(Object.assign({}, item), { selected: item.id === selectedItemId })));
export const getSelectedItem2 = (gxOptions) => {
    var _a;
    return gxOptions
        ? ((_a = gxOptions.find(item => item.selected)) !== null && _a !== void 0 ? _a : gxOptions[0]).id
        : undefined;
};
// Dots animation used in ch-chat code-render (or other components)
export const ANIMATION_DOTS = (size = "regular", color = "primary", sizeType = "dynamic", duration = "1s") => {
    const n = size === "regular" ? 1.5 : 4;
    let colorDot1, colorDot2, colorDot3;
    if (color === "nexa") {
        colorDot1 = "#5ba7ff";
        colorDot2 = "#00CCFF";
        colorDot3 = "#CF7AFF";
    }
    else if (color === "on-surface") {
        colorDot1 = colorDot2 = colorDot3 = "var(--color-text-neutral-strawberry)";
    }
    else {
        // primary
        colorDot1 = colorDot2 = colorDot3 = "var(--color-primary-600)"; // mer token
    }
    const animateRadiusSize = (begin = "0") => {
        return (h("animate", { attributeName: "r", values: `${2 / n};${4 / n};${2 / n}`, dur: duration, begin: begin, repeatCount: "indefinite" }));
    };
    return (h("svg", { width: 36 / n, height: 8 / n, fill: "transparent" }, h("circle", { cx: 4 / n, cy: 4 / n, r: 4 / n, opacity: "0", fill: colorDot1 }, h("animate", { attributeName: "opacity", values: "0;1;0", dur: duration, repeatCount: "indefinite" }), sizeType === "dynamic" ? animateRadiusSize("0") : null), h("circle", { cx: 18 / n, cy: 4 / n, r: 4 / n, opacity: "0", fill: colorDot2 }, h("animate", { attributeName: "opacity", values: "0;1;0", dur: duration, begin: "0.15s", repeatCount: "indefinite" }), sizeType === "dynamic" ? animateRadiusSize("0.33s") : null), h("circle", { cx: 32 / n, cy: 4 / n, r: 4 / n, opacity: "0", fill: colorDot3 }, h("animate", { attributeName: "opacity", values: "0;1;0", dur: duration, begin: "0.30s", repeatCount: "indefinite" }), sizeType === "dynamic" ? animateRadiusSize("0.66s") : null)));
};
//# sourceMappingURL=common.js.map
