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/Cart/ContinueButton/index.tsx
var ContinueButton_exports = {};
__export(ContinueButton_exports, {
  default: () => ContinueButton_default
});
module.exports = __toCommonJS(ContinueButton_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_materials = require("@pisell/materials");
var import_useEngineContext = __toESM(require("../../../../../hooks/useEngineContext"));
var import_hooks = require("../../../hooks");
var import_context = require("../../../context");
var import_utils2 = require("../utils");
var import_index = require("./index.less");
var ContinueButton = ({ onNext }) => {
  var _a, _b, _c;
  const context = (0, import_useEngineContext.default)();
  const utils = context.appHelper.utils || {};
  const { isLogin, openLoginModal } = (0, import_hooks.useAppointmentBookingLogin)();
  const { accountLists, getHolders, checkAccount } = (0, import_hooks.useAppointmentBookingAccount)();
  const {
    currentStep,
    carts,
    appointmentBooking,
    setCarts,
    loading,
    setIsErrorHolder,
    isLastStep
  } = (0, import_context.useAppointmentBookingContext)();
  const { isFormSubject, isRetailTemplate } = (0, import_hooks.useAppointmentBookingSetting)();
  const stepList = (0, import_react.useMemo)(() => {
    var _a2, _b2, _c2;
    return (_c2 = (_b2 = (_a2 = appointmentBooking == null ? void 0 : appointmentBooking.store) == null ? void 0 : _a2.step) == null ? void 0 : _b2.store) == null ? void 0 : _c2.stepList;
  }, [(_c = (_b = (_a = appointmentBooking == null ? void 0 : appointmentBooking.store) == null ? void 0 : _a.step) == null ? void 0 : _b.store) == null ? void 0 : _c.stepList]);
  const handleCheckAccount = () => {
    if (isRetailTemplate) return false;
    const result = (0, import_utils2.checkHolder)({
      isFormSubject,
      checkAccount,
      carts
    });
    if (result) {
      setCarts(result);
    }
    setIsErrorHolder(!!result);
    return !!result;
  };
  const handleLoginCheck = async () => {
    return await (0, import_utils2.checkLogin)({
      isLogin,
      openLoginModal,
      isFormSubject,
      utils,
      accountLists,
      appointmentBooking,
      getHolders
    });
  };
  const handleContinue = async () => {
    try {
      return onNext && onNext();
    } catch (error) {
      console.log(error, "handleContinue_error");
    }
  };
  const continueText = (0, import_react.useMemo)(() => {
    if (isLastStep) {
      return import_utils.locales.getText("pisell2.event.checkout");
    } else {
      return import_utils.locales.getText("pisell2.event.close.continue");
    }
  }, [isLastStep]);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_materials.Button,
    {
      disabled: !(carts == null ? void 0 : carts.length),
      size: "large",
      type: "primary",
      onClick: () => handleContinue(),
      loading
    },
    continueText
  ));
};
var ContinueButton_default = ContinueButton;
