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