function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import React, { memo, useState } from 'react';
import classNames from 'classnames';
import { locales } from '@pisell/utils';
import PisellSaleSummaryDetail from "../../../../../plus/pisellSaleSummaryDetail";
// 直接复用 sale detail footer 的样式，保证两处 summary 外观/顺序完全一致。
import "../../../../../plus/saleDetail/components/Summary/index.less";

/** 与 saleDetail/components/Summary 同源的类名前缀，沿用其全部样式。 */
var PREFIX = 'pisell-sale-detail-summary';
/** 件数文案：优先用 i18n formatter，否则按单/复数拼接（对齐 sale detail 的 “1 item”）。 */
function getItemCountText(count) {
  var formatItemCount = locales.getText('payment.result.item-count');
  if (typeof formatItemCount === 'function') {
    return formatItemCount(count);
  }
  var unit = locales.getText(count === 1 ? 'payment.result.item' : 'payment.result.items');
  return "".concat(count, " ").concat(unit);
}

/**
 * footer 条：与 saleDetail/components/Summary 使用完全相同的 DOM 结构 + class +
 * less，仅数据来自本 toast 的 ViewModel。
 * - 上排：件数 · Total · Paid（可选 excl. Payment SC）+ Detail 展开触发
 * - 下排：状态药丸（FULLY PAID / TO PAY…）+ Balance Due 金额
 * - Detail 展开：复用已解耦的 PisellSaleSummaryDetail
 * 按钮在外层 actions 区，不在此组件内。
 */
export var SaleDetailFooter = /*#__PURE__*/memo(function SaleDetailFooter(_ref) {
  var footer = _ref.footer;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    expanded = _useState2[0],
    setExpanded = _useState2[1];
  var itemCount = footer.itemCount,
    totalText = footer.totalText,
    paidText = footer.paidText,
    hasPaymentSurcharge = footer.hasPaymentSurcharge,
    statusLabel = footer.statusLabel,
    statusStyle = footer.statusStyle,
    balanceDueText = footer.balanceDueText,
    isRefund = footer.isRefund,
    detailDataSource = footer.detailDataSource;
  var canExpand = !!detailDataSource;
  var showExpand = canExpand && expanded;
  return /*#__PURE__*/React.createElement("section", {
    className: classNames(PREFIX, _defineProperty({}, "".concat(PREFIX, "--open"), expanded))
  }, showExpand ?
  /*#__PURE__*/
  // 内联展开（非 portal）。限高在 PaymentResultToastV2.less 中按 V2 作用域覆盖，
  // 避免在 toast 卡片内过高溢出，内部由 __popover-content 自带滚动。
  React.createElement("div", {
    className: "".concat(PREFIX, "__popover-panel")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__popover-content")
  }, /*#__PURE__*/React.createElement(PisellSaleSummaryDetail, {
    dataSource: detailDataSource
  }))) : null, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__bar")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__top")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__meta")
  }, /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__item-count")
  }, getItemCountText(itemCount)), /*#__PURE__*/React.createElement("span", null, locales.getText('payment.result.total'), " ", totalText), /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__dot")
  }), /*#__PURE__*/React.createElement("span", null, locales.getText('payment.result.paidLabel'), " ", paidText), hasPaymentSurcharge ? /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__payment-sc-note")
  }, locales.getText('payment.result.exclPaymentSc')) : null), canExpand ? /*#__PURE__*/React.createElement("button", {
    type: "button",
    className: "".concat(PREFIX, "__detail-trigger"),
    "aria-expanded": expanded,
    onClick: function onClick() {
      return setExpanded(function (prev) {
        return !prev;
      });
    }
  }, /*#__PURE__*/React.createElement("span", {
    className: classNames("".concat(PREFIX, "__detail-icon"), _defineProperty({}, "".concat(PREFIX, "__detail-icon--open"), expanded)),
    "aria-hidden": true
  }, /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__detail-chevron")
  })), /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__detail-text")
  }, locales.getText('payment.result.detail'))) : null), /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__bottom")
  }, statusLabel ? /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__status"),
    style: statusStyle
  }, String(statusLabel).toUpperCase()) : null, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__balance")
  }, /*#__PURE__*/React.createElement("span", {
    className: "".concat(PREFIX, "__balance-label")
  }, locales.getText('payment.result.balanceDue')), /*#__PURE__*/React.createElement("span", {
    className: classNames("".concat(PREFIX, "__amount"), _defineProperty({}, "".concat(PREFIX, "__amount--refund"), isRefund))
  }, balanceDueText)))));
});
SaleDetailFooter.displayName = 'PaymentResultToastV2SaleDetailFooter';
export default SaleDetailFooter;