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/booking/info2/index.tsx
var info2_exports = {};
__export(info2_exports, {
  default: () => info2_default
});
module.exports = __toCommonJS(info2_exports);
var import_react = __toESM(require("react"));
var import_model = require("../info/model");
var import_client = __toESM(require("../info/client"));
var import_service = __toESM(require("./service"));
var import_pet = __toESM(require("../info/pet"));
var import_date = __toESM(require("../info/date"));
var import_footer = __toESM(require("../components/footer"));
var import_tabPane = __toESM(require("../components/tabPane"));
var import_header = __toESM(require("../info/header"));
var import_locales = __toESM(require("../locales"));
var import_utils = require("@pisell/utils");
var import_reloadResourceModal = __toESM(require("../components/reloadResourceModal"));
var import_utils2 = require("@pisell/utils");
var import_utils3 = require("../utils");
var import_utilsByBooking = require("./utilsByBooking");
var import_utilsByBooking2 = require("./utilsByBooking");
var import_serve = require("./serve");
var import_date2 = require("../info/date");
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var import_notes = __toESM(require("../info/notes"));
var import_info = require("../info/index.less");
var import_antd = require("antd");
var import_classnames = __toESM(require("classnames"));
var import_useCreateBookingPageHeader = __toESM(require("../hooks/useCreateBookingPageHeader"));
var import_locales2 = require("../../../utils/locales");
var import_ahooks = require("ahooks");
var import_cartClientCard = __toESM(require("./cartClientCard"));
var import_materials = require("@pisell/materials");
var defaultModules = {
  client: 1,
  date: 1,
  service: 1,
  holder: 1,
  note: 1
};
import_utils.locales.init(import_locales.default, (0, import_locales2.getLocale)());
var Info = (0, import_model.Provider)((props) => {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
  const { style, globalState, modules = defaultModules, slot } = props;
  const modal = (0, import_react.useContext)(import_model.Context);
  const context = (0, import_useEngineContext.default)();
  import_utils3.request.setRequest(context.appHelper.utils.request);
  const params = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2, _d2;
    return ((_d2 = (_c2 = (_b2 = (_a2 = modal.state) == null ? void 0 : _a2.bookingConfig) == null ? void 0 : _b2.config) == null ? void 0 : _c2.basic) == null ? void 0 : _d2.appointment_subject) || {};
  }, [(_d = (_c = (_b = (_a = modal.state) == null ? void 0 : _a.bookingConfig) == null ? void 0 : _b.config) == null ? void 0 : _c.basic) == null ? void 0 : _d.appointment_subject]);
  const stateRef = (0, import_react.useRef)(globalState);
  stateRef.current = globalState;
  const { createHeader, isBookingCreatePage, isBookingCreatePageCreateMode } = (0, import_useCreateBookingPageHeader.default)(globalState);
  (0, import_react.useEffect)(() => {
    document.body.id = "body";
    if (props.setState) {
      props.setState({
        bookingFunctions: {
          formatResource: import_utilsByBooking.formatResource,
          getErrorList: import_utilsByBooking2.getErrorList,
          sliceDayIntoFiveMinutes: import_utils3.sliceDayIntoFiveMinutes,
          findNextDuration: import_utils3.findNextDuration,
          flexibleObj: import_utils3.flexibleObj,
          updateServiceDate: import_date2.updateServiceDate
        }
      });
    }
  }, []);
  (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m;
    const isFranchisee = (_d2 = (_c2 = (_b2 = (_a2 = context == null ? void 0 : context.appHelper) == null ? void 0 : _a2.utils) == null ? void 0 : _b2.businessUtils) == null ? void 0 : _c2.getAppByModal) == null ? void 0 : _d2.call(_c2, "franchisee");
    modal.dispatch({
      type: "setState",
      payload: {
        setGlobalState: props.setGlobalState,
        ...globalState,
        isTerminal: (_g2 = (_f2 = (_e2 = context == null ? void 0 : context.appHelper) == null ? void 0 : _e2.utils) == null ? void 0 : _f2.isTerminal) == null ? void 0 : _g2.call(_f2),
        isFranchisee,
        timezone: (_m = (_l2 = (_k2 = (_j2 = (_i2 = (_h2 = context == null ? void 0 : context.appHelper) == null ? void 0 : _h2.utils) == null ? void 0 : _i2.store) == null ? void 0 : _j2.getState()) == null ? void 0 : _k2.global) == null ? void 0 : _l2.globalConfig) == null ? void 0 : _m.timezone
      }
    });
  }, [globalState]);
  const addNote = (e) => {
    modal.dispatch({
      type: "setNotes",
      payload: {
        orderNote: e,
        edit: true
      }
    });
  };
  const header = (0, import_react.useMemo)(() => {
    if ((globalState == null ? void 0 : globalState.renderType) === "eventBooking") {
      return import_utils.locales.getText("pisell2.text.enroll.detail");
    }
    return (globalState == null ? void 0 : globalState.bookingId) ? /* @__PURE__ */ import_react.default.createElement(import_header.default, { state: modal.state, dispatch: modal.dispatch }) : /* @__PURE__ */ import_react.default.createElement("div", { className: "", style: { height: 0 } });
  }, [
    globalState == null ? void 0 : globalState.bookingId,
    modal.state,
    modal.dispatch,
    globalState == null ? void 0 : globalState.renderType
  ]);
  const notes = (0, import_react.useMemo)(() => {
    if (!modules.note) {
      return null;
    }
    return (globalState == null ? void 0 : globalState.bookingId) ? globalState.renderType === "eventBooking" ? /* @__PURE__ */ import_react.default.createElement(import_notes.default, null) : null : (
      // <AddNote value={modal.state?.notes?.orderNote} onChange={addNote} />
      null
    );
  }, [
    modules.note,
    globalState == null ? void 0 : globalState.bookingId,
    globalState.render,
    (_f = (_e = modal.state) == null ? void 0 : _e.notes) == null ? void 0 : _f.orderNote
  ]);
  const currentDate = (0, import_react.useMemo)(() => {
    var _a2, _b2;
    if ((_b2 = (_a2 = modal.state) == null ? void 0 : _a2.date) == null ? void 0 : _b2.value) {
      return modal.state.date.value.format("YYYY-MM-DD");
    }
    return null;
  }, [(_i = (_h = (_g = modal.state) == null ? void 0 : _g.date) == null ? void 0 : _h.value) == null ? void 0 : _i.format("YYYY-MM-DD")]);
  const getResourcesData = async () => {
    let bookingResourceList = localStorage.getItem("bookingResourceList");
    let timeoutNumber = 0;
    if (bookingResourceList) {
      bookingResourceList = JSON.parse(bookingResourceList);
      if ((bookingResourceList == null ? void 0 : bookingResourceList.date) === currentDate) {
        timeoutNumber = 200;
        modal.dispatch({
          type: "setService",
          payload: {
            ...stateRef.current.service,
            resourcesOrigin: bookingResourceList.list || [],
            resourcesOriginMap: bookingResourceList.listMap
          }
        });
      }
    }
    return new Promise((resolve, reject) => {
      setTimeout(async () => {
        var _a2, _b2, _c2, _d2;
        try {
          let data = await (0, import_serve.getResourceList)(
            {
              date: currentDate
            },
            (_d2 = (_c2 = (_b2 = (_a2 = stateRef == null ? void 0 : stateRef.current) == null ? void 0 : _a2.service) == null ? void 0 : _b2.value) == null ? void 0 : _c2.map) == null ? void 0 : _d2.call(_c2, (item) => item == null ? void 0 : item.booking_id)
          );
          try {
            data.date = currentDate;
            localStorage.setItem("bookingResourceList", JSON.stringify(data));
          } catch (error) {
            (0, import_utils2.sendWarningLog)({
              title: `设置资源失败`,
              content: [
                {
                  key: "error",
                  value: JSON.stringify({
                    message: error == null ? void 0 : error.message,
                    stack: error == null ? void 0 : error.stack,
                    name: error == null ? void 0 : error.name
                  })
                }
              ]
            });
          }
          modal.dispatch({
            type: "setService",
            payload: {
              ...stateRef.current.service,
              resourcesOrigin: data.list || [],
              resourcesOriginMap: data.listMap,
              reloadResourceModal: false
            }
          });
          resolve(data);
        } catch (error) {
          (0, import_utils2.sendWarningLog)({
            title: `获取资源失败`,
            content: [
              {
                key: "error",
                value: JSON.stringify({
                  message: error == null ? void 0 : error.message,
                  stack: error == null ? void 0 : error.stack,
                  name: error == null ? void 0 : error.name
                })
              }
            ]
          });
          modal.dispatch({
            type: "setService",
            payload: {
              ...stateRef.current.service,
              reloadResourceModal: true
            }
          });
          reject(error);
        }
      }, timeoutNumber);
    });
  };
  (0, import_ahooks.useDebounceEffect)(
    () => {
      if (currentDate) {
        getResourcesData();
      }
    },
    [currentDate],
    {
      wait: 300
    }
  );
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_reloadResourceModal.default,
    {
      modal,
      onReload: getResourcesData,
      onCancel: () => {
        modal.dispatch({
          type: "setService",
          payload: {
            ...stateRef.current.service,
            reloadResourceModal: false
          }
        });
      }
    }
  ), !!modal.state.setGlobalState ? /* @__PURE__ */ import_react.default.createElement(
    import_tabPane.default,
    {
      style: {
        height: ((_k = (_j = context == null ? void 0 : context.appHelper) == null ? void 0 : _j.utils) == null ? void 0 : _k.isMobile) ? "100%" : "100vh"
      },
      header,
      footer: /* @__PURE__ */ import_react.default.createElement(
        import_footer.default,
        {
          state: modal.state,
          dispatch: modal.dispatch,
          source: "info"
        }
      ),
      bodyClassName: (0, import_classnames.default)("booking-info-warp", {
        ["create-booking-page-info-wrap"]: isBookingCreatePage,
        ["create-booking-page-info-wrap-create"]: isBookingCreatePageCreateMode
      }),
      state: modal.state,
      dispatch: modal.dispatch,
      source: "info"
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "booking-info" }, createHeader, /* @__PURE__ */ import_react.default.createElement("div", { className: "booking-info-client-line" }, modules.client ? (globalState == null ? void 0 : globalState.isBookingTicket2) ? /* @__PURE__ */ import_react.default.createElement("div", { style: { flex: 1, overflow: "hidden" } }, /* @__PURE__ */ import_react.default.createElement(import_cartClientCard.default, null)) : /* @__PURE__ */ import_react.default.createElement(import_client.default, null) : null, (globalState == null ? void 0 : globalState.isBookingTicket2) ? /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "booking-info-client-line-code",
        onClick: () => {
          var _a2;
          (_a2 = globalState == null ? void 0 : globalState.onQrCodeClick) == null ? void 0 : _a2.call(globalState);
        }
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_materials.Iconfont,
        {
          type: "pisell2-a-qr-code-02",
          style: { color: "#fff", fontSize: 42 }
        }
      )
    ) : null), modules.holder && !((_l = modal.state) == null ? void 0 : _l.disabledEdit) ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, params.type === "form" ? /* @__PURE__ */ import_react.default.createElement(import_pet.default, null) : null) : null, modules.date ? /* @__PURE__ */ import_react.default.createElement(import_date.default, null) : null, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Skeleton,
      {
        loading: globalState.loading,
        round: true,
        active: true,
        avatar: false,
        style: { paddingTop: 20 }
      },
      modules.service ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, modal.state.date.value ? /* @__PURE__ */ import_react.default.createElement(import_service.default, null) : null) : null,
      notes,
      slot ? slot : null
    ))
  ) : null);
});
var info2_default = Info;
