import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__ant_design_icons__ from "@ant-design/icons";
import * as __WEBPACK_EXTERNAL_MODULE_antd_style__ from "antd-style";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__action_context_mjs__ from "../action/context.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__action_hooks_useGetAriaLabelOfPopover_mjs__ from "../action/hooks/useGetAriaLabelOfPopover.mjs";
import "../action/hooks/useSetAriaLabelForPopover.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__popover_index_mjs__ from "../popover/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_mjs__ from "./hooks.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__InternalNester_mjs__ from "./InternalNester.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__InternalViewer_mjs__ from "./InternalViewer.mjs";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n      max-width: 95%;\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
function _templateObject1() {
    const data = _tagged_template_literal([
        "\n      position: fixed;\n      top: 0;\n      left: 0;\n      width: 100%;\n      height: 100%;\n      background-color: transparent;\n      z-index: 9999;\n    "
    ]);
    _templateObject1 = function() {
        return data;
    };
    return data;
}
function _templateObject2() {
    const data = _tagged_template_literal([
        "\n      min-width: 600px;\n      max-width: 800px;\n      max-height: 440px;\n      overflow: auto;\n      .ant-card {\n        border: 0px;\n      }\n    "
    ]);
    _templateObject2 = function() {
        return data;
    };
    return data;
}
const useStyles = (0, __WEBPACK_EXTERNAL_MODULE_antd_style__.createStyles)((param)=>{
    let { css } = param;
    return {
        pretty: css(_templateObject()),
        mask: css(_templateObject1()),
        container: css(_templateObject2())
    };
});
const InternaPopoverNester = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    var _options_uiSchema;
    const { styles } = useStyles();
    const { options } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_mjs__.useAssociationFieldContext)();
    const [visible, setVisible] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const schema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    schema['x-component-props'].enableLink = false;
    const ref = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)();
    const nesterProps = {
        ...props,
        shouldMountElement: true
    };
    const content = /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        ref: ref,
        className: styles.container,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__InternalNester_mjs__.InternalNester, {
            ...nesterProps
        })
    });
    const getContainer = ()=>ref.current;
    const ctx = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__action_context_mjs__.ActionContext);
    const modalProps = {
        getContainer: getContainer
    };
    const { getAriaLabel } = (0, __WEBPACK_EXTERNAL_MODULE__action_hooks_useGetAriaLabelOfPopover_mjs__.useGetAriaLabelOfPopover)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE__action_context_mjs__.ActionContextProvider, {
        value: {
            ...ctx,
            modalProps
        },
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__popover_index_mjs__.StablePopover, {
                overlayStyle: {
                    padding: '0px'
                },
                content: content,
                trigger: "click",
                placement: "topLeft",
                open: visible,
                onOpenChange: (open)=>setVisible(open),
                title: t(null == options ? void 0 : null === (_options_uiSchema = options.uiSchema) || void 0 === _options_uiSchema ? void 0 : _options_uiSchema.rawTitle),
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("span", {
                    style: {
                        cursor: 'pointer',
                        display: 'flex'
                    },
                    children: [
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                            className: styles.pretty,
                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__InternalViewer_mjs__.ReadPrettyInternalViewer, {
                                ...props
                            })
                        }),
                        /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.EditOutlined, {
                            style: {
                                display: 'inline-flex',
                                margin: '5px'
                            }
                        })
                    ]
                })
            }),
            visible && /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                role: "button",
                "aria-label": getAriaLabel('mask'),
                onClick: ()=>setVisible(false),
                className: styles.mask
            })
        ]
    });
}, {
    displayName: 'InternaPopoverNester'
});
export { InternaPopoverNester };
