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/saleDetail/tmpl/B/components/Pay/index.tsx
var Pay_exports = {};
__export(Pay_exports, {
  Pay: () => Pay
});
module.exports = __toCommonJS(Pay_exports);
var import_react = __toESM(require("react"));
var import_classnames = __toESM(require("classnames"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_utils2 = require("../../../../utils");
var import_usePaymentMethodNameMap = require("../../../../../pisellSalesManagement/hooks/usePaymentMethodNameMap");
var import_index = require("./index.less");
function formatPaymentTime(record) {
  const value = record.payment_time || record.created_at;
  return (0, import_utils2.formatLocalizedDateTime)(value);
}
function getPaymentRecordMethod(record, paymentMethodNameMap) {
  return (0, import_usePaymentMethodNameMap.resolvePaymentMethodName)(record, paymentMethodNameMap);
}
function getPaymentRecordAmount(record) {
  return record.amount ?? 0;
}
function isRefundPaymentRecord(record) {
  const rawType = String(record.type || "").toLowerCase();
  return rawType.includes("refund") || Number(getPaymentRecordAmount(record)) < 0;
}
function Pay({ context }) {
  const paymentMethodNameMap = (0, import_usePaymentMethodNameMap.usePaymentMethodNameMap)();
  const tempOrder = context.sales.tempOrder;
  const summary = context.summary.summary ?? (tempOrder == null ? void 0 : tempOrder.summary) ?? null;
  const symbol = (tempOrder == null ? void 0 : tempOrder.currency_symbol) || "$";
  const payments = Array.isArray(tempOrder == null ? void 0 : tempOrder.payments) ? tempOrder == null ? void 0 : tempOrder.payments : [];
  const overviewItems = [
    {
      key: "total",
      label: import_utils.locales.getText("pisell2.sale-detail.total"),
      value: summary == null ? void 0 : summary.total_amount
    },
    {
      key: "paid",
      label: import_utils.locales.getText("pisell2.sale-detail.pay.paid"),
      value: summary == null ? void 0 : summary.order_paid_amount
    },
    {
      key: "refunded",
      label: import_utils.locales.getText("pisell2.sale-detail.pay.refunded"),
      value: summary == null ? void 0 : summary.total_refund_amount,
      tone: "warning"
    },
    {
      key: "toPay",
      label: import_utils.locales.getText("pisell2.sale-detail.to-pay"),
      value: summary == null ? void 0 : summary.amount_gap
    }
  ];
  return /* @__PURE__ */ import_react.default.createElement("main", { className: "pisell-sale-detail-main pisell-sale-detail-pay-main" }, /* @__PURE__ */ import_react.default.createElement("section", { className: "pisell-sale-detail-pay-overview" }, overviewItems.map((item) => /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      key: item.key,
      className: (0, import_classnames.default)("pisell-sale-detail-pay-overview__item", {
        "pisell-sale-detail-pay-overview__item--warning": item.tone === "warning"
      })
    },
    /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-pay-overview__label" }, item.label),
    /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-pay-overview__value" }, (0, import_utils.formatAmount)(item.value ?? 0, 2, symbol))
  ))), /* @__PURE__ */ import_react.default.createElement("section", { className: "pisell-sale-detail-pay-timeline" }, payments.length ? payments.map((payment, index) => {
    const isRefund = isRefundPaymentRecord(payment);
    const amount = getPaymentRecordAmount(payment);
    const signedAmount = isRefund ? -Math.abs(Number(amount)) : amount;
    return /* @__PURE__ */ import_react.default.createElement(
      "article",
      {
        key: payment.order_payment_id || index,
        className: (0, import_classnames.default)("pisell-sale-detail-pay-record", {
          "pisell-sale-detail-pay-record--refund": isRefund
        })
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-pay-record__date" }, formatPaymentTime(payment)),
      /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-pay-record__content" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-pay-record__title" }, isRefund ? import_utils.locales.getText("pisell2.sale-detail.refund") : import_utils.locales.getText("pisell2.sale-detail.pay.payment"), " · ", getPaymentRecordMethod(payment, paymentMethodNameMap)), /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-pay-record__amount" }, (0, import_utils.formatAmount)(signedAmount, 2, symbol)))
    );
  }) : /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-pay-timeline__empty" }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellEmpty,
    {
      description: import_utils.locales.getText(
        "pisell2.sale-detail.pay.empty"
      )
    }
  ))));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Pay
});
