import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__application_index_mjs__ from "../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__utils_mjs__ from "../utils.mjs";
const InitializerWithSwitch = (props)=>{
    var _item_schema;
    const { type, schema, item, remove: passInRemove, disabled } = props;
    const { exists, remove } = (0, __WEBPACK_EXTERNAL_MODULE__utils_mjs__.useCurrentSchema)((null == schema ? void 0 : schema[type]) || (null == item ? void 0 : null === (_item_schema = item.schema) || void 0 === _item_schema ? void 0 : _item_schema[type]), type, item.find, null != passInRemove ? passInRemove : item.remove);
    const { insert } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializer)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__application_index_mjs__.SchemaInitializerSwitch, {
        checked: exists,
        disabled: disabled,
        title: item.title,
        onClick: ()=>{
            var _item_schemaInitialize;
            if (disabled) return;
            if (exists) return remove();
            const s = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.merge)(schema || {}, item.schema || {});
            null == item || null === (_item_schemaInitialize = item.schemaInitialize) || void 0 === _item_schemaInitialize || _item_schemaInitialize.call(item, s);
            insert(s);
        }
    });
};
export { InitializerWithSwitch };
