const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_useVariables = require("../../dataSourceComponents/hooks/useVariables.js");
const require_useComponentId = require("../../dataSourceComponents/hooks/useComponentId.js");
const require_useDataSourceKey = require("../hooks/useDataSourceKey.js");
const require_useHandleAction = require("../hooks/useHandleAction.js");
const require_ChildComponentProps = require("./ChildComponentProps.js");
let react = require("react");
react = require_runtime.__toESM(react);
let _pisell_utils = require("@pisell/utils");
//#region src/components/pisellDataSourceContainer/provider/HandleActions.tsx
const HandleActionContext = (0, react.createContext)(null);
const HandleActionsProvider = (props) => {
	const { dataSource, children, autoRun, pagination, extraParams } = props;
	const { form } = require_ChildComponentProps.useChildComponentPropsContext();
	const componentId = require_useComponentId.default(props);
	const { registerValueVariable } = require_useVariables.default();
	const { dataSourceKey } = require_useDataSourceKey.default();
	const handleAction = require_useHandleAction.default({ list: extraParams === null || extraParams === void 0 ? void 0 : extraParams.list }, pagination, form);
	(0, react.useEffect)(() => {
		registerValueVariable === null || registerValueVariable === void 0 || registerValueVariable(componentId, { currentDataSource: dataSource });
	}, [dataSource]);
	(0, react.useEffect)(() => {
		if ((0, _pisell_utils.isBoolean)(autoRun === null || autoRun === void 0 ? void 0 : autoRun.list) && (autoRun === null || autoRun === void 0 ? void 0 : autoRun.list)) {
			const formValues = form.getFieldsValue() || {};
			if (dataSourceKey) handleAction.list.onSearch(require_objectSpread2._objectSpread2({}, formValues));
			else {
				var _handleAction$list;
				(_handleAction$list = handleAction.list) === null || _handleAction$list === void 0 || _handleAction$list.mutate([]);
			}
		}
	}, [dataSourceKey, autoRun === null || autoRun === void 0 ? void 0 : autoRun.list]);
	return /* @__PURE__ */ react.default.createElement(HandleActionContext.Provider, { value: handleAction }, children);
};
const useHandleActionProvider = () => {
	return (0, react.useContext)(HandleActionContext);
};
//#endregion
exports.HandleActionsProvider = HandleActionsProvider;
exports.useHandleActionProvider = useHandleActionProvider;
