import { C as p, a as g, a9 as n, T as r, F as y, af as f, g as d, L as O, i as S } from "./index-162fd1aa.mjs";
import { P } from "./Pagination-a353297b.mjs";
import { w as N } from "./WithPropsGuard-9dd19ecc.mjs";
import e from "react";
import { Link as L } from "react-router-dom";
import { A as H, b as C, a as v } from "./AccountMainSection-4c35f8d7.mjs";
import { p as F } from "./MockVars-1cf2eb0a.mjs";
import "./dateFns-2367ee5b.mjs";
import "./validator-61879ab7.mjs";
import "./reactPlayer-2f69f369.mjs";
import "./reactSlick-cb4a2d39.mjs";
class I extends p {
  constructor(t) {
    super(), this.props = t, this.state = {
      isFetching: !1,
      orderInfoList: null,
      error: null
    }, this.sdk = g.getAppState().getSdk();
  }
  getLimit() {
    return this.props.pageSize || 10;
  }
  getOffset(t) {
    return t ? (t - 1) * this.getLimit() : 0;
  }
  async init() {
    try {
      if (this.state.isFetching)
        return;
      this.setState({
        isFetching: !0,
        orderInfoList: null,
        error: null
      });
      const { page: t, userId: i, status: c } = this.props;
      if (!i)
        return;
      const l = await this.sdk.Platform.Order().getOrderList({
        userId: i,
        queryParams: { status: c, offset: this.getOffset(t), limit: this.getLimit() }
      }).then((s) => {
        if (s.error)
          throw s.error;
        return s.response.data;
      });
      await this.setState({
        orderInfoList: l
      });
    } catch (t) {
      this.setState({ error: t });
    } finally {
      await this.setState({ isFetching: !1 });
    }
  }
}
const K = "orderHistoryPage _orderHistoryPage_e43b7", E = {
  orderHistoryPage: K
}, D = (o) => {
  const { status: t } = o;
  switch (!0) {
    case t === n.enum.INIT:
      return /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderStatus.init" }, "Initialized");
    case t === n.enum.CHARGEBACK:
      return /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderStatus.chargeback" }, "Chargeback");
    case t === n.enum.CHARGEBACK_REVERSED:
      return /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderStatus.chargebackReversed" }, "Chargeback Reversed");
    case t === n.enum.CHARGED:
      return /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderStatus.charged" }, "Charged");
    case t === n.enum.FULFILLED:
      return /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderStatus.fulfilled" }, "Fulfilled");
    case t === n.enum.FULFILL_FAILED:
      return /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderStatus.fulfillFailed" }, "Fulfill Failed");
    case t === n.enum.REFUNDING:
      return /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderStatus.refunding" }, "Refunding");
    case t === n.enum.REFUNDED:
      return /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderStatus.refunded" }, "Refunded");
    case t === n.enum.REFUND_FAILED:
      return /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderStatus.refundFailed" }, "Refund Failed");
    case t === n.enum.CLOSED:
      return /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderStatus.closed" }, "Closed");
    case t === n.enum.DELETED:
      return /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderStatus.deleted" }, "Deleted");
    default:
      return /* @__PURE__ */ e.createElement("span", null, "status");
  }
};
class b extends e.Component {
  constructor(t) {
    var l;
    super(t), this.renderTableOrder = (s) => /* @__PURE__ */ e.createElement("div", { className: E.orderHistoryPage }, /* @__PURE__ */ e.createElement("div", { className: "tableHead" }, /* @__PURE__ */ e.createElement("div", { className: "tableColumn first" }, /* @__PURE__ */ e.createElement("p", { className: "title" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryPage.date" }, "Date")), /* @__PURE__ */ e.createElement("p", { className: "title" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryPage.itemName" }, "Item name"))), /* @__PURE__ */ e.createElement("div", { className: "tableColumn second" }, /* @__PURE__ */ e.createElement("p", { className: "title" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryPage.total" }, "Total")), /* @__PURE__ */ e.createElement("p", { className: "title" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryPage.status" }, "Status")))), s.map((a) => {
      const m = y.formatDate(a.createdTime, "LLLL");
      return /* @__PURE__ */ e.createElement("div", { className: "tableContent", key: a.orderNo }, /* @__PURE__ */ e.createElement("div", { className: "tableColumn first" }, /* @__PURE__ */ e.createElement("div", { className: "date" }, /* @__PURE__ */ e.createElement("p", null, m)), /* @__PURE__ */ e.createElement("div", { className: "textContent " }, a.itemSnapshot && a.itemSnapshot.title)), /* @__PURE__ */ e.createElement("div", { className: "tableColumn second" }, /* @__PURE__ */ e.createElement("div", { className: "textContent" }, `${a.currency.currencySymbol} ${f.calculateIntegerPrice(a.totalPrice || 0, a.currency)}`), /* @__PURE__ */ e.createElement("div", { className: "textContent" }, /* @__PURE__ */ e.createElement(D, { status: a.status })), /* @__PURE__ */ e.createElement("div", { className: "btnView" }, /* @__PURE__ */ e.createElement(
        L,
        {
          to: d.OrderHistoryDetail.makePath({
            orderNo: a.orderNo
          })
        },
        /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryPage.view" }, "View")
      ))));
    })), this.renderPagination = () => {
      const { orderInfoList: s } = this.logic.state;
      if (!s)
        return;
      const { paging: a } = s, m = !!(a != null && a.next), h = !!(a != null && a.previous), u = this.props.page;
      return /* @__PURE__ */ e.createElement("div", { className: "paginationContainer" }, /* @__PURE__ */ e.createElement(
        P,
        {
          next: m && d.OrderHistory.withSearchParams({ page: u + 1 }),
          prev: h && d.OrderHistory.withSearchParams({ page: u - 1 })
        }
      ));
    };
    const { page: i } = t, c = ((l = g.getAppState().getUser()) == null ? void 0 : l.userId) || null;
    this.logic = new I({ page: i, userId: c }), this.logic.subscribe(() => this.setState({}));
  }
  componentDidMount() {
    this.props.isPreviewMode || this.logic.init();
  }
  render() {
    const { isFetching: t, orderInfoList: i, error: c } = this.logic.state, s = this.props.isPreviewMode ? F : i;
    return /* @__PURE__ */ e.createElement(H, { className: E.orderHistoryPage }, /* @__PURE__ */ e.createElement(C, null, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryPage.title" }, "Order History")), /* @__PURE__ */ e.createElement(v, null, t && /* @__PURE__ */ e.createElement(O, { className: "loading" }), !t && c && /* @__PURE__ */ e.createElement("div", { className: "errorContainer" }, /* @__PURE__ */ e.createElement(S, { error: c })), !t && s && s.data.length > 0 && this.renderTableOrder(s.data), !t && s && s.data.length === 0 && /* @__PURE__ */ e.createElement("div", { className: "noData" }, /* @__PURE__ */ e.createElement(r, { i18nKey: "OrderHistoryPage.dataNotFound" }, "Order history data not found")), !t && s && this.renderPagination()));
  }
}
const B = N(b, (o, t) => o.page !== t.page);
export {
  B as default
};
