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/components/AmountDetails/index.tsx
var AmountDetails_exports = {};
__export(AmountDetails_exports, {
  AmountDetails: () => AmountDetails
});
module.exports = __toCommonJS(AmountDetails_exports);
var import_antd = require("antd");
var import_classnames = __toESM(require("classnames"));
var import_react = __toESM(require("react"));
var import_materials = require("@pisell/materials");
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../../../hooks/useEngineContext"));
var import__ = require("../../../../index");
var import_index = require("./index.less");
var EMPTY_AMOUNT_VIEW = {
  totalText: "",
  arrearsText: "",
  subTotalList: [],
  orderTotalList: [],
  hasOrderTotal: false
};
function AmountDetails({
  dataSource
}) {
  var _a, _b, _c;
  const context = (0, import_useEngineContext.default)();
  const { getData } = (_a = context.appHelper) == null ? void 0 : _a.utils;
  const [showDetail, setShowDetail] = (0, import_react.useState)(false);
  const amountView = (0, import_react.useMemo)(() => {
    const tempOrder = dataSource.sales.tempOrder;
    const summary = dataSource.summary.summary;
    if (!tempOrder || !summary) {
      return EMPTY_AMOUNT_VIEW;
    }
    const symbol = context.appHelper.utils.getSymbolic();
    const translationOriginal = context.appHelper.utils.translationOriginal;
    const hasPayment = tempOrder.payments.length > 0;
    const parsedTaxRate = Number(getData("tax_rate") ?? 10);
    const surcharges = summary.surcharges ? summary.surcharges : [];
    const surchargeList = surcharges.filter((surcharge) => surcharge.name).map((surcharge) => ({
      key: `custom_surcharge_${surcharge.surcharge_id}`,
      value: surcharge.amount,
      label: translationOriginal(surcharge.name)
    }));
    const subTotalList = [
      {
        key: "sub_total",
        value: summary.product_amount
      },
      ...surchargeList,
      {
        key: "tax",
        value: summary.tax_fee,
        tax: {
          is_price_include_tax: getData("is_price_include_tax"),
          rate: Number.isNaN(parsedTaxRate) ? 0.1 : parsedTaxRate / 100,
          title: getData("tax_title") || "GST"
        }
      },
      {
        key: "discount",
        value: summary.discount_amount
      },
      {
        key: "expect_amount",
        value: summary.expect_amount,
        label: import_utils.locales.getText("pisell2.sale-detail.total")
      },
      {
        hidden: !Number(summary.rounding_amount),
        key: "custom_roundingAmount",
        value: summary.rounding_amount,
        label: import_utils.locales.getText("pisell2.sale-detail.rounding")
      }
    ];
    const orderTotalList = [
      {
        hidden: !hasPayment,
        key: "custom_orderPaidAmount",
        value: summary.order_paid_amount,
        label: import_utils.locales.getText("pisell2.text.amount-paid-on-order")
      },
      {
        hidden: !hasPayment,
        key: "custom_actualPaidAmount",
        value: summary.customer_paid_amount,
        label: import_utils.locales.getText("pisell2.text.amount-actually-paid-by-the-customer")
      },
      {
        hidden: !hasPayment || !Number(summary.total_refund_amount),
        key: "custom_totalRefundAmount",
        value: summary.total_refund_amount,
        label: import_utils.locales.getText("pisell2.text.refunded-amount")
      }
    ];
    return {
      totalText: `${import_utils.locales.getText("pisell2.sale-detail.to-pay")}: ${(0, import_utils.formatAmount)(summary.total_amount, 2, symbol)}`,
      arrearsText: "",
      subTotalList,
      orderTotalList,
      hasOrderTotal: hasPayment
    };
  }, [context, (_b = dataSource.sales) == null ? void 0 : _b.tempOrder, (_c = dataSource.summary) == null ? void 0 : _c.summary]);
  return /* @__PURE__ */ import_react.default.createElement(
    "section",
    {
      className: (0, import_classnames.default)("pisell-sale-detail-amount-details", {
        "pisell-sale-detail-amount-details--open": showDetail
      })
    },
    /* @__PURE__ */ import_react.default.createElement(import_antd.Skeleton, { title: false, round: true, loading: false, active: true }, /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-amount-details__summary" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-amount-details__summary-left" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-amount-details__summary-total" }, amountView.totalText), /* @__PURE__ */ import_react.default.createElement("span", { className: "pisell-sale-detail-amount-details__summary-arrears" }, amountView.arrearsText)), /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        className: "pisell-sale-detail-amount-details__details-trigger",
        onClick: () => setShowDetail(!showDetail)
      },
      import_utils.locales.getText("pisell2.sale-detail.details"),
      " ",
      /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: (0, import_classnames.default)(
            "pisell-sale-detail-amount-details__details-icon",
            {
              "pisell-sale-detail-amount-details__details-icon--open": showDetail
            }
          )
        },
        /* @__PURE__ */ import_react.default.createElement(import_materials.Iconfont, { type: "pisell2-chevron-down" })
      )
    )), /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)("pisell-sale-detail-amount-details__details", {
          "pisell-sale-detail-amount-details__details--open": showDetail
        })
      },
      /* @__PURE__ */ import_react.default.createElement(
        import__.SubTotal,
        {
          mode: "column1",
          list: amountView.subTotalList,
          style: { padding: 0 }
        }
      ),
      amountView.hasOrderTotal ? /* @__PURE__ */ import_react.default.createElement("div", { className: "pisell-sale-detail-amount-details__divider" }) : null,
      amountView.hasOrderTotal ? /* @__PURE__ */ import_react.default.createElement(
        import__.SubTotal,
        {
          mode: "column1",
          list: amountView.orderTotalList,
          style: { padding: " 0 0 16px" }
        }
      ) : null
    ))
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  AmountDetails
});
