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/plus/salesSdk/adjustTime/AdjustTimeModal.tsx
var AdjustTimeModal_exports = {};
__export(AdjustTimeModal_exports, {
  AdjustTimeModal: () => AdjustTimeModal
});
module.exports = __toCommonJS(AdjustTimeModal_exports);
var import_react = __toESM(require("react"));
var import_time = require("./utils/time");
var import_useInitLocalesOnce = __toESM(require("../../../hooks/useInitLocalesOnce"));
var import_i18n = require("./i18n");
var import_compensatedPisellContainer = __toESM(require("../../../pro/compensatedPisellContainer"));
var import_AdjustTimeTabs = require("./components/AdjustTimeTabs");
var import_AdjustTimeActionList = require("./components/AdjustTimeActionList");
var import_AdjustTimeComparePanel = require("./components/AdjustTimeComparePanel");
var import_ManualTimeControls = require("./components/ManualTimeControls");
var import_AdjustTimeAmountPanel = require("./components/AdjustTimeAmountPanel");
var import_TicketRatePanel = require("./components/TicketRatePanel");
var import_useAdjustTimeModalController = require("./hooks/useAdjustTimeModalController");
var import_locales = __toESM(require("./locales"));
var import_AdjustTimeModal = require("./AdjustTimeModal.less");
var AdjustTimeModal = ({
  open,
  booking,
  products,
  resourceEndTime,
  shopClosingTime,
  currencySymbol = "$",
  orderTotalAmount,
  orderPaidAmount,
  onCancel,
  onSave,
  onCheckout,
  onTicketCountClick
}) => {
  (0, import_useInitLocalesOnce.default)(import_locales.default);
  const {
    activeAction,
    autoPricing,
    checkoutDisabled,
    dueAmount,
    addedMinutes,
    pricedNewEnd,
    pricedTotalMinutes,
    shouldShowEffectiveUntilHint,
    effectiveUntilTime,
    resourceAvailabilityWarning,
    manualEndTime,
    scenario,
    handleActionChange,
    handleCheckout,
    handleSave,
    handleManualEndTimeChange,
    handleReset,
    priceInputState,
    handleDueAmountChange,
    handleAutoAmount,
    handlePriceInputStateChange
  } = (0, import_useAdjustTimeModalController.useAdjustTimeModalController)({
    open,
    booking,
    products,
    resourceEndTime,
    shopClosingTime,
    onSave,
    onCheckout
  });
  const originalStart = (0, import_time.toDate)(booking.start);
  const originalEnd = (0, import_time.toDate)(booking.end);
  const startTimeHighlighted = scenario.newStart.getTime() !== originalStart.getTime();
  const endTimeHighlighted = pricedNewEnd.getTime() !== originalEnd.getTime();
  const ticketCount = Math.max(1, Number(booking.quantity || 1));
  const totalDueAmount = dueAmount * ticketCount;
  const totalAutoDueAmount = autoPricing.totalPrice * ticketCount;
  const displayOrderTotalAmount = Number(orderTotalAmount ?? booking.paidAmount ?? 0) || 0;
  const displayPaidAmount = Number(orderPaidAmount ?? booking.paidAmount ?? 0) || 0;
  const submitDisabled = checkoutDisabled;
  return /* @__PURE__ */ import_react.default.createElement(
    import_compensatedPisellContainer.default,
    {
      renderType: "modal",
      props: {
        open,
        closable: false,
        width: 920,
        onCancel,
        className: "pisell-adjust-time-modal-container",
        headerDivider: false,
        footerDivider: false,
        title: /* @__PURE__ */ import_react.default.createElement(import_AdjustTimeTabs.AdjustTimeTabs, null),
        footer: /* @__PURE__ */ import_react.default.createElement("footer", { className: "pisell-adjust-time__foot" }, /* @__PURE__ */ import_react.default.createElement("button", { type: "button", className: "pisell-adjust-time__foot-btn", onClick: onCancel }, (0, import_i18n.t)("pisell2.adjust-time.cancel")), /* @__PURE__ */ import_react.default.createElement("button", { type: "button", className: "pisell-adjust-time__foot-btn", onClick: handleReset }, (0, import_i18n.t)("pisell2.adjust-time.reset")), /* @__PURE__ */ import_react.default.createElement("span", null), /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            type: "button",
            className: "pisell-adjust-time__foot-btn",
            disabled: submitDisabled,
            onClick: handleSave
          },
          (0, import_i18n.t)("pisell2.adjust-time.save")
        ), /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            type: "button",
            className: "pisell-adjust-time__foot-btn pisell-adjust-time__foot-btn--checkout",
            disabled: submitDisabled,
            onClick: handleCheckout
          },
          (0, import_i18n.t)("pisell2.adjust-time.checkout")
        )),
        bodyStyle: {
          padding: 0
        },
        styles: {
          content: {
            maxHeight: "100%"
          }
        },
        style: {
          maxHeight: "min(92dvh, 960px)"
        }
      }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-adjust-time__body" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-adjust-time__mode2" }, /* @__PURE__ */ import_react.default.createElement(
      import_AdjustTimeActionList.AdjustTimeActionList,
      {
        booking,
        products,
        activeAction,
        currencySymbol,
        onActionChange: handleActionChange
      }
    ), /* @__PURE__ */ import_react.default.createElement("section", { className: "pisell-adjust-time__main" }, /* @__PURE__ */ import_react.default.createElement(
      import_AdjustTimeComparePanel.AdjustTimeComparePanel,
      {
        title: scenario.title,
        subtitle: scenario.subtitle,
        icon: scenario.icon,
        startAt: scenario.newStart,
        endAt: pricedNewEnd,
        startTimeHighlighted,
        endTimeHighlighted,
        ticketCount,
        onTicketCountClick,
        addedDuration: activeAction === "restart" ? void 0 : (0, import_i18n.formatDurationI18n)(addedMinutes),
        minimumExtensionDuration: activeAction === "restart" || !autoPricing.available ? void 0 : (0, import_i18n.formatDurationI18n)(autoPricing.coveredMinutes),
        totalDuration: `${(0, import_i18n.t)("pisell2.adjust-time.total-prefix")} ${(0, import_i18n.formatDurationI18n)(pricedTotalMinutes)}${(0, import_i18n.t)("pisell2.adjust-time.total-suffix")}`,
        overtimeDuration: activeAction === "restart" || scenario.targetMinutes <= 0 ? void 0 : (0, import_i18n.formatDurationI18n)(scenario.targetMinutes),
        shouldShowEffectiveUntilHint,
        effectiveUntilTime,
        resourceAvailabilityWarning,
        active: open
      }
    ), /* @__PURE__ */ import_react.default.createElement(
      import_ManualTimeControls.ManualTimeControls,
      {
        visible: activeAction === "manualDuration",
        endTime: manualEndTime,
        onEndTimeChange: handleManualEndTimeChange
      }
    ), activeAction !== "restart" ? /* @__PURE__ */ import_react.default.createElement(
      import_AdjustTimeAmountPanel.AdjustTimeAmountPanel,
      {
        currencySymbol,
        newTotal: displayOrderTotalAmount + totalDueAmount,
        paidAmount: displayPaidAmount,
        dueAmount: totalDueAmount,
        autoDueAmount: totalAutoDueAmount,
        ticketCount,
        unitDueAmount: dueAmount,
        priceInputState,
        onDueAmountChange: handleDueAmountChange,
        onPriceInputStateChange: handlePriceInputStateChange,
        onAuto: handleAutoAmount
      }
    ) : null, activeAction !== "restart" ? /* @__PURE__ */ import_react.default.createElement(
      import_TicketRatePanel.TicketRatePanel,
      {
        currencySymbol,
        products,
        hint: activeAction === "manualDuration" ? (0, import_i18n.t)("pisell2.adjust-time.hint-manual-rate") : (0, import_i18n.t)("pisell2.adjust-time.hint-best-rate")
      }
    ) : null)))
  );
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  AdjustTimeModal
});
