import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__application_index_mjs__ from "../../../../application/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__ from "../../../../data-source/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__icon_index_mjs__ from "../../../../icon/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__schema_initializer_items_DataBlockInitializer_mjs__ from "../../../../schema-initializer/items/DataBlockInitializer.mjs";
const createTreeBlockSchema = (options)=>{
    const { actionInitializers = 'TreeActionInitializers', collection, association, resource, ...others } = options;
    const resourceName = resource || association || collection;
    const schema = {
        type: 'void',
        'x-acl-action': "".concat(resourceName, ":list"),
        'x-decorator': 'TreeBlockProvider',
        'x-decorator-props': {
            resource: resourceName,
            collection,
            association,
            readPretty: true,
            action: 'list',
            runWhenParamsChanged: true,
            ...others
        },
        'x-filter-targets': [],
        'x-filter-operators': {},
        'x-settings': 'blockSettings:filterTree',
        'x-component': 'CardItem',
        properties: {
            actionBar: {
                type: 'void',
                'x-initializer': 'filterTree:configureActions',
                'x-component': 'ActionBar',
                'x-component-props': {
                    style: {
                        marginBottom: 'var(--tb-spacing)'
                    }
                },
                properties: {}
            },
            tree: {
                type: 'array',
                'x-component': 'Tree',
                'x-use-component-props': 'useTreeBlockProps'
            }
        }
    };
    return schema;
};
const FilterTreeBlockInitializer = (param)=>{
    let { filterCollections, onlyCurrentDataSource, hideChildrenIfSingleCollection } = param;
    const itemConfig = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializerItem)();
    const { insert } = (0, __WEBPACK_EXTERNAL_MODULE__application_index_mjs__.useSchemaInitializer)();
    const cm = (0, __WEBPACK_EXTERNAL_MODULE__data_source_index_mjs__.useCollectionManager)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__schema_initializer_items_DataBlockInitializer_mjs__.DataBlockInitializer, {
        ...itemConfig,
        onlyCurrentDataSource: onlyCurrentDataSource,
        icon: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__icon_index_mjs__.Icon, {
            type: "TableOutlined"
        }),
        componentType: 'FilterTree',
        onCreateBlockSchema: async (param)=>{
            let { item } = param;
            const collection = cm.getCollection(item.name);
            const schema = createTreeBlockSchema({
                collection: item.name,
                rowKey: collection.filterTargetKey || 'id'
            });
            insert(schema);
        },
        filter: filterCollections,
        hideChildrenIfSingleCollection: hideChildrenIfSingleCollection
    });
};
export { FilterTreeBlockInitializer, createTreeBlockSchema };
