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__api_client_index_mjs__ from "../../../api-client/index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__ from "../../../application/hoc/withDynamicSchemaProps.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__hooks_useProps_mjs__ from "../../hooks/useProps.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__context_mjs__ from "./context.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__Filter_Action_Designer_mjs__ from "./Filter.Action.Designer.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__FilterAction_mjs__ from "./FilterAction.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__FilterGroup_mjs__ from "./FilterGroup.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__SaveDefaultValue_mjs__ from "./SaveDefaultValue.mjs";
const useDef = (options)=>{
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    return (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useRequest)(()=>Promise.resolve({
            data: field.dataSource
        }), options);
};
const Filter = (0, __WEBPACK_EXTERNAL_MODULE__application_hoc_withDynamicSchemaProps_mjs__.withDynamicSchemaProps)((0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.observer)((props)=>{
    const { useDataSource = useDef } = props;
    const { options, dynamicComponent, className, collectionName } = (0, __WEBPACK_EXTERNAL_MODULE__hooks_useProps_mjs__.useProps)(props);
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const fieldSchema = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useFieldSchema)();
    useDataSource({
        onSuccess (data) {
            field.dataSource = (null == data ? void 0 : data.data) || [];
        }
    });
    (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
        if (fieldSchema.defaultValue) field.initialValue = fieldSchema.defaultValue;
    }, [
        fieldSchema.defaultValue
    ]);
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("div", {
        className: className,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__context_mjs__.FilterContext.Provider, {
            value: {
                field,
                fieldSchema,
                dynamicComponent,
                options: options || field.dataSource || [],
                disabled: props.disabled,
                collectionName
            },
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__FilterGroup_mjs__.FilterGroup, {
                ...props,
                bordered: false
            })
        })
    });
}), {
    displayName: 'Filter'
});
Filter.SaveDefaultValue = __WEBPACK_EXTERNAL_MODULE__SaveDefaultValue_mjs__.SaveDefaultValue;
Filter.Action = __WEBPACK_EXTERNAL_MODULE__FilterAction_mjs__.FilterAction;
Filter.Action.Designer = __WEBPACK_EXTERNAL_MODULE__Filter_Action_Designer_mjs__.FilterActionDesigner;
export { Filter };
