import { jsx } from "react/jsx-runtime";
import "react";
import { useSchemaInitializer, useSchemaInitializerItem } from "../../../../application/index.mjs";
import { useCollectionManager } from "../../../../data-source/index.mjs";
import { Icon } from "../../../../icon/index.mjs";
import { DataBlockInitializer } 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 = useSchemaInitializerItem();
    const { insert } = useSchemaInitializer();
    const cm = useCollectionManager();
    return /*#__PURE__*/ jsx(DataBlockInitializer, {
        ...itemConfig,
        onlyCurrentDataSource: onlyCurrentDataSource,
        icon: /*#__PURE__*/ jsx(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 };
