const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_utils = require("./utils.js");
const require_model = require("../model.js");
const require_index = require("../components/CurrentDay/index.js");
const require_index$1 = require("./list/index.js");
const require_serve = require("./serve.js");
const require_index$2 = require("./ProductDetailDrawer/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let ahooks = require("ahooks");
require("./index.less");
//#region src/components/schedules/products/index.tsx
const Products = () => {
	const { state, dispatch } = (0, react.useContext)(require_model.Context);
	const { products, currentSelectDayDetail } = state;
	const _getProducts = (0, ahooks.useRequest)(require_serve.getProductList, { manual: true });
	(0, react.useEffect)(() => {
		dispatch({
			type: "setProducts",
			payload: { list: require_utils.formatProductSchedules(_getProducts.data || [], state.schedules.scheduleMap) }
		});
	}, [_getProducts.data, state.schedules.scheduleMap]);
	const _init = () => {
		dispatch({
			type: "setProducts",
			payload: {
				search: "",
				currentProduct: null,
				openProductDetailDrawer: false,
				openAddSchedulesDrawer: false
			}
		});
		if (currentSelectDayDetail && (!currentSelectDayDetail.scheduleIds || !currentSelectDayDetail.scheduleIds.length)) _getProducts.mutate([]);
		else _getProducts.run({
			skip: 1,
			num: 500,
			with: ["category"],
			status: "published",
			open_quotation: 1,
			with_schedule: true,
			schedule: 1,
			schedule_ids: currentSelectDayDetail ? currentSelectDayDetail.scheduleIds || [] : void 0
		});
	};
	(0, react.useEffect)(() => {
		_init();
	}, [currentSelectDayDetail]);
	const handleClose = () => {
		dispatch({
			type: "setState",
			payload: { currentSelectDayDetail: null }
		});
	};
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__schedules-component-products" }, /* @__PURE__ */ react.default.createElement(require_index.default, {
		onClose: handleClose,
		currentDay: currentSelectDayDetail === null || currentSelectDayDetail === void 0 ? void 0 : currentSelectDayDetail.date
	}), /* @__PURE__ */ react.default.createElement(require_index$1.default, {
		loading: _getProducts.loading,
		list: products.list
	}), /* @__PURE__ */ react.default.createElement(require_index$2.default, null));
};
//#endregion
exports.default = Products;
