"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__, {
    ApTreeItem: ()=>ApTreeItem,
    ApTreeView: ()=>ApTreeView
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const ChevronRight_namespaceObject = require("@mui/icons-material/ChevronRight");
var ChevronRight_default = /*#__PURE__*/ __webpack_require__.n(ChevronRight_namespaceObject);
const material_namespaceObject = require("@mui/material");
const styles_namespaceObject = require("@mui/material/styles");
const x_tree_view_namespaceObject = require("@mui/x-tree-view");
const hooks_namespaceObject = require("@mui/x-tree-view/hooks");
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 index_cjs_namespaceObject = require("../ap-typography/index.cjs");
const external_utils_cjs_namespaceObject = require("./utils.cjs");
const ICON_SIZE = parseInt(apollo_core_default().Spacing.SpacingM, 10);
const CHEVRON_ICON_SIZE = ICON_SIZE;
const ICON_GAP = parseInt(apollo_core_default().Spacing.SpacingS, 10);
const StyledTreeItem = (0, styles_namespaceObject.styled)(x_tree_view_namespaceObject.TreeItem, {
    shouldForwardProp: (prop)=>'levelPadding' !== prop && 'disableExpandCollapse' !== prop
})(({ disableExpandCollapse })=>({
        '.MuiTreeItem-content': {
            position: 'relative',
            color: 'var(--color-foreground)',
            borderRadius: 0,
            height: apollo_core_default().Spacing.SpacingXl,
            '&.Mui-selected': {
                backgroundColor: 'var(--color-background-selected)',
                '&::before': {
                    content: '""',
                    position: 'absolute',
                    top: 0,
                    left: 0,
                    bottom: 0,
                    backgroundColor: 'var(--color-selection-indicator)',
                    width: apollo_core_default().Spacing.SpacingXs
                },
                '&:hover': {
                    backgroundColor: 'var(--color-background-selected)'
                }
            },
            '&:hover:not(.Mui-disabled)': {
                backgroundColor: 'var(--color-background-hover)'
            },
            '.MuiTreeItem-iconContainer': {
                display: disableExpandCollapse ? 'none' : 'flex',
                width: `${ICON_SIZE}px`,
                height: `${ICON_SIZE}px`,
                '& > svg': {
                    fontSize: `${ICON_SIZE}px !important`
                }
            }
        },
        '.MuiCollapse-root': {
            paddingLeft: 0,
            '.MuiTreeItem-content': {
                paddingLeft: 'var(--ap-tree-level-padding) !important'
            }
        },
        '&:focus-visible > .MuiTreeItem-content': {
            zIndex: 1,
            outline: `${apollo_core_default().Border.BorderThickS} solid var(--color-focus-indicator)`
        }
    }));
const ApTreeItemParentContext = /*#__PURE__*/ (0, external_react_namespaceObject.createContext)({
    level: 0,
    hasIcon: false,
    levelPadding: 0
});
const ApTreeItem = ({ itemId, children, disableExpandCollapse, showSelectedChevron })=>{
    const item = (0, hooks_namespaceObject.useTreeItemModel)(itemId);
    const { status, interactions } = (0, hooks_namespaceObject.useTreeItemUtils)({
        itemId,
        children
    });
    const parentContext = (0, external_react_namespaceObject.useContext)(ApTreeItemParentContext);
    const { id = itemId, title = '', description, icon, iconColor, disabled, children: descendants, additionalInfo, titleColor } = item || {};
    const canExpand = status.expandable;
    const isItemExpanded = status.expanded;
    const isItemSelected = status.selected;
    const canSelect = !status.disabled;
    const hasChildren = !!descendants?.length;
    const currentItemContext = (0, external_react_namespaceObject.useMemo)(()=>{
        const level = parentContext.level + 1;
        return {
            level,
            levelPadding: parentContext.levelPadding + (level > 1 ? CHEVRON_ICON_SIZE + ICON_SIZE : 0) - (hasChildren ? 0 : CHEVRON_ICON_SIZE),
            hasIcon: Boolean(icon)
        };
    }, [
        parentContext,
        icon,
        hasChildren
    ]);
    const { levelPadding } = currentItemContext;
    const handleKeyDown = (0, external_react_namespaceObject.useCallback)((e)=>{
        e.defaultMuiPrevented = true;
        if (e.currentTarget !== e.target) return;
        if (' ' === e.key && canSelect) {
            e.preventDefault();
            interactions.handleSelection(e);
        } else if ('Enter' === e.key) {
            if (canExpand) {
                interactions.handleExpansion(e);
                e.preventDefault();
            } else if (canSelect) {
                interactions.handleSelection(e);
                e.preventDefault();
            }
        } else if ('ArrowRight' === e.key) {
            if (!isItemExpanded) interactions.handleExpansion(e);
            e.preventDefault();
        } else if ('ArrowLeft' === e.key) {
            if (isItemExpanded) interactions.handleExpansion(e);
            e.preventDefault();
        }
    }, [
        canSelect,
        canExpand,
        interactions,
        isItemExpanded
    ]);
    const label = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(material_namespaceObject.Tooltip, {
        title: description || '',
        arrow: true,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(material_namespaceObject.Box, {
            sx: {
                display: 'flex',
                width: '100%',
                alignItems: 'center',
                justifyContent: 'space-between'
            },
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(material_namespaceObject.Box, {
                    sx: {
                        display: 'flex',
                        alignItems: 'center',
                        gap: `${ICON_GAP}px`
                    },
                    children: [
                        icon && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(material_namespaceObject.Box, {
                            component: "span",
                            sx: {
                                display: 'inline-flex',
                                alignItems: 'center',
                                width: `${ICON_SIZE}px`,
                                height: `${ICON_SIZE}px`,
                                color: iconColor || 'inherit'
                            },
                            children: icon
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.ApTypography, {
                            variant: apollo_core_namespaceObject.FontVariantToken.fontSizeM,
                            style: {
                                whiteSpace: 'nowrap',
                                overflow: 'hidden',
                                textOverflow: 'ellipsis',
                                color: titleColor || void 0
                            },
                            children: title
                        })
                    ]
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(material_namespaceObject.Box, {
                    sx: {
                        display: 'flex',
                        alignItems: 'center',
                        gap: apollo_core_default().Spacing.SpacingXs
                    },
                    children: [
                        additionalInfo && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.ApTypography, {
                            variant: apollo_core_namespaceObject.FontVariantToken.fontSizeM,
                            style: {
                                color: 'var(--color-foreground-de-emp)',
                                whiteSpace: 'nowrap'
                            },
                            children: additionalInfo
                        }),
                        showSelectedChevron && isItemSelected && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ChevronRight_default(), {
                            sx: {
                                fontSize: ICON_SIZE,
                                color: 'var(--color-foreground-de-emp)'
                            }
                        })
                    ]
                })
            ]
        })
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(ApTreeItemParentContext.Provider, {
        value: currentItemContext,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(StyledTreeItem, {
            levelPadding: levelPadding,
            "data-is-focusable": !disabled,
            style: {
                '--ap-tree-level-padding': `${levelPadding}px`
            },
            onKeyDown: handleKeyDown,
            itemId: id,
            label: label,
            disableExpandCollapse: disableExpandCollapse,
            disabled: disabled,
            "data-test": `ap-tree-item-${id}`,
            role: "treeitem",
            children: children
        }, id)
    });
};
const getItemLabel = (item)=>item.title;
const isItemDisabled = (item)=>!!item.disabled;
const ApTreeView = /*#__PURE__*/ external_react_default().forwardRef(({ items = [], selectedItemId, expanded, disableExpandCollapse, showSelectedChevron, onSelectedItemsChange, useApIcon = false, ...restProps }, ref)=>{
    const [expandedItems, setExpandedItems] = (0, external_react_namespaceObject.useState)(()=>expanded && 'boolean' == typeof expanded || disableExpandCollapse ? (0, external_utils_cjs_namespaceObject.recursivelyExpand)(items) : [
            ...expanded || []
        ]);
    const handleOnSelectedItemsChange = (0, external_react_namespaceObject.useCallback)((_, itemId)=>{
        if (null == itemId) return void onSelectedItemsChange?.(void 0);
        const selectedItemResult = (0, external_utils_cjs_namespaceObject.deepFind)(items, (item)=>itemId === item.id);
        if (selectedItemResult) onSelectedItemsChange?.(selectedItemResult.id);
    }, [
        items,
        onSelectedItemsChange
    ]);
    const onExpandedItemsChange = (0, external_react_namespaceObject.useCallback)((_e, itemIds)=>{
        if (disableExpandCollapse) return;
        setExpandedItems(itemIds);
    }, [
        disableExpandCollapse
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
        ref: ref,
        role: "tree",
        ...restProps,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(x_tree_view_namespaceObject.RichTreeView, {
            items: items,
            selectedItems: selectedItemId ?? null,
            expandedItems: expandedItems,
            getItemLabel: getItemLabel,
            onSelectedItemsChange: handleOnSelectedItemsChange,
            onExpandedItemsChange: onExpandedItemsChange,
            isItemDisabled: isItemDisabled,
            slots: {
                item: ApTreeItem
            },
            slotProps: {
                item: {
                    disableExpandCollapse,
                    showSelectedChevron,
                    useApIcon
                }
            }
        })
    });
});
ApTreeView.displayName = 'ApTreeView';
exports.ApTreeItem = __webpack_exports__.ApTreeItem;
exports.ApTreeView = __webpack_exports__.ApTreeView;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "ApTreeItem",
    "ApTreeView"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
