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/components/booking/payments/index.tsx
var payments_exports = {};
__export(payments_exports, {
  default: () => payments_default
});
module.exports = __toCommonJS(payments_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_tabPane = __toESM(require("../components/tabPane"));
var import_model = require("./model");
var import_utils = require("@pisell/utils");
var import_dayjs = __toESM(require("dayjs"));
var import_index = require("./index.less");
var import_footer = __toESM(require("../components/footer"));
var import_emptyBooking = __toESM(require("../components/emptyBooking"));
var import_icons = require("@ant-design/icons");
var paymentStatusMap = {
  paid: {
    text: import_utils.locales.getText("pisell2.text.paid"),
    icon: /* @__PURE__ */ import_react.default.createElement(import_icons.CheckCircleFilled, { style: { color: "#16B364", fontSize: 20 } })
  },
  voided: {
    text: import_utils.locales.getText("pisell2.text.voided_pay"),
    icon: /* @__PURE__ */ import_react.default.createElement(import_icons.CloseCircleFilled, { style: { color: "#F04438", fontSize: 20 } })
  },
  payment_processing: {
    text: import_utils.locales.getText("pisell2.text.processing_pay"),
    icon: /* @__PURE__ */ import_react.default.createElement(import_icons.ExclamationCircleFilled, { style: { color: "#EAAA08", fontSize: 20 } })
  }
};
var PaymentStatusTitle = (props) => {
  const { type, extra } = props;
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-list-item-status-title" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "payment-list-item-status-title-left" }, paymentStatusMap[type].icon || null, /* @__PURE__ */ import_react.default.createElement("span", { className: "payment-list-item-type" }, paymentStatusMap[type].text)), extra);
};
var Payments = (0, import_model.Provider)((props) => {
  const { globalState } = props;
  const { state, dispatch } = (0, import_react.useContext)(import_model.Context);
  const [loading, setLoading] = (0, import_react.useState)(false);
  const [paymentList, setPaymentList] = (0, import_react.useState)([]);
  const [refundAmount, setRefundAmount] = (0, import_react.useState)();
  const init = () => {
    getPayments();
    getRefundInfo();
  };
  (0, import_react.useEffect)(() => {
    if (state.bookingDetail) {
      init();
    }
  }, [state.bookingDetail]);
  const getRefundInfo = async () => {
    const res = await state.apis.getRefundInfo();
    setRefundAmount(res.total_refund_amount);
  };
  const getPayments = async () => {
    setLoading(true);
    const res = await state.apis.getPaymentList({
      skip: 1,
      num: 100,
      order_id: state.bookingId,
      status: ["voided", "payment_processing", "paid"]
    });
    const orderPaymentList = (res == null ? void 0 : res.list) || [];
    setPaymentList(orderPaymentList);
    setLoading(false);
  };
  (0, import_react.useEffect)(() => {
    document.body.id = "body";
    dispatch({
      type: "setState",
      payload: {
        setGlobalState: props.setGlobalState
      }
    });
  }, []);
  (0, import_react.useEffect)(() => {
    dispatch({
      type: "setState",
      payload: {
        ...globalState
      }
    });
  }, [globalState]);
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_tabPane.default,
    {
      header: import_utils.locales.getText("pisell2.text.payments"),
      footer: state.bookingId && /* @__PURE__ */ import_react.default.createElement(import_footer.default, { state, dispatch, source: "payment" }),
      loading: loading && state.bookingId
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-customer-pay-title" }, import_utils.locales.getText("pisell2.text.customerpay")),
    state.bookingId && paymentList.length ? /* @__PURE__ */ import_react.default.createElement(
      import_antd.List,
      {
        dataSource: paymentList,
        renderItem: (item) => /* @__PURE__ */ import_react.default.createElement(import_antd.List.Item, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-list-item" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-list-item-left" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-record", key: item.id }, /* @__PURE__ */ import_react.default.createElement(
          PaymentStatusTitle,
          {
            type: item.status,
            extra: /* @__PURE__ */ import_react.default.createElement("span", { className: "payment-list-item-pay-amount" }, (0, import_utils.formatAmount)(
              item.amount,
              2,
              (state == null ? void 0 : state.amountSymbol) || "$"
            ))
          }
        ), /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-list-item-content" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-list-item-pay-methods" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "payment-list-item-pay-name" }, item.payment_method_name || "-")), Number(item.service_fee) ? /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-list-item-surcharge" }, "(", import_utils.locales.getText("pisell2.text.surcharge"), " ", (0, import_utils.formatAmount)(
          item.service_fee,
          2,
          (state == null ? void 0 : state.amountSymbol) || "$"
        ), ")") : null, /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-list-item-date" }, (0, import_dayjs.default)(item.payment_time).format(
          "HH:mm YYYY/MM/DD"
        ), /* @__PURE__ */ import_react.default.createElement("span", { className: "payment-list-item-platform-type" }, item.platform && import_utils.locales.getText("pisell2.text.platform.type")(
          item.platform
        ))))))))
      }
    ) : /* @__PURE__ */ import_react.default.createElement(
      import_emptyBooking.default,
      {
        description: state.bookingId ? import_utils.locales.getText("pisell1.text.no-payments") : void 0
      }
    ),
    !!state.bookingId && !!Number(refundAmount) && /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_antd.Divider, { className: "payment-divider" }), /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-refund-wrap" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-refund-title" }, import_utils.locales.getText("pisell2.text.refund"), ":"), /* @__PURE__ */ import_react.default.createElement("div", { className: "payment-refund-amount" }, /* @__PURE__ */ import_react.default.createElement("span", null, import_utils.locales.getText("pisell2.text.refund-amount")), /* @__PURE__ */ import_react.default.createElement("span", null, (0, import_utils.formatAmount)(refundAmount, 2, (state == null ? void 0 : state.amountSymbol) || "$")))), /* @__PURE__ */ import_react.default.createElement(import_antd.Divider, { className: "payment-divider" }))
  ));
});
var payments_default = Payments;
