const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_locales = require("../../utils/locales.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_useEngineContext = require("../../hooks/useEngineContext.js");
const require_model = require("./model.js");
const require_utils = require("./utils.js");
const require_index = require("./calendar/index.js");
const require_index$1 = require("./schedules/index.js");
const require_index$2 = require("./products/index.js");
const require_index$3 = require("./resources/index.js");
const require_index$4 = require("./openHours/index.js");
const require_locales$1 = require("./locales.js");
const require_constants = require("./constants.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
require("./index.less");
//#region src/components/schedules/index.tsx
_pisell_utils.locales.init(require_locales$1.default, require_locales.getLocale());
const Schedules = require_model.Provider((props) => {
	const { globalState } = props;
	const { state, dispatch } = (0, react.useContext)(require_model.Context);
	const { tabKey } = state;
	const [forceUpdateOpenHours, setForceUpdateOpenHours] = (0, react.useState)(0);
	const openHoursRef = (0, react.useRef)();
	const context = require_useEngineContext.default();
	const [modal, contextHolder] = antd.Modal.useModal();
	require_utils.request.setRequest(context.appHelper.utils.request);
	require_utils.setModal(modal);
	const setState = (payload) => {
		dispatch({
			type: "setState",
			payload: require_objectSpread2._objectSpread2({}, payload)
		});
	};
	(0, react.useEffect)(() => {
		dispatch({
			type: "setGlobalState",
			payload: require_objectSpread2._objectSpread2({ setGlobalState: props.setGlobalState }, globalState)
		});
	}, [globalState]);
	const onChange = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* (key) {
			var _openHoursRef$current;
			if (tabKey === "openHours" && ((_openHoursRef$current = openHoursRef.current) === null || _openHoursRef$current === void 0 ? void 0 : _openHoursRef$current.getIsEdit())) {
				if (!(yield require_utils.saveConfirm())) return;
				setForceUpdateOpenHours((p) => p + 1);
			}
			setState({ tabKey: key });
		});
		return function onChange(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	(0, react.useEffect)(() => {
		document.body.id = "body";
	}, []);
	const isProduct = (0, react.useMemo)(() => {
		var _context$appHelper$ut, _context$appHelper$ut2;
		return (((_context$appHelper$ut = context.appHelper.utils.store) === null || _context$appHelper$ut === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut.getState) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.call(_context$appHelper$ut)) === null || _context$appHelper$ut2 === void 0 || (_context$appHelper$ut2 = _context$appHelper$ut2.global) === null || _context$appHelper$ut2 === void 0 ? void 0 : _context$appHelper$ut2.globalConfig.apps) || []).some((d) => require_constants.scheduleApps.includes(d.module));
	}, []);
	(0, react.useEffect)(() => {
		dispatch({
			type: "setState",
			payload: { tabKey: isProduct ? "products" : "schedules" }
		});
	}, [isProduct]);
	const items = (0, react.useMemo)(() => {
		let list = [
			{
				key: "products",
				label: _pisell_utils.locales.getText("pisell2.text.schedules.products-title"),
				children: /* @__PURE__ */ react.default.createElement(require_index$2.default, null),
				forceRender: true
			},
			{
				key: "schedules",
				label: _pisell_utils.locales.getText("pisell2.text.schedules.schedules-title"),
				children: /* @__PURE__ */ react.default.createElement(require_index$1.default, null),
				forceRender: true
			},
			{
				key: "resources",
				label: _pisell_utils.locales.getText("pisell2.text.schedules.resources-title"),
				children: /* @__PURE__ */ react.default.createElement(require_index$3.default, null),
				forceRender: true
			},
			{
				key: "openHours",
				label: _pisell_utils.locales.getText("pisell2.text.schedules.open-hours-title"),
				children: /* @__PURE__ */ react.default.createElement(require_index$4.default, {
					ref: openHoursRef,
					key: forceUpdateOpenHours
				}),
				forceRender: true
			}
		];
		if (!isProduct) list = list.filter((item) => item.key !== "products");
		return list;
	}, [
		state,
		openHoursRef,
		forceUpdateOpenHours,
		modal,
		isProduct
	]);
	return /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__schedules-component" }, /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__schedules-component-calendar" }, /* @__PURE__ */ react.default.createElement(require_index.default, null)), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__schedules-component-panels" }, /* @__PURE__ */ react.default.createElement(antd.Tabs, {
		className: "pisell-lowcode__schedules-tabs-wrap",
		activeKey: tabKey,
		tabBarStyle: { margin: "0 32px" },
		items,
		onChange
	})), contextHolder);
});
//#endregion
exports.default = Schedules;
