"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    NodePropertyTriggerSectionLabel: ()=>NodePropertyTriggerSectionLabel,
    NodePropertyTriggerSeparator: ()=>NodePropertyTriggerSeparator,
    NodePropertyTriggerCheckboxItem: ()=>NodePropertyTriggerCheckboxItem,
    NodePropertyTriggerRadioItem: ()=>NodePropertyTriggerRadioItem,
    NodePropertyTrigger: ()=>NodePropertyTrigger
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const apollo_wind_namespaceObject = require("@uipath/apollo-wind");
const external_react_namespaceObject = require("react");
const index_cjs_namespaceObject = require("../../../i18n/index.cjs");
const icon_registry_cjs_namespaceObject = require("../../utils/icon-registry.cjs");
function clampToOptions(value, options) {
    return options.some((option)=>option.value === value) ? value : options[0]?.value ?? value;
}
const defaultBehaviorOptions = (_)=>[
        {
            value: 'auto-hide',
            label: _({
                id: 'canvas.property_trigger.auto_hide',
                message: 'Auto hide'
            })
        },
        {
            value: 'always-persist',
            label: _({
                id: 'canvas.property_trigger.always_persist',
                message: 'Always persist'
            })
        }
    ];
const defaultLayoutOptions = (_)=>[
        {
            value: 'right',
            label: _({
                id: 'canvas.property_trigger.layout_right',
                message: 'Default — Right'
            })
        },
        {
            value: 'bottom',
            label: _({
                id: 'canvas.property_trigger.layout_bottom',
                message: 'Default — Bottom'
            })
        },
        {
            value: 'split',
            label: _({
                id: 'canvas.property_trigger.layout_split',
                message: 'Default — Split'
            })
        }
    ];
const ROW_CLASS = 'group justify-between gap-2 rounded-none px-3 py-2 text-xs text-foreground-muted focus:bg-surface-overlay focus:text-foreground';
const DOT_CLASS = 'size-2 shrink-0 rounded-full bg-surface-overlay group-data-[state=checked]:bg-foreground-accent';
const HIDE_LEFT_INDICATOR_CLASS = '[&>span:first-child]:hidden';
function NodePropertyTriggerSectionLabel({ className, ...props }) {
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.DropdownMenuLabel, {
        className: (0, apollo_wind_namespaceObject.cn)('px-3 pb-1 pt-2 text-[10px] font-semibold uppercase tracking-wide text-foreground-subtle', className),
        ...props
    });
}
function NodePropertyTriggerSeparator({ className, ...props }) {
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.DropdownMenuSeparator, {
        className: (0, apollo_wind_namespaceObject.cn)('mx-0 my-0 bg-border-subtle', className),
        ...props
    });
}
function NodePropertyTriggerCheckboxItem({ className, children, closeOnSelect = false, onSelect, ...props }) {
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(apollo_wind_namespaceObject.DropdownMenuCheckboxItem, {
        className: (0, apollo_wind_namespaceObject.cn)(ROW_CLASS, HIDE_LEFT_INDICATOR_CLASS, className),
        onSelect: (e)=>{
            if (!closeOnSelect) e.preventDefault();
            onSelect?.(e);
        },
        ...props,
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                className: "min-w-0 flex-1 truncate",
                children: children
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                className: DOT_CLASS
            })
        ]
    });
}
function NodePropertyTriggerRadioItem({ className, children, ...props }) {
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(apollo_wind_namespaceObject.DropdownMenuRadioItem, {
        className: (0, apollo_wind_namespaceObject.cn)(ROW_CLASS, HIDE_LEFT_INDICATOR_CLASS, className),
        ...props,
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                className: "min-w-0 flex-1 truncate",
                children: children
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                className: DOT_CLASS
            })
        ]
    });
}
function NodePropertyTrigger({ label, className, showMenu = true, open, onOpenChange, menuAriaLabel, children, onPropertiesClick, panels = [], behavior, behaviorOptions, layout, layoutOptions, presets = [], onBehaviorChange, onLayoutChange, onPanelToggle, onPresetApply, onPresetRename, onPresetDelete, onSavePreset, canSavePreset = false }) {
    const { _ } = (0, index_cjs_namespaceObject.useSafeLingui)();
    const resolvedLabel = label ?? _({
        id: 'canvas.property_trigger.properties',
        message: 'Properties'
    });
    const resolvedMenuAriaLabel = menuAriaLabel ?? _({
        id: 'canvas.property_trigger.panel_options',
        message: 'Panel options'
    });
    const resolvedBehaviorOptions = behaviorOptions ?? defaultBehaviorOptions(_);
    const resolvedLayoutOptions = layoutOptions ?? defaultLayoutOptions(_);
    const labelBaseClassName = 'flex h-8 items-center rounded-lg px-2.5 text-xs font-medium text-foreground-muted transition';
    const [internalBehavior, setInternalBehavior] = (0, external_react_namespaceObject.useState)(()=>resolvedBehaviorOptions[0]?.value ?? 'auto-hide');
    const [internalLayout, setInternalLayout] = (0, external_react_namespaceObject.useState)(()=>resolvedLayoutOptions[0]?.value ?? 'right');
    const effectiveBehavior = behavior ?? clampToOptions(internalBehavior, resolvedBehaviorOptions);
    const effectiveLayout = layout ?? clampToOptions(internalLayout, resolvedLayoutOptions);
    const handleBehaviorChange = (0, external_react_namespaceObject.useCallback)((val)=>{
        if (onBehaviorChange) onBehaviorChange(val);
        else setInternalBehavior(val);
    }, [
        onBehaviorChange
    ]);
    const handleLayoutChange = (0, external_react_namespaceObject.useCallback)((val)=>{
        if (onLayoutChange) onLayoutChange(val);
        else setInternalLayout(val);
    }, [
        onLayoutChange
    ]);
    const sections = [];
    if (panels.length > 0) sections.push({
        key: 'panels',
        node: panels.map(({ id, label: panelLabel, enabled })=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(NodePropertyTriggerCheckboxItem, {
                checked: !!enabled,
                onCheckedChange: (checked)=>onPanelToggle?.(id ?? panelLabel, true === checked),
                children: panelLabel
            }, id ?? panelLabel))
    });
    if (resolvedBehaviorOptions.length > 0) sections.push({
        key: 'behavior',
        node: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(NodePropertyTriggerSectionLabel, {
                    children: _({
                        id: 'canvas.property_trigger.panel_behavior',
                        message: 'Panel behavior'
                    })
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.DropdownMenuRadioGroup, {
                    value: effectiveBehavior,
                    onValueChange: handleBehaviorChange,
                    children: resolvedBehaviorOptions.map(({ value, label: behaviorLabel })=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(NodePropertyTriggerRadioItem, {
                            value: value,
                            children: behaviorLabel
                        }, value))
                })
            ]
        })
    });
    if (resolvedLayoutOptions.length > 0) sections.push({
        key: 'layouts',
        node: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(NodePropertyTriggerSectionLabel, {
                    children: _({
                        id: 'canvas.property_trigger.default_layouts',
                        message: 'Default layouts'
                    })
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.DropdownMenuRadioGroup, {
                    value: effectiveLayout,
                    onValueChange: handleLayoutChange,
                    children: resolvedLayoutOptions.map(({ value, label: layoutLabel })=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(NodePropertyTriggerRadioItem, {
                            value: value,
                            children: layoutLabel
                        }, value))
                })
            ]
        })
    });
    if (presets.length > 0 || canSavePreset) sections.push({
        key: 'presets',
        node: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
            children: [
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(NodePropertyTriggerSectionLabel, {
                    children: _({
                        id: 'canvas.property_trigger.saved_presets',
                        message: 'Saved presets'
                    })
                }),
                0 === presets.length && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("p", {
                    className: "px-3 pb-2 text-[11px] text-foreground-subtle",
                    children: _({
                        id: 'canvas.property_trigger.no_saved_presets',
                        message: 'No saved presets yet.'
                    })
                }),
                presets.map((preset)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(apollo_wind_namespaceObject.DropdownMenuItem, {
                        "aria-label": _({
                            id: 'canvas.property_trigger.apply_preset_with_label',
                            message: 'Apply {label}',
                            values: {
                                label: preset.label
                            }
                        }),
                        className: (0, apollo_wind_namespaceObject.cn)(ROW_CLASS, 'pr-1'),
                        onSelect: ()=>onPresetApply?.(preset),
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                                title: preset.label,
                                className: "min-w-0 flex-1 truncate",
                                children: preset.label
                            }),
                            onPresetRename && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
                                type: "button",
                                title: _({
                                    id: 'canvas.property_trigger.rename_preset_with_label',
                                    message: 'Rename {label}',
                                    values: {
                                        label: preset.label
                                    }
                                }),
                                "aria-label": _({
                                    id: 'canvas.property_trigger.rename_preset_with_label',
                                    message: 'Rename {label}',
                                    values: {
                                        label: preset.label
                                    }
                                }),
                                onClick: (e)=>{
                                    e.stopPropagation();
                                    e.preventDefault();
                                    onPresetRename(preset);
                                },
                                onPointerDown: (e)=>e.stopPropagation(),
                                onPointerUp: (e)=>e.stopPropagation(),
                                className: "grid size-6 shrink-0 place-items-center rounded text-foreground-subtle transition hover:text-foreground",
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                                    icon: "pencil",
                                    size: 11
                                })
                            }),
                            onPresetDelete && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
                                type: "button",
                                title: _({
                                    id: 'canvas.property_trigger.delete_preset_with_label',
                                    message: 'Delete {label}',
                                    values: {
                                        label: preset.label
                                    }
                                }),
                                "aria-label": _({
                                    id: 'canvas.property_trigger.delete_preset_with_label',
                                    message: 'Delete {label}',
                                    values: {
                                        label: preset.label
                                    }
                                }),
                                onClick: (e)=>{
                                    e.stopPropagation();
                                    e.preventDefault();
                                    onPresetDelete(preset.id);
                                },
                                onPointerDown: (e)=>e.stopPropagation(),
                                onPointerUp: (e)=>e.stopPropagation(),
                                className: "grid size-6 shrink-0 place-items-center rounded text-foreground-subtle transition hover:text-foreground",
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                                    icon: "trash-2",
                                    size: 11
                                })
                            })
                        ]
                    }, preset.id)),
                canSavePreset && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(apollo_wind_namespaceObject.DropdownMenuItem, {
                    className: (0, apollo_wind_namespaceObject.cn)(ROW_CLASS, 'justify-start'),
                    onSelect: ()=>onSavePreset?.(),
                    children: [
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                            icon: "plus",
                            size: 12
                        }),
                        /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                            children: _({
                                id: 'canvas.property_trigger.save_as_preset',
                                message: 'Save as preset'
                            })
                        })
                    ]
                })
            ]
        })
    });
    const defaultSections = sections.map(({ key, node }, index)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_react_namespaceObject.Fragment, {
            children: [
                index > 0 && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(NodePropertyTriggerSeparator, {}),
                node
            ]
        }, key));
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
        "data-node-property-trigger-root": true,
        className: (0, apollo_wind_namespaceObject.cn)('w-fit flex flex-row items-center rounded-xl border border-border-subtle bg-surface-raised p-1', className),
        style: {
            boxShadow: '0 2px 6px rgba(0,0,0,0.08)'
        },
        children: [
            onPropertiesClick ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
                type: "button",
                onClick: onPropertiesClick,
                className: (0, apollo_wind_namespaceObject.cn)(labelBaseClassName, 'hover:bg-surface-overlay hover:text-foreground'),
                children: resolvedLabel
            }) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                className: labelBaseClassName,
                children: resolvedLabel
            }),
            showMenu && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
                children: [
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                        className: "mx-0.5 h-4 w-px shrink-0 bg-border-subtle"
                    }),
                    /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(apollo_wind_namespaceObject.DropdownMenu, {
                        open: open,
                        onOpenChange: onOpenChange,
                        modal: false,
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.DropdownMenuTrigger, {
                                asChild: true,
                                children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("button", {
                                    type: "button",
                                    title: resolvedMenuAriaLabel,
                                    "aria-label": resolvedMenuAriaLabel,
                                    className: "grid size-8 place-items-center rounded-lg text-foreground-muted transition hover:bg-surface-overlay hover:text-foreground data-[state=open]:bg-surface-overlay data-[state=open]:text-foreground",
                                    children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
                                        icon: "sliders-horizontal",
                                        size: 14
                                    })
                                })
                            }),
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.DropdownMenuContent, {
                                "data-node-property-trigger-menu": true,
                                align: "end",
                                sideOffset: 12,
                                alignOffset: -4,
                                className: "w-56 rounded-xl border-border-subtle bg-surface-raised p-0 shadow-[0_4px_16px_rgba(0,0,0,0.12)]",
                                children: children ?? defaultSections
                            })
                        ]
                    })
                ]
            })
        ]
    });
}
NodePropertyTrigger.displayName = 'NodePropertyTrigger';
exports.NodePropertyTrigger = __webpack_exports__.NodePropertyTrigger;
exports.NodePropertyTriggerCheckboxItem = __webpack_exports__.NodePropertyTriggerCheckboxItem;
exports.NodePropertyTriggerRadioItem = __webpack_exports__.NodePropertyTriggerRadioItem;
exports.NodePropertyTriggerSectionLabel = __webpack_exports__.NodePropertyTriggerSectionLabel;
exports.NodePropertyTriggerSeparator = __webpack_exports__.NodePropertyTriggerSeparator;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "NodePropertyTrigger",
    "NodePropertyTriggerCheckboxItem",
    "NodePropertyTriggerRadioItem",
    "NodePropertyTriggerSectionLabel",
    "NodePropertyTriggerSeparator"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
