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_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "../../index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__ from "../../../api-client/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__ from "../../../block-provider/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__filter_provider_utils_mjs__ from "../../../filter-provider/utils.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_initializer_items_ActionInitializer_mjs__ from "../../../schema-initializer/items/ActionInitializer.mjs";
const ActionBarAssociationFilterAction = (props)=>{
    const { refresh } = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(__WEBPACK_EXTERNAL_MODULE__index_mjs__.SchemaComponentContext);
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    const api = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useAPIClient)();
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const dn = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.createDesignable)({
        t,
        api,
        refresh,
        current: fieldSchema
    });
    const { service, props: blockProps } = (0, __WEBPACK_EXTERNAL_MODULE__block_provider_index_mjs__.useBlockRequestContext)();
    dn.loadAPIClientEvents();
    const handleInsert = (s)=>{
        dn.insertBeforeBegin(s);
    };
    const handleRemove = (schema, remove)=>{
        var _service_params, _blockProps_params;
        remove(schema);
        service.run({
            ...null === (_service_params = service.params) || void 0 === _service_params ? void 0 : _service_params[0],
            filter: (0, __WEBPACK_EXTERNAL_MODULE__filter_provider_utils_mjs__.mergeFilter)([
                null == blockProps ? void 0 : null === (_blockProps_params = blockProps.params) || void 0 === _blockProps_params ? void 0 : _blockProps_params.filter
            ])
        });
    };
    const schema = {
        type: 'void',
        'x-action': 'associateFilter',
        'x-initializer': 'AssociationFilter.Initializer',
        'x-component': 'AssociationFilter',
        properties: {}
    };
    const newProps = {
        ...props,
        insert: handleInsert,
        remove: handleRemove,
        wrap: (s)=>s
    };
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_initializer_items_ActionInitializer_mjs__.ActionInitializer, {
        ...newProps,
        schema: schema
    });
};
export { ActionBarAssociationFilterAction };
