var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/schedules/index.tsx
var schedules_exports = {};
__export(schedules_exports, {
  default: () => schedules_default
});
module.exports = __toCommonJS(schedules_exports);
var import_react = __toESM(require("react"));
var import_calendar = __toESM(require("./calendar"));
var import_antd = require("antd");
var import_model = require("./model");
var import_schedules = __toESM(require("./schedules"));
var import_products = __toESM(require("./products"));
var import_resources = __toESM(require("./resources"));
var import_openHours = __toESM(require("./openHours"));
var import_useEngineContext = __toESM(require("../../hooks/useEngineContext"));
var import_utils = require("./utils");
var import_utils2 = require("@pisell/utils");
var import_locales = __toESM(require("./locales"));
var import_constants = require("./constants");
var import_index = require("./index.less");
var import_locales2 = require("../../utils/locales");
import_utils2.locales.init(import_locales.default, (0, import_locales2.getLocale)());
var Schedules = (0, import_model.Provider)((props) => {
  const { globalState } = props;
  const { state, dispatch } = (0, import_react.useContext)(import_model.Context);
  const { tabKey } = state;
  const [forceUpdateOpenHours, setForceUpdateOpenHours] = (0, import_react.useState)(0);
  const openHoursRef = (0, import_react.useRef)();
  const context = (0, import_useEngineContext.default)();
  const [modal, contextHolder] = import_antd.Modal.useModal();
  import_utils.request.setRequest(context.appHelper.utils.request);
  (0, import_utils.setModal)(modal);
  const setState = (payload) => {
    dispatch({
      type: "setState",
      payload: {
        ...payload
      }
    });
  };
  (0, import_react.useEffect)(() => {
    dispatch({
      type: "setGlobalState",
      payload: {
        setGlobalState: props.setGlobalState,
        ...globalState
      }
    });
  }, [globalState]);
  const onChange = async (key) => {
    var _a;
    if (tabKey === "openHours" && ((_a = openHoursRef.current) == null ? void 0 : _a.getIsEdit())) {
      const confirm = await (0, import_utils.saveConfirm)();
      if (!confirm) return;
      setForceUpdateOpenHours((p) => p + 1);
    }
    setState({
      tabKey: key
    });
  };
  (0, import_react.useEffect)(() => {
    document.body.id = "body";
  }, []);
  const isProduct = (0, import_react.useMemo)(() => {
    var _a, _b, _c, _d;
    let apps = ((_d = (_c = (_b = (_a = context.appHelper.utils.store) == null ? void 0 : _a.getState) == null ? void 0 : _b.call(_a)) == null ? void 0 : _c.global) == null ? void 0 : _d.globalConfig.apps) || [];
    return apps.some((d) => import_constants.scheduleApps.includes(d.module));
  }, []);
  (0, import_react.useEffect)(() => {
    dispatch({
      type: "setState",
      payload: {
        tabKey: isProduct ? "products" : "schedules"
      }
    });
  }, [isProduct]);
  const items = (0, import_react.useMemo)(() => {
    let list = [
      {
        key: "products",
        label: import_utils2.locales.getText("pisell2.text.schedules.products-title"),
        children: /* @__PURE__ */ import_react.default.createElement(import_products.default, null),
        forceRender: true
      },
      {
        key: "schedules",
        label: import_utils2.locales.getText("pisell2.text.schedules.schedules-title"),
        children: /* @__PURE__ */ import_react.default.createElement(import_schedules.default, null),
        forceRender: true
      },
      {
        key: "resources",
        label: import_utils2.locales.getText("pisell2.text.schedules.resources-title"),
        children: /* @__PURE__ */ import_react.default.createElement(import_resources.default, null),
        forceRender: true
      },
      {
        key: "openHours",
        label: import_utils2.locales.getText("pisell2.text.schedules.open-hours-title"),
        children: /* @__PURE__ */ import_react.default.createElement(import_openHours.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__ */ import_react.default.createElement("div", { className: "pisell-lowcode__schedules-component" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__schedules-component-calendar" }, /* @__PURE__ */ import_react.default.createElement(import_calendar.default, null)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-lowcode__schedules-component-panels" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Tabs,
    {
      className: "pisell-lowcode__schedules-tabs-wrap",
      activeKey: tabKey,
      tabBarStyle: { margin: "0 32px" },
      items,
      onChange
    }
  )), contextHolder);
});
var schedules_default = Schedules;
