"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = (module)=>{
        var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = (exports1, definition)=>{
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
    __webpack_require__.r = (exports1)=>{
        if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    FULL_OPTION_HEIGHT: ()=>FULL_OPTION_HEIGHT,
    defaultRowActions: ()=>defaultRowActions,
    DENSE_OPTION_HEIGHT: ()=>DENSE_OPTION_HEIGHT,
    ModelOptionRow: ()=>ModelOptionRow
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const EditOutlined_namespaceObject = require("@mui/icons-material/EditOutlined");
var EditOutlined_default = /*#__PURE__*/ __webpack_require__.n(EditOutlined_namespaceObject);
const Box_namespaceObject = require("@mui/material/Box");
var Box_default = /*#__PURE__*/ __webpack_require__.n(Box_namespaceObject);
const ButtonBase_namespaceObject = require("@mui/material/ButtonBase");
var ButtonBase_default = /*#__PURE__*/ __webpack_require__.n(ButtonBase_namespaceObject);
const IconButton_namespaceObject = require("@mui/material/IconButton");
var IconButton_default = /*#__PURE__*/ __webpack_require__.n(IconButton_namespaceObject);
const Tooltip_namespaceObject = require("@mui/material/Tooltip");
var Tooltip_default = /*#__PURE__*/ __webpack_require__.n(Tooltip_namespaceObject);
const Typography_namespaceObject = require("@mui/material/Typography");
var Typography_default = /*#__PURE__*/ __webpack_require__.n(Typography_namespaceObject);
const apollo_core_namespaceObject = require("@uipath/apollo-core");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const external_ModelTagChip_cjs_namespaceObject = require("../ModelTagChip.cjs");
const external_utils_cjs_namespaceObject = require("../utils.cjs");
const FULL_OPTION_HEIGHT = 64;
const DENSE_OPTION_HEIGHT = 44;
function formatContextWindow(tokens) {
    if (null == tokens || tokens <= 0) return null;
    if (tokens >= 1000000) {
        const m = tokens / 1000000;
        return `${m % 1 === 0 ? m.toFixed(0) : m.toFixed(1)}M context`;
    }
    if (tokens >= 1000) {
        const k = Math.round(tokens / 1000);
        return `${k}K context`;
    }
    return `${tokens} context`;
}
const ModelOptionRowInner = ({ model, index, active, selected, onSelect, onActivate, tagContext, tagVariants, renderActions, renderMeta, dense, hideTagKinds, id, 'data-testid': dataTestId })=>{
    const inlineTags = (0, external_utils_cjs_namespaceObject.deriveModelTags)(model, tagContext ?? {}).filter((t)=>!hideTagKinds?.includes(t.kind));
    const primaryLabel = model.displayName ?? null;
    const primary = primaryLabel ?? model.modelName;
    const usesFriendlyName = !!primaryLabel && primaryLabel !== model.modelId;
    const techId = usesFriendlyName ? model.modelId : null;
    const minHeight = dense ? DENSE_OPTION_HEIGHT : FULL_OPTION_HEIGHT;
    const contextLabel = formatContextWindow(model.modelDetails?.contextWindowTokens);
    const rowActions = renderActions ? renderActions(model) : null;
    const meta = renderMeta?.(model);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(ButtonBase_default(), {
        component: "div",
        id: id,
        role: "option",
        "aria-selected": selected,
        "data-testid": dataTestId,
        tabIndex: -1,
        onClick: ()=>onSelect(model),
        onMouseEnter: onActivate ? ()=>onActivate(index) : void 0,
        sx: {
            width: '100%',
            minHeight,
            px: dense ? 1.5 : 1.75,
            py: dense ? 0.875 : 1.375,
            display: 'flex',
            alignItems: 'flex-start',
            gap: dense ? 1 : 1.5,
            justifyContent: 'flex-start',
            textAlign: 'left',
            position: 'relative',
            boxShadow: selected ? `inset 3px 0px 0px var(--color-primary, ${apollo_core_namespaceObject.Colors.ColorBlue500})` : 'none',
            backgroundColor: selected ? `var(--color-background-selected, ${apollo_core_namespaceObject.Colors.ColorBlue050})` : active ? "var(--color-background-hover, rgba(82, 96, 105, 0.078))" : 'transparent',
            '&:hover': {
                backgroundColor: selected ? `var(--color-background-selected, ${apollo_core_namespaceObject.Colors.ColorBlue050})` : "var(--color-background-hover, rgba(82, 96, 105, 0.078))"
            }
        },
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(Box_default(), {
                sx: {
                    flex: 1,
                    minWidth: 0
                },
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(Box_default(), {
                        sx: {
                            display: 'flex',
                            alignItems: 'center',
                            gap: 0.75,
                            flexWrap: 'nowrap',
                            minWidth: 0
                        },
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Typography_default(), {
                                variant: "body2",
                                sx: {
                                    fontWeight: 600,
                                    color: `var(--color-foreground, ${apollo_core_namespaceObject.Colors.ColorGray850})`,
                                    lineHeight: 1.3,
                                    fontSize: dense ? 13 : 14,
                                    whiteSpace: 'nowrap',
                                    overflow: 'hidden',
                                    textOverflow: 'ellipsis',
                                    flex: '0 1 auto',
                                    minWidth: 0
                                },
                                children: primary
                            }),
                            inlineTags.map((t)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Box_default(), {
                                    sx: {
                                        flexShrink: 0
                                    },
                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_ModelTagChip_cjs_namespaceObject.ModelTagChip, {
                                        tag: t,
                                        variants: tagVariants
                                    })
                                }, `${t.kind}-${t.label}`))
                        ]
                    }),
                    techId && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Typography_default(), {
                        variant: "caption",
                        sx: {
                            display: 'block',
                            color: `var(--color-foreground-de-emp, ${apollo_core_namespaceObject.Colors.ColorGray550})`,
                            mt: 0.25,
                            fontFamily: apollo_core_namespaceObject.FontFamily.FontMono,
                            fontSize: 11,
                            whiteSpace: 'nowrap',
                            overflow: 'hidden',
                            textOverflow: 'ellipsis'
                        },
                        children: techId
                    }),
                    model.byoConnectionLabel && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Typography_default(), {
                        variant: "caption",
                        sx: {
                            display: 'block',
                            color: `var(--color-foreground-de-emp, ${apollo_core_namespaceObject.Colors.ColorGray550})`,
                            mt: techId ? 0 : 0.25,
                            fontSize: 12,
                            whiteSpace: 'nowrap',
                            overflow: 'hidden',
                            textOverflow: 'ellipsis',
                            maxWidth: '100%'
                        },
                        children: model.byoConnectionLabel
                    })
                ]
            }),
            (contextLabel ?? meta) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(Box_default(), {
                sx: {
                    flexShrink: 0,
                    display: 'flex',
                    flexDirection: 'column',
                    alignItems: 'flex-end',
                    gap: 0.5,
                    pt: 0.125
                },
                onClick: (e)=>e.stopPropagation(),
                children: [
                    contextLabel && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Typography_default(), {
                        variant: "caption",
                        sx: {
                            color: `var(--color-foreground-de-emp, ${apollo_core_namespaceObject.Colors.ColorGray550})`,
                            fontSize: 11,
                            lineHeight: 1.2
                        },
                        children: contextLabel
                    }),
                    meta
                ]
            }),
            rowActions && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Box_default(), {
                sx: {
                    display: 'flex',
                    alignItems: 'center',
                    gap: 0.25,
                    color: `var(--color-foreground-de-emp, ${apollo_core_namespaceObject.Colors.ColorGray550})`,
                    flexShrink: 0,
                    pt: 0.125
                },
                onClick: (e)=>e.stopPropagation(),
                children: rowActions
            })
        ]
    });
};
const ModelOptionRow = /*#__PURE__*/ external_react_default().memo(ModelOptionRowInner);
ModelOptionRow.displayName = 'ModelOptionRow';
function defaultRowActions(model, options = {}) {
    const { i18n, onEdit } = options;
    if (!onEdit) return null;
    const isByo = 'BYOMAdded' === model.modelSubscriptionType || 'BYOMReplacedAlternative' === model.modelSubscriptionType || 'BYOMReplacedLikeForLike' === model.modelSubscriptionType;
    if (!isByo) return null;
    const editTitle = i18n ? i18n._({
        id: 'modelPicker.row.editConfiguration',
        message: 'Edit configuration'
    }) : 'Edit configuration';
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(Tooltip_default(), {
        title: editTitle,
        arrow: true,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(IconButton_default(), {
            size: "small",
            sx: {
                color: 'inherit'
            },
            "aria-label": editTitle,
            onClick: ()=>onEdit(model),
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(EditOutlined_default(), {
                fontSize: "small"
            })
        })
    });
}
exports.DENSE_OPTION_HEIGHT = __webpack_exports__.DENSE_OPTION_HEIGHT;
exports.FULL_OPTION_HEIGHT = __webpack_exports__.FULL_OPTION_HEIGHT;
exports.ModelOptionRow = __webpack_exports__.ModelOptionRow;
exports.defaultRowActions = __webpack_exports__.defaultRowActions;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "DENSE_OPTION_HEIGHT",
    "FULL_OPTION_HEIGHT",
    "ModelOptionRow",
    "defaultRowActions"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
