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__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__ from "../../../data-source/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__flag_provider_index_mjs__ from "../../../flag-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__action_context_mjs__ from "../action/context.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_mjs__ from "./hooks.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__InternalSubTable_mjs__ from "./InternalSubTable.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__InternalViewer_mjs__ from "./InternalViewer.mjs";
const InternaDrawerSubTable = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    var _options_uiSchema;
    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 nesterProps = {
        ...props,
        shouldMountElement: true
    };
    const titleProps = {
        ...props,
        enableLink: true
    };
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const cm = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollectionManager)();
    const ctx = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__action_context_mjs__.ActionContext);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.Fragment, {
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("span", {
                style: {
                    cursor: 'pointer',
                    display: 'flex'
                },
                onClick: ()=>{
                    setVisible(true);
                },
                children: [
                    /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
                        style: {
                            maxWidth: '95%'
                        },
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__InternalViewer_mjs__.ReadPrettyInternalViewer, {
                            ...titleProps
                        })
                    }),
                    /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__ant_design_icons__.EditOutlined, {
                        style: {
                            display: 'inline-flex',
                            marginLeft: '5px'
                        }
                    })
                ]
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__action_context_mjs__.ActionContextProvider, {
                value: {
                    ...ctx,
                    visible,
                    setVisible,
                    openMode: 'drawer'
                },
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Drawer, {
                    title: t(null == options ? void 0 : null === (_options_uiSchema = options.uiSchema) || void 0 === _options_uiSchema ? void 0 : _options_uiSchema.rawTitle),
                    open: visible,
                    onClose: ()=>{
                        setVisible(false);
                    },
                    style: {
                        backgroundColor: '#f3f3f3'
                    },
                    width: '70%',
                    destroyOnClose: true,
                    extra: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Button, {
                        type: "primary",
                        onClick: ()=>setVisible(false),
                        children: "确认"
                    }),
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__flag_provider_index_mjs__.FlagProvider, {
                        isInSubForm: true,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__hooks_mjs__.SubFormProvider, {
                            value: {
                                value: field.value,
                                collection: cm.getCollection(fieldSchema['x-collection-field'])
                            },
                            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__InternalSubTable_mjs__.InternalSubTable, {
                                ...nesterProps
                            })
                        })
                    })
                })
            })
        ]
    });
}, {
    displayName: 'InternaDrawerSubTable'
});
export { InternaDrawerSubTable };
