import { jsx, jsxs } from "react/jsx-runtime";
import react from "react";
import { useFieldSchema } from "@tachybase/schema";
import { createStyles } from "antd-style";
import classnames from "classnames";
import { useSchemaInitializerRender } from "../../../application/index.mjs";
import { Plugin } from "../../../application/Plugin.mjs";
import { TableBlockProvider } from "../../../block-provider/TableBlockProvider.mjs";
import { useCollection_deprecated } from "../../../collection-manager/index.mjs";
import { associationFilterFilterBlockInitializer, filterCollapseItemInitializer } from "../../../modules/blocks/filter-blocks/collapse/filterCollapseItemInitializer.mjs";
import { DndContext, SortableItem } from "../../common/index.mjs";
import { useDesigner } from "../../hooks/index.mjs";
import { AssociationFilterBlockDesigner } from "./AssociationFilter.BlockDesigner.mjs";
import { associationFilterInitializer } from "./AssociationFilter.Initializer.mjs";
import { AssociationFilterItem } from "./AssociationFilter.Item.mjs";
import { AssociationFilterItemDesigner } from "./AssociationFilter.Item.Designer.mjs";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n      height: 100%;\n      overflow-y: auto;\n      position: relative;\n      border-radius: ",
        "px;\n      &:hover {\n        > .general-schema-designer {\n          display: block;\n        }\n      }\n      &.tb-form-item:hover {\n        > .general-schema-designer {\n          background: var(--colorBgSettingsHover) !important;\n          border: 0 !important;\n          top: -5px !important;\n          bottom: -5px !important;\n          left: -5px !important;\n          right: -5px !important;\n        }\n      }\n      > .general-schema-designer {\n        position: absolute;\n        z-index: 999;\n        top: 0;\n        bottom: 0;\n        left: 0;\n        right: 0;\n        display: none;\n        border: 2px solid var(--colorBorderSettingsHover);\n        pointer-events: none;\n        > .general-schema-designer-icons {\n          position: absolute;\n          right: 2px;\n          top: 2px;\n          line-height: 16px;\n          pointer-events: all;\n          .ant-space-item {\n            background-color: var(--colorSettings);\n            color: #fff;\n            line-height: 16px;\n            width: 16px;\n            padding-left: 1px;\n            align-self: stretch;\n          }\n        }\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const useStyles = createStyles((param)=>{
    let { css, token } = param;
    return {
        container: css(_templateObject(), token.borderRadiusLG)
    };
});
const AssociationFilter = (props)=>{
    const Designer = useDesigner();
    const filedSchema = useFieldSchema();
    const { styles } = useStyles();
    const { render } = useSchemaInitializerRender(filedSchema['x-initializer'], filedSchema['x-initializer-props']);
    return /*#__PURE__*/ jsx(DndContext, {
        children: /*#__PURE__*/ jsxs(SortableItem, {
            className: classnames('tb-block-item', props.className, styles.container),
            children: [
                /*#__PURE__*/ jsx(Designer, {}),
                props.children,
                render()
            ]
        })
    });
};
AssociationFilter.Provider = TableBlockProvider;
AssociationFilter.Item = AssociationFilterItem;
AssociationFilter.Item.Designer = AssociationFilterItemDesigner;
AssociationFilter.BlockDesigner = AssociationFilterBlockDesigner;
AssociationFilter.useAssociationField = ()=>{
    const fieldSchema = useFieldSchema();
    const { getField } = useCollection_deprecated();
    return react.useMemo(()=>getField(fieldSchema.name), [
        fieldSchema.name
    ]);
};
class AssociationFilterPlugin extends Plugin {
    async load() {
        this.app.schemaInitializerManager.add(associationFilterFilterBlockInitializer);
        this.app.schemaInitializerManager.add(filterCollapseItemInitializer);
        this.app.schemaInitializerManager.add(associationFilterInitializer);
    }
}
export { AssociationFilter, AssociationFilterPlugin };
