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__collection_manager_index_mjs__ from "../../../../collection-manager/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_initializer_components_index_mjs__ from "../../../../schema-initializer/components/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__action_index_mjs__ from "../../action/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_mjs__ from "../hooks.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_mjs__ from "../schema.mjs";
const CreateRecordAction = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const ctx = (0, __WEBPACK_EXTERNAL_MODULE__action_index_mjs__.useActionContext)();
    const { getCollection } = (0, __WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.useCollectionManager_deprecated)();
    const insertAddNewer = (0, __WEBPACK_EXTERNAL_MODULE__hooks_mjs__.useInsertSchema)('AddNewer');
    const { options: collectionField } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_mjs__.useAssociationFieldContext)();
    const [visibleAddNewer, setVisibleAddNewer] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(false);
    const targetCollection = getCollection(null == collectionField ? void 0 : collectionField.target);
    const [currentCollection, setCurrentCollection] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(null == targetCollection ? void 0 : targetCollection.name);
    const [currentDataSource, setCurrentDataSource] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(null == targetCollection ? void 0 : targetCollection.dataSource);
    const addbuttonClick = (collectionData)=>{
        insertAddNewer(__WEBPACK_EXTERNAL_MODULE__schema_mjs__["default"].AddNewer);
        setVisibleAddNewer(true);
        setCurrentCollection(collectionData.name);
        setCurrentDataSource(collectionData.dataSource);
    };
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.CollectionProvider_deprecated, {
        name: null == collectionField ? void 0 : collectionField.target,
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_initializer_components_index_mjs__.CreateAction, {
                ...props,
                onClick: (arg)=>addbuttonClick(arg)
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__action_index_mjs__.ActionContextProvider, {
                value: {
                    ...ctx,
                    visible: visibleAddNewer,
                    setVisible: setVisibleAddNewer
                },
                children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__collection_manager_index_mjs__.CollectionProvider_deprecated, {
                    name: currentCollection,
                    dataSource: currentDataSource,
                    children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__tachybase_schema__.RecursionField, {
                        onlyRenderProperties: true,
                        basePath: field.address,
                        schema: fieldSchema,
                        filterProperties: (s)=>'AssociationField.AddNewer' === s['x-component']
                    })
                })
            })
        ]
    });
}, {
    displayName: 'CreateRecordAction'
});
export { CreateRecordAction };
