// TODO: The functions on this file are a WA until Chameleon 7 is released and we can reuse
// the existing functions from Chameleon. At the moment, we have to copy paste the functions
// because in Chameleon 6 we can import them.
// The following utils were copied from Chamelmeon (src/components/chat/utils.ts or src/common/utils.ts)
export const getMessageSerializedContentAll = (message) => typeof message.content === "string"
    ? message.content
    : JSON.stringify(message.content, undefined, 2);
export const getMessageContent = (message) => typeof message.content === "string"
    ? message.content
    : message.content.message;
/**
 * Converts an object mapping token keys to booleans into a space-separated
 * string containing the token keys that map to truthy values.
 * @example
 *   part={tokenMap({
 *     header: true,
 *     disabled: this.disabled,
 *     selected: this.selected,
 *     [levelPart]: canShowLines,
 *     "expand-button":
 *       canShowLines && !this.leaf && this.expandableButton !== "no"
 *   })}
 */
export const tokenMap = (tokens) => {
    const keys = Object.keys(tokens);
    let result = "";
    for (let index = 0; index < keys.length; index++) {
        const tokenKey = keys[index];
        const tokenValue = tokens[tokenKey];
        if (tokenValue) {
            result += result === "" ? tokenKey : ` ${tokenKey}`;
        }
    }
    return result;
};
export const copyToTheClipboard = (text) => navigator.clipboard.writeText(text);
export const copy = (text) => () => {
    copyToTheClipboard(text);
};
export const copyButtonClickHandler = (event, text) => {
    copyToTheClipboard(text);
    const button = event.currentTarget;
    if (button) {
        const buttonOriginalParts = button.getAttribute("part");
        const buttonWithCopyingParts = `${buttonOriginalParts} copying`;
        button.setAttribute("disabled", "disabled");
        button.setAttribute("part", buttonWithCopyingParts);
        setTimeout(() => {
            button.removeAttribute("disabled");
            button.setAttribute("part", buttonOriginalParts || "");
        }, 1500);
    }
};
export const DEFAULT_ASSISTANT_STATUS = "complete";
