"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__, {
    NodePropertiesPanel: ()=>NodePropertiesPanel_NodePropertiesPanel
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const react_cjs_namespaceObject = require("../../xyflow/react.cjs");
const apollo_wind_namespaceObject = require("@uipath/apollo-wind");
const external_react_namespaceObject = require("react");
const icon_registry_cjs_namespaceObject = require("../../utils/icon-registry.cjs");
const index_cjs_namespaceObject = require("../FloatingCanvasPanel/index.cjs");
const external_fields_index_cjs_namespaceObject = require("./fields/index.cjs");
const external_hooks_index_cjs_namespaceObject = require("./hooks/index.cjs");
const PINNED_PANEL_WIDTH = 320;
function renderField(field, value, onChange, error) {
    switch(field.type){
        case 'text':
        case 'textarea':
            {
                const textValue = 'string' == typeof value ? value : String(value ?? '');
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_fields_index_cjs_namespaceObject.TextField, {
                    field: field,
                    value: textValue,
                    onChange: onChange,
                    error: error
                });
            }
        case 'select':
            {
                const selectValue = value;
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_fields_index_cjs_namespaceObject.SelectField, {
                    field: field,
                    value: selectValue,
                    onChange: onChange,
                    error: error
                });
            }
        case 'number':
            {
                const numberValue = 'number' == typeof value ? value : void 0;
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_fields_index_cjs_namespaceObject.NumberField, {
                    field: field,
                    value: numberValue,
                    onChange: onChange,
                    error: error
                });
            }
        case 'checkbox':
            {
                const boolValue = 'boolean' == typeof value ? value : !!value;
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_fields_index_cjs_namespaceObject.CheckboxField, {
                    field: field,
                    value: boolValue,
                    onChange: onChange,
                    error: error
                });
            }
        default:
            {
                const defaultValue = String(value ?? '');
                return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_fields_index_cjs_namespaceObject.TextField, {
                    field: field,
                    value: defaultValue,
                    onChange: onChange,
                    error: error
                });
            }
    }
}
const NodePropertiesPanel_NodePropertiesPanel = /*#__PURE__*/ (0, external_react_namespaceObject.memo)(function({ nodeId, onClose, position = 'right', customSchemas = {}, enableValidation = false, onChange, maintainSelection = true, defaultPinned = false, onPinnedChange }) {
    const { getInternalNode } = (0, react_cjs_namespaceObject.useReactFlow)();
    const { setSelectedNodeId, selectedNode } = (0, external_hooks_index_cjs_namespaceObject.useNodeSelection)(nodeId, maintainSelection);
    const { schema, errors, handleFieldChange } = (0, external_hooks_index_cjs_namespaceObject.useNodeConfiguration)(selectedNode, customSchemas, enableValidation, onChange);
    const [isPinned, setIsPinned] = (0, external_react_namespaceObject.useState)(defaultPinned);
    const handleClose = (0, external_react_namespaceObject.useCallback)(()=>{
        setSelectedNodeId(null);
        setIsPinned(false);
        if (onClose) onClose();
    }, [
        onClose,
        setSelectedNodeId
    ]);
    const handleTogglePin = (0, external_react_namespaceObject.useCallback)(()=>{
        setIsPinned((prev)=>!prev);
    }, []);
    (0, external_react_namespaceObject.useEffect)(()=>{
        if (onPinnedChange) onPinnedChange(isPinned);
    }, [
        isPinned,
        onPinnedChange
    ]);
    const internalNode = selectedNode ? getInternalNode(selectedNode.id) : null;
    const renderSection = (section)=>{
        if (!selectedNode) return null;
        return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
            className: "px-4 py-4 border-b border-(--canvas-border-de-emp) last:border-b-0",
            children: [
                section.title && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    className: "font-medium text-[14px] text-(--canvas-foreground) mb-2",
                    children: section.title
                }),
                /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                    className: "flex flex-col gap-4",
                    children: section.fields.map((field)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                            children: renderField(field, selectedNode.data[field.key], (value)=>handleFieldChange(field.key, value), errors[field.key])
                        }, field.key))
                })
            ]
        }, section.id);
    };
    if (!selectedNode || !schema || !internalNode) return null;
    const headerActions = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(apollo_wind_namespaceObject.Button, {
        variant: "ghost",
        size: "icon",
        className: "h-6 w-6",
        onClick: handleTogglePin,
        title: isPinned ? 'Unpin panel' : 'Pin panel',
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(icon_registry_cjs_namespaceObject.CanvasIcon, {
            icon: isPinned ? 'shrink' : 'expand',
            size: 16
        })
    });
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(index_cjs_namespaceObject.FloatingCanvasPanel, {
        open: !!selectedNode,
        nodeId: isPinned ? void 0 : selectedNode.id,
        anchorRect: isPinned ? {
            x: window.innerWidth - PINNED_PANEL_WIDTH,
            y: 0,
            width: 0,
            height: window.innerHeight
        } : void 0,
        placement: isPinned ? 'left-start' : 'right' === position ? 'right-start' : 'left-start',
        offset: isPinned ? 0 : 20,
        title: 'stage' === selectedNode.type ? 'Stage properties' : `${selectedNode.type || 'Node'} Configuration`,
        headerActions: headerActions,
        onClose: handleClose,
        scrollKey: selectedNode.id,
        isPinned: isPinned,
        children: schema.sections ? schema.sections.map((section)=>renderSection(section)) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
            className: "px-4 py-4",
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                className: "flex flex-col gap-4",
                children: schema.fields?.map((field)=>/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("div", {
                        children: selectedNode && renderField(field, selectedNode.data[field.key], (value)=>handleFieldChange(field.key, value), errors[field.key])
                    }, field.key))
            })
        })
    });
});
exports.NodePropertiesPanel = __webpack_exports__.NodePropertiesPanel;
for(var __rspack_i in __webpack_exports__)if (-1 === [
    "NodePropertiesPanel"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
    value: true
});
