import { getRichTextProfile } from "../../services/contentService";
import { getCachedParsedProfile } from "./utils/profileServiceCache";
const SUPPORTED_BRIDGE_MARKS = new Set([
    "bold",
    "italic",
    "underline",
    "strikethrough",
    "subscript",
    "superscript",
]);
export function getExecCommandForMark(markId) {
    switch (markId) {
        case "bold":
            return "bold";
        case "italic":
            return "italic";
        case "underline":
            return "underline";
        case "strikethrough":
            return "strikeThrough";
        case "subscript":
            return "subscript";
        case "superscript":
            return "superscript";
        default:
            return undefined;
    }
}
function getExecCommandForList(listId) {
    switch (listId) {
        case "ordered-list":
            return "insertOrderedList";
        case "unordered-list":
            return "insertUnorderedList";
        default:
            return undefined;
    }
}
export async function loadParsedRichTextProfile(field) {
    const richTextField = field;
    const profilePath = richTextField.customProperties?.profile;
    const contextItemId = field.descriptor.item.id;
    const serviceCall = (path) => getRichTextProfile(path, contextItemId);
    return getCachedParsedProfile(profilePath, serviceCall);
}
export function getBridgeRichTextProfileGroups(profile) {
    if (!profile?.toolbar?.groups) {
        return [];
    }
    const groups = [];
    let hasLinkOption = false;
    for (const group of profile.toolbar.groups) {
        if (!group.options || group.options.length === 0)
            continue;
        const options = [];
        for (const option of group.options) {
            if (option.type === "mark") {
                if (!SUPPORTED_BRIDGE_MARKS.has(option.id))
                    continue;
                const command = getExecCommandForMark(option.id);
                if (!command)
                    continue;
                options.push({
                    type: "mark",
                    id: option.id,
                    command,
                });
            }
            else if (option.type === "list") {
                const command = getExecCommandForList(option.id);
                if (!command)
                    continue;
                options.push({
                    type: "list",
                    id: option.id,
                    command,
                });
            }
            else if (option.type === "link" && !hasLinkOption) {
                hasLinkOption = true;
                options.push({
                    type: "link",
                    id: "link",
                });
            }
        }
        if (options.length > 0) {
            groups.push({
                id: group.id,
                options,
            });
        }
    }
    return groups;
}
//# sourceMappingURL=bridgeRichTextProfile.js.map