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/appointmentBooking/components/Content/index.tsx
var Content_exports = {};
__export(Content_exports, {
  default: () => Content_default
});
module.exports = __toCommonJS(Content_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_Item = __toESM(require("../Cart/Item"));
var import_Header = __toESM(require("../Header"));
var import_Footer = __toESM(require("../Footer"));
var import_Services = __toESM(require("../Services"));
var import_Date = __toESM(require("../Date"));
var import_Resource = __toESM(require("../Resource"));
var import_TimeSlicing = __toESM(require("../TimeSlicing"));
var import_Guest = __toESM(require("../Guest"));
var import_Form = __toESM(require("../Form"));
var import_ConfirmInformation = __toESM(require("../ConfirmInformation"));
var import_context = require("../../context");
var import_PolicyModal = __toESM(require("../../deposit/components/PolicyModal"));
var import_utils2 = require("../Resource/utils");
var import_hooks = require("../../hooks");
var import_index = require("./index.less");
var import_useComponents = __toESM(require("../../../../hooks/useComponents"));
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_utils3 = require("../../utils");
var Layout = () => {
  var _a, _b, _c, _d, _e, _f;
  const stepRef = (0, import_react.useRef)();
  const {
    currentStep,
    setResourceOtherParams,
    resourceOtherParams,
    setIsAgreeDepositPolicy,
    appointmentBooking,
    setLoading,
    policyParams,
    closePolicy,
    currentStepParams,
    setIsErrorHolder
  } = (0, import_context.useAppointmentBookingContext)();
  const { isDateSelectedFirst, isFormSubject, isRetailTemplate } = (0, import_hooks.useAppointmentBookingSetting)();
  const { isLogin } = (0, import_hooks.useAppointmentBookingLogin)();
  const { getHolders } = (0, import_hooks.useAppointmentBookingAccount)();
  const { removeStep } = (0, import_hooks.useAppointmentBookingStep)();
  const { shopDiscount } = (0, import_hooks.useShopDiscount)();
  const { customPageData } = (_a = (0, import_useEngineContext.default)().engine) == null ? void 0 : _a.props;
  const [CustomComponent] = (0, import_useComponents.default)({
    components: ["CustomComponent"]
  });
  console.log("CustomComponent:", CustomComponent, typeof CustomComponent, CustomComponent == null ? void 0 : CustomComponent.$$typeof);
  (0, import_hooks.useAppointmentBookingCart)();
  (0, import_hooks.useAppointmentBookingStep)();
  const [params, setParams] = (0, import_react.useState)({});
  const utils = (0, import_hooks.contextUtils)();
  const context = (0, import_useEngineContext.default)();
  const { pubsub } = context.appHelper.utils;
  (0, import_react.useEffect)(() => {
    const handleLoginSuccess = async (res) => {
      var _a2;
      if (!isFormSubject) {
        const user = JSON.parse(((_a2 = utils == null ? void 0 : utils.storage) == null ? void 0 : _a2.get("customer")) || "{}");
        const currentUser = (0, import_utils3.formatCustomer)(user);
        const accountLists = await appointmentBooking.getAccounts();
        const meAccount = accountLists == null ? void 0 : accountLists.find((d) => !(d == null ? void 0 : d.isGuest));
        appointmentBooking.setLoginAccount(meAccount == null ? void 0 : meAccount.id, currentUser);
      } else {
        if (!isRetailTemplate) {
          getHolders();
        }
      }
    };
    pubsub.subscribe("pisell1.login.success", handleLoginSuccess);
    return () => {
      pubsub.unsubscribe("pisell1.login.success", handleLoginSuccess);
    };
  }, []);
  (0, import_react.useEffect)(() => {
    appointmentBooking.removeStep("fill-form");
    return () => {
      var _a2;
      setIsAgreeDepositPolicy(false);
      appointmentBooking.destroy();
      (_a2 = shopDiscount == null ? void 0 : shopDiscount.destroy) == null ? void 0 : _a2.call(shopDiscount);
    };
  }, []);
  (0, import_react.useEffect)(() => {
    var _a2;
    if ((currentStepParams == null ? void 0 : currentStepParams.index) < 0) return;
    const resourceStepIndex = (_a2 = currentStepParams == null ? void 0 : currentStepParams.stepLists) == null ? void 0 : _a2.findIndex(
      (item) => item.key === "select-resource"
    );
    if ((currentStepParams == null ? void 0 : currentStepParams.index) < resourceStepIndex) {
      appointmentBooking.setOtherData("current_selected_resources", null);
    }
  }, [currentStepParams]);
  (0, import_react.useEffect)(() => {
    var _a2, _b2;
    try {
      if (!(appointmentBooking == null ? void 0 : appointmentBooking.otherParams) || isRetailTemplate) return;
      const showAddGuest = (_b2 = (_a2 = appointmentBooking == null ? void 0 : appointmentBooking.otherParams) == null ? void 0 : _a2.productModuleParams) == null ? void 0 : _b2.showAddGuest;
      if (isFormSubject || !showAddGuest) {
        removeStep("select-guest");
      } else {
        appointmentBooking.addStep(
          {
            key: "select-guest",
            description: import_utils.locales.getText("pisell2.appointment.add-guests")
          },
          "select-service"
        );
      }
    } catch (error) {
    }
  }, [isFormSubject, isRetailTemplate]);
  (0, import_react.useEffect)(() => {
    if (isFormSubject && isLogin && !isRetailTemplate) {
      getHolders();
    }
  }, [isFormSubject, isLogin, isRetailTemplate]);
  (0, import_react.useEffect)(() => {
    var _a2;
    if (!(currentStep == null ? void 0 : currentStep.step)) return;
    setLoading(false);
    setResourceOtherParams({
      ...resourceOtherParams,
      errorList: null
    });
    setIsErrorHolder(false);
    window.scrollTo({
      top: 0,
      behavior: "smooth"
    });
    if (((_a2 = currentStep == null ? void 0 : currentStep.step) == null ? void 0 : _a2.key) === "confirm-information") {
      (0, import_utils2.scrollToFirstErrorCard)(".pisell-lowcode-product-card-error");
    }
  }, [(_b = currentStep == null ? void 0 : currentStep.step) == null ? void 0 : _b.key]);
  const components = {
    // 选择服务
    "select-service": import_Services.default,
    // 添加客户
    "select-guest": import_Guest.default,
    // 选择时间
    "select-date": import_Date.default,
    // 时间切片
    "select-time": import_TimeSlicing.default,
    // 确认信息
    "confirm-information": import_ConfirmInformation.default
  };
  const Com = (0, import_react.useMemo)(() => {
    var _a2;
    const key = (_a2 = currentStep == null ? void 0 : currentStep.step) == null ? void 0 : _a2.key;
    if (!key) return null;
    let Com2;
    if (key.startsWith("select-resource")) {
      Com2 = import_Resource.default;
    } else if (key.startsWith("fill-form")) {
      Com2 = import_Form.default;
    } else {
      Com2 = components[key];
    }
    if (key === "select-service") {
      return /* @__PURE__ */ import_react.default.createElement(CustomComponent, { block: customPageData == null ? void 0 : customPageData.block, customComponents: {
        product_list: /* @__PURE__ */ import_react.default.createElement(Com2, { onChange: setParams, params, ref: stepRef })
      } });
    } else {
      return /* @__PURE__ */ import_react.default.createElement(Com2, { onChange: setParams, params, ref: stepRef });
    }
  }, [(_c = currentStep == null ? void 0 : currentStep.step) == null ? void 0 : _c.key]);
  (0, import_react.useEffect)(() => {
    var _a2, _b2;
    if ((0, import_utils.isMobile)()) {
      const header = document.querySelector(".event-progress-bar");
      const footer = document.querySelector(".pisell-section-footers-wrapper") || document.querySelector("#layout-footer");
      const content = document.querySelector(
        ".parallel-content-mobile-wrap"
      );
      const headerHeight = ((_a2 = header == null ? void 0 : header.getBoundingClientRect()) == null ? void 0 : _a2.height) || 0;
      const footerHeight = ((_b2 = footer == null ? void 0 : footer.getBoundingClientRect()) == null ? void 0 : _b2.height) || 0;
      const windowHeight = window.innerHeight;
      const contentHeight = windowHeight - headerHeight - footerHeight;
      if (content && (content == null ? void 0 : content.style)) {
        content.style.height = `${contentHeight}px`;
        content.style.overflowY = "auto";
      }
    }
  }, [(_d = currentStep == null ? void 0 : currentStep.step) == null ? void 0 : _d.key]);
  const isShowCartCom = (0, import_react.useMemo)(() => {
    var _a2;
    const key = (_a2 = currentStep == null ? void 0 : currentStep.step) == null ? void 0 : _a2.key;
    if ((0, import_utils.isMobile)()) return null;
    if (isDateSelectedFirst && key === "select-date") {
      return null;
    }
    return /* @__PURE__ */ import_react.default.createElement("div", { className: "parallel-content-right" }, /* @__PURE__ */ import_react.default.createElement(import_Item.default, { onNext: () => {
      var _a3, _b2;
      return (_b2 = (_a3 = stepRef == null ? void 0 : stepRef.current) == null ? void 0 : _a3.next) == null ? void 0 : _b2.call(_a3);
    } }));
  }, [isDateSelectedFirst, (_e = currentStep == null ? void 0 : currentStep.step) == null ? void 0 : _e.key]);
  const isFooter = (0, import_react.useMemo)(() => {
    var _a2;
    if (!(0, import_utils.isMobile)()) return false;
    const key = (_a2 = currentStep == null ? void 0 : currentStep.step) == null ? void 0 : _a2.key;
    if (isDateSelectedFirst && key === "select-date") return false;
    return key !== "confirm-information";
  }, [isDateSelectedFirst, (_f = currentStep == null ? void 0 : currentStep.step) == null ? void 0 : _f.key]);
  const depositProtocolRequest = (id) => {
    var _a2;
    return (_a2 = appointmentBooking == null ? void 0 : appointmentBooking.getProtocol) == null ? void 0 : _a2.call(appointmentBooking, id);
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, !isRetailTemplate ? /* @__PURE__ */ import_react.default.createElement(import_Header.default, null) : null, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: `parallel-content-wrap ${(0, import_utils.isMobile)() ? "parallel-content-mobile-wrap" : ""} ${isRetailTemplate ? "parallel-content-retail-wrap" : ""}`
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "parallel-content-left" }, Com),
    isShowCartCom
  ), isFooter ? /* @__PURE__ */ import_react.default.createElement(
    import_Footer.default,
    {
      onNext: () => {
        var _a2, _b2;
        return (_b2 = (_a2 = stepRef == null ? void 0 : stepRef.current) == null ? void 0 : _a2.next) == null ? void 0 : _b2.call(_a2);
      }
    }
  ) : null, (policyParams == null ? void 0 : policyParams.open) ? /* @__PURE__ */ import_react.default.createElement(
    import_PolicyModal.default,
    {
      key: policyParams == null ? void 0 : policyParams._ts,
      open: policyParams == null ? void 0 : policyParams.open,
      onCancel: () => closePolicy(false),
      onConfirm: () => closePolicy(true),
      item: policyParams == null ? void 0 : policyParams.content,
      onChange: () => setLoading(false),
      isHideCheckout: false,
      depositProtocolRequest
    }
  ) : null);
};
var Content_default = Layout;
