"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__, {
    ResourceChipBase: ()=>ResourceChipBase,
    ResourceChipNodeView: ()=>ResourceChipNodeView
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const react_namespaceObject = require("@lingui/react");
const styles_namespaceObject = require("@mui/material/styles");
const external_tiptap_react_namespaceObject = require("@tiptap/react");
const apollo_core_namespaceObject = require("@uipath/apollo-core");
var apollo_core_default = /*#__PURE__*/ __webpack_require__.n(apollo_core_namespaceObject);
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const chat_state_provider_cjs_namespaceObject = require("../../../providers/chat-state-provider.cjs");
const index_cjs_namespaceObject = require("../../../service/index.cjs");
const font_by_variant_cjs_namespaceObject = require("../../../utils/font-by-variant.cjs");
const action_button_cjs_namespaceObject = require("../../common/action-button.cjs");
const tooltip_cjs_namespaceObject = require("../../common/tooltip.cjs");
const ChipContent = (0, styles_namespaceObject.styled)('span')(({ readonly })=>({
        display: 'inline-flex',
        alignItems: 'center',
        padding: `0 ${apollo_core_default().Padding.PadS}`,
        backgroundColor: 'var(--color-primary-lighter)',
        color: 'var(--color-foreground)',
        borderRadius: `calc(${apollo_core_default().Border.BorderRadiusL} * 2)`,
        verticalAlign: 'middle',
        ...!readonly && {
            cursor: 'default'
        },
        maxWidth: index_cjs_namespaceObject.CHAT_RESOURCE_CHIP_MAX_WIDTH,
        position: 'relative'
    }));
const ChipIcon = (0, styles_namespaceObject.styled)('span')(()=>({
        fontFamily: '"Material Icons Outlined"',
        fontSize: apollo_core_default().Icon.IconXs,
        flexShrink: 0,
        userSelect: 'none'
    }));
const ChipLabel = (0, styles_namespaceObject.styled)('span')(()=>({
        fontWeight: apollo_core_default().FontFamily.FontWeightSemibold,
        overflow: 'hidden',
        textOverflow: 'ellipsis',
        whiteSpace: 'nowrap',
        padding: `0 ${apollo_core_default().Padding.PadS}`
    }));
const ChipDeleteContainer = (0, styles_namespaceObject.styled)('span')(({ visible, compactMode })=>({
        opacity: visible ? 1 : 0,
        position: 'absolute',
        right: apollo_core_default().Spacing.SpacingMicro,
        top: '50%',
        transform: 'translateY(-50%)',
        display: 'flex',
        alignItems: 'center',
        backgroundColor: 'var(--color-primary-lighter)',
        borderRadius: `calc(${apollo_core_default().Border.BorderRadiusL} * 2)`,
        transition: 'opacity 0.15s ease-in-out',
        '& .MuiButtonBase-root.MuiButtonBase-root': {
            height: compactMode ? apollo_core_default().Spacing.SpacingS : apollo_core_default().Spacing.SpacingM,
            width: compactMode ? apollo_core_default().Spacing.SpacingS : apollo_core_default().Spacing.SpacingM,
            padding: 0,
            minWidth: 'unset',
            borderRadius: `calc(${apollo_core_default().Border.BorderRadiusL} * 2)`
        }
    }));
const ResourceChipBaseInner = ({ label, icon, readonly = false, onDelete })=>{
    const { _ } = (0, react_namespaceObject.useLingui)();
    const { spacing } = (0, chat_state_provider_cjs_namespaceObject.useChatState)();
    const [isHovered, setIsHovered] = external_react_default().useState(false);
    const [isFocused, setIsFocused] = external_react_default().useState(false);
    const handleDelete = external_react_default().useCallback((e)=>{
        e.preventDefault();
        e.stopPropagation();
        onDelete?.();
    }, [
        onDelete
    ]);
    const handleMouseEnter = external_react_default().useCallback(()=>setIsHovered(true), []);
    const handleMouseLeave = external_react_default().useCallback(()=>setIsHovered(false), []);
    const handleFocus = external_react_default().useCallback(()=>setIsFocused(true), []);
    const handleBlur = external_react_default().useCallback(()=>setIsFocused(false), []);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(ChipContent, {
        readonly: readonly,
        ...!readonly && {
            onMouseEnter: handleMouseEnter,
            onMouseLeave: handleMouseLeave
        },
        children: [
            icon && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ChipIcon, {
                "aria-hidden": true,
                children: icon
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(tooltip_cjs_namespaceObject.AutopilotChatTooltip, {
                title: label,
                placement: "top",
                disableInteractive: true,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ChipLabel, {
                    children: label
                })
            }),
            onDelete && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ChipDeleteContainer, {
                visible: isHovered || isFocused,
                compactMode: spacing.compactMode,
                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(action_button_cjs_namespaceObject.AutopilotChatActionButton, {
                    iconSize: spacing.compactMode ? apollo_core_default().Icon.IconXxs : apollo_core_default().Icon.IconXs,
                    iconName: "close",
                    tooltip: _({
                        id: 'autopilot-chat.common.attachments.remove-file'
                    }),
                    ariaLabel: _({
                        id: 'autopilot-chat.common.attachments.remove-file-name',
                        values: {
                            label: label
                        }
                    }),
                    onClick: handleDelete,
                    onFocus: handleFocus,
                    onBlur: handleBlur,
                    "data-testid": "resource-chip-delete"
                })
            })
        ]
    });
};
const ResourceChipBase = /*#__PURE__*/ external_react_default().memo(ResourceChipBaseInner);
ResourceChipBase.displayName = 'ResourceChipBase';
const ResourceChipNodeView = /*#__PURE__*/ external_react_default().memo(({ node, deleteNode })=>{
    const { label, icon } = node.attrs;
    const { spacing } = (0, chat_state_provider_cjs_namespaceObject.useChatState)();
    const lineHeight = (0, font_by_variant_cjs_namespaceObject.fontByVariant)(spacing.primaryFontToken)?.lineHeight ?? apollo_core_namespaceObject.Typography.fontSizeM.lineHeight;
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_tiptap_react_namespaceObject.NodeViewWrapper, {
        as: "span",
        style: {
            display: 'inline-flex',
            alignItems: 'center',
            height: lineHeight,
            lineHeight,
            verticalAlign: 'top',
            marginTop: apollo_core_default().Padding.PadXs
        },
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ResourceChipBase, {
            label: label,
            icon: icon,
            onDelete: deleteNode
        })
    });
});
ResourceChipNodeView.displayName = 'ResourceChipNodeView';
exports.ResourceChipBase = __webpack_exports__.ResourceChipBase;
exports.ResourceChipNodeView = __webpack_exports__.ResourceChipNodeView;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "ResourceChipBase",
    "ResourceChipNodeView"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
