import React from "react";
export function optionValueKey(value) {
    if (typeof value === "string")
        return value;
    if (typeof value === "number" || typeof value === "boolean" || value == null)
        return String(value);
    try {
        return JSON.stringify(value);
    }
    catch {
        return String(value);
    }
}
export function optionLabelText(value) {
    if (typeof value === "string")
        return value;
    if (typeof value === "number")
        return String(value);
    if (Array.isArray(value))
        return value.map(optionLabelText).join("");
    if (React.isValidElement(value)) {
        return optionLabelText(value.props.children);
    }
    return "";
}
export function optionToSelectListOption(option, input = {}) {
    return {
        id: optionValueKey(option.value),
        label: optionLabelText(option.label) || optionValueKey(option.value),
        detail: option.description ?? "",
        description: option.type === "input" ? option.placeholder ?? "" : "",
        disabled: option.disabled,
        selected: input.selected ?? input.focused,
        tone: option.disabled ? "muted" : input.focused ? "brand" : undefined,
    };
}
