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/components/AdjustTimeAmountPanel.tsx
var AdjustTimeAmountPanel_exports = {};
__export(AdjustTimeAmountPanel_exports, {
  AdjustTimeAmountPanel: () => AdjustTimeAmountPanel
});
module.exports = __toCommonJS(AdjustTimeAmountPanel_exports);
var import_react = __toESM(require("react"));
var import_utils = require("@pisell/utils");
var import_priceKeyboard = require("../../../../pro/priceKeyboard");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import_i18n = require("../i18n");
var formatMoney = (value, currencySymbol) => `${currencySymbol}${Number(value || 0).toFixed(2)}`;
var clampDueAmount = (value, maxValue) => Math.min(Math.max(Number(value) || 0, 0), Math.max(Number(maxValue) || 0, 0));
var resolveDiscountedDueAmount = (autoDueAmount, discountAmount) => clampDueAmount(Number(autoDueAmount || 0) - Number(discountAmount || 0), autoDueAmount);
var buildAmountDueHint = (taxText) => (0, import_i18n.t)("pisell2.adjust-time.amount-due-hint").replace("{tax}", taxText);
var buildAmountDueLabel = (ticketCount) => {
  if (ticketCount <= 1) return (0, import_i18n.t)("pisell2.adjust-time.amount-due");
  return (0, import_i18n.t)("pisell2.adjust-time.amount-due-with-ticket-count").replace("{count}", String(ticketCount)).replace(
    "{tickets}",
    (0, import_i18n.t)("pisell2.adjust-time.ticket-count").replace("{count}", String(ticketCount))
  );
};
var AdjustTimeAmountPanel = ({
  currencySymbol,
  newTotal,
  paidAmount,
  dueAmount,
  autoDueAmount,
  ticketCount = 1,
  unitDueAmount,
  priceInputState,
  onDueAmountChange,
  onPriceInputStateChange,
  onAuto
}) => {
  const context = (0, import_useEngineContext.default)();
  const [keyboardOpen, setKeyboardOpen] = (0, import_react.useState)(false);
  const amountDueHint = (0, import_react.useMemo)(() => {
    var _a, _b;
    const getData = (_b = (_a = context.appHelper) == null ? void 0 : _a.utils) == null ? void 0 : _b.getData;
    const parsedTaxRate = Number((getData == null ? void 0 : getData("tax_rate")) ?? 10);
    const taxRate = Number.isNaN(parsedTaxRate) ? 0.1 : parsedTaxRate / 100;
    const taxTitle = (getData == null ? void 0 : getData("tax_title")) || "GST";
    const includedText = (getData == null ? void 0 : getData("is_price_include_tax")) ? import_utils.locales.getText("pisell2.subtotal.included") : import_utils.locales.getText("pisell2.subtotal.not-contain");
    const taxText = `${taxTitle} ${(taxRate * 100).toFixed(2)}% ${includedText}`;
    return buildAmountDueHint(taxText);
  }, [context]);
  return /* @__PURE__ */ import_react.default.createElement("section", null, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-adjust-time__price-section-title" }, (0, import_i18n.t)("pisell2.adjust-time.amount-due"), ticketCount > 1 ? /* @__PURE__ */ import_react.default.createElement("em", { className: "pisell-adjust-time__ticket-count" }, (0, import_i18n.t)("pisell2.adjust-time.ticket-count").replace("{count}", String(ticketCount))) : null, " ", /* @__PURE__ */ import_react.default.createElement("span", { style: { color: "var(--muted)" } }, amountDueHint)), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-adjust-time__price-grid", style: { marginTop: 8 } }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-adjust-time__price-stat" }, (0, import_i18n.t)("pisell2.adjust-time.new-total"), " ", /* @__PURE__ */ import_react.default.createElement("strong", null, formatMoney(newTotal, currencySymbol))), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-adjust-time__price-stat" }, (0, import_i18n.t)("pisell2.adjust-time.paid"), " ", /* @__PURE__ */ import_react.default.createElement("strong", null, formatMoney(paidAmount, currencySymbol))), /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-adjust-time__amount-editor" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-adjust-time__amount-label" }, buildAmountDueLabel(ticketCount)), /* @__PURE__ */ import_react.default.createElement(
    "button",
    {
      type: "button",
      className: "pisell-adjust-time__amount-input",
      "aria-label": (0, import_i18n.t)("pisell2.adjust-time.amount-due-label"),
      onClick: () => setKeyboardOpen(true)
    },
    /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-adjust-time__amount-input-text" }, formatMoney(dueAmount, currencySymbol))
  ), /* @__PURE__ */ import_react.default.createElement("button", { type: "button", className: "pisell-adjust-time__auto-btn", onClick: onAuto }, (0, import_i18n.t)("pisell2.adjust-time.auto")), ticketCount > 1 ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-adjust-time__amount-multiplier" }, `${formatMoney(unitDueAmount ?? dueAmount / ticketCount, currencySymbol)} x ${ticketCount} = ${formatMoney(dueAmount, currencySymbol)}`) : null)), /* @__PURE__ */ import_react.default.createElement(
    import_priceKeyboard.DiscountKeyboard,
    {
      containerProps: {
        renderType: "modal",
        open: keyboardOpen,
        onCancel: () => setKeyboardOpen(false),
        className: "pisell-discount-keyboard-modal pisell-adjust-time-payment-keyboard-wrap"
      },
      selectType: "dark",
      amountSymbol: currencySymbol,
      defaultValue: String(dueAmount || 0),
      originalValue: String(autoDueAmount || 0),
      valueState: priceInputState,
      onValueStateChange: onPriceInputStateChange,
      doneText: import_utils.locales.getText("confirm") || "Done",
      onEnter: (discountAmount, state) => {
        setKeyboardOpen(false);
        onPriceInputStateChange == null ? void 0 : onPriceInputStateChange(state);
        onDueAmountChange(resolveDiscountedDueAmount(autoDueAmount, discountAmount), state);
      }
    }
  ));
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  AdjustTimeAmountPanel
});
