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/info/main.tsx
var main_exports = {};
__export(main_exports, {
  default: () => main_default
});
module.exports = __toCommonJS(main_exports);
var import_utils = require("@pisell/utils");
var import_react = __toESM(require("react"));
var import_footer = __toESM(require("../components/footer"));
var import_tabPane = __toESM(require("../components/tabPane"));
var import_locales = __toESM(require("../locales"));
var import_addNote = __toESM(require("../notes/addNote"));
var import_client = __toESM(require("./client"));
var import_date = __toESM(require("./date"));
var import_header = __toESM(require("./header"));
var import_model = require("./model");
var import_pet = __toESM(require("./pet"));
var import_service = __toESM(require("./service"));
var import_antd = require("antd");
var import_classnames = __toESM(require("classnames"));
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var import_useCreateBookingPageHeader = __toESM(require("../hooks/useCreateBookingPageHeader"));
var import_utils2 = require("../utils");
var import_date2 = require("./date");
var import_locales2 = require("../../../utils/locales");
var import_index = require("./index.less");
var import_notes = __toESM(require("./notes"));
var import_service2 = require("./service2");
var import_utils3 = require("./service2/utils");
var defaultModules = {
  client: 1,
  date: 1,
  service: 1,
  holder: 1,
  note: 1,
  service2: 0
};
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;
  const { style, globalState, modules = defaultModules, slot } = props;
  const modal = (0, import_react.useContext)(import_model.Context);
  const context = (0, import_useEngineContext.default)();
  import_utils2.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 { createHeader, isBookingCreatePage, isBookingCreatePageCreateMode } = (0, import_useCreateBookingPageHeader.default)(globalState);
  (0, import_react.useEffect)(() => {
    document.body.id = "body";
    if (props.setState) {
      props.setState({
        bookingFunctions: {
          formatResource: import_utils2.formatResource,
          getErrorList: import_utils2.getErrorList,
          sliceDayIntoFiveMinutes: import_utils2.sliceDayIntoFiveMinutes,
          findNextDuration: import_utils2.findNextDuration,
          flexibleObj: import_utils2.flexibleObj,
          updateServiceDate: import_date2.updateServiceDate
        }
      });
    }
  }, []);
  (0, import_react.useEffect)(() => {
    var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j, _k, _l, _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 = (_l = (_k = (_j = (_i2 = (_h2 = context == null ? void 0 : context.appHelper) == null ? void 0 : _h2.utils) == null ? void 0 : _i2.store) == null ? void 0 : _j.getState()) == null ? void 0 : _k.global) == null ? void 0 : _l.globalConfig) == null ? void 0 : _m.timezone,
        isDayBooking: (globalState == null ? void 0 : globalState.renderType) === "dayBooking"
      }
    });
  }, [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)(() => {
    var _a2, _b2, _c2, _d2;
    if (!modules.note) {
      return null;
    }
    if ((0, import_utils3.isEventBooking)(modal.state)) {
      return null;
    }
    if ((0, import_utils3.isDayBooking)(globalState)) {
      return /* @__PURE__ */ import_react.default.createElement(import_addNote.default, { value: (_b2 = (_a2 = modal.state) == null ? void 0 : _a2.notes) == null ? void 0 : _b2.orderNote, onChange: addNote });
    }
    return (globalState == null ? void 0 : globalState.bookingId) ? globalState.renderType === "eventBooking" || globalState.isBookingCreatePage ? /* @__PURE__ */ import_react.default.createElement(import_notes.default, null) : null : /* @__PURE__ */ import_react.default.createElement(import_addNote.default, { value: (_d2 = (_c2 = modal.state) == null ? void 0 : _c2.notes) == null ? void 0 : _d2.orderNote, onChange: addNote });
  }, [
    modules.note,
    globalState == null ? void 0 : globalState.bookingId,
    globalState.render,
    (_f = (_e = modal.state) == null ? void 0 : _e.notes) == null ? void 0 : _f.orderNote
  ]);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, !!modal.state.setGlobalState ? /* @__PURE__ */ import_react.default.createElement(
    import_tabPane.default,
    {
      style: {
        ...style,
        height: ((_h = (_g = context == null ? void 0 : context.appHelper) == null ? void 0 : _g.utils) == null ? void 0 : _h.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 && !(0, import_utils3.isTerminalDayBooking)(modal.state)
      })
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "booking-info" }, createHeader, modules.client ? /* @__PURE__ */ import_react.default.createElement(import_client.default, null) : null, modules.holder && !((_i = modal.state) == null ? void 0 : _i.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,
      modules.service2 ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, modal.state.date.value ? /* @__PURE__ */ import_react.default.createElement(import_service2.Service2Cart, null) : null) : null,
      notes,
      slot ? slot : null
    ))
  ) : null);
});
var main_default = Info;
