import { CommonError as E } from "./accelbyte-widgets124.mjs";
import { Loading as y } from "./accelbyte-widgets136.mjs";
import { Pagination as g } from "./accelbyte-widgets256.mjs";
import h from "./accelbyte-widgets210.mjs";
import { OrderListLogic as f } from "./accelbyte-widgets257.mjs";
import { Ctx as N } from "./accelbyte-widgets33.mjs";
import { AccPath as m } from "./accelbyte-widgets34.mjs";
import { FeUtils as P } from "./accelbyte-widgets45.mjs";
import { PurchaseHelper as v } from "./accelbyte-widgets211.mjs";
import e from "react";
import { Trans as n } from "react-i18next";
import { Link as H } from "react-router-dom";
import { AccountMainSection as O, AccountMainSectionHeader as C, AccountMainSectionBody as S } from "./accelbyte-widgets122.mjs";
import p from "./accelbyte-widgets258.mjs";
import { OrderStatusTranslation as b } from "./accelbyte-widgets259.mjs";
import { mockUserOrderHistory as L } from "./accelbyte-widgets209.mjs";
class I extends e.Component {
  constructor(a) {
    var i;
    super(a), this.renderTableOrder = (r) => /* @__PURE__ */ e.createElement("div", { className: p.orderHistoryPage }, /* @__PURE__ */ e.createElement("div", { className: "tableHead" }, /* @__PURE__ */ e.createElement("div", { className: "tableColumn first" }, /* @__PURE__ */ e.createElement("p", { className: "title" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "OrderHistoryPage.date" }, "Date")), /* @__PURE__ */ e.createElement("p", { className: "title" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "OrderHistoryPage.itemName" }, "Item name"))), /* @__PURE__ */ e.createElement("div", { className: "tableColumn second" }, /* @__PURE__ */ e.createElement("p", { className: "title" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "OrderHistoryPage.total" }, "Total")), /* @__PURE__ */ e.createElement("p", { className: "title" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "OrderHistoryPage.status" }, "Status")))), r.map((t) => {
      const c = P.formatDate(t.createdTime, { type: "dynamic", format: "LLLL" });
      return /* @__PURE__ */ e.createElement("div", { className: "tableContent", key: t.orderNo }, /* @__PURE__ */ e.createElement("div", { className: "tableColumn first" }, /* @__PURE__ */ e.createElement("div", { className: "date" }, /* @__PURE__ */ e.createElement("p", null, c)), /* @__PURE__ */ e.createElement("div", { className: "textContent " }, t.itemSnapshot && t.itemSnapshot.title)), /* @__PURE__ */ e.createElement("div", { className: "tableColumn second" }, /* @__PURE__ */ e.createElement("div", { className: "textContent" }, `${t.currency.currencySymbol} ${v.calculateIntegerPrice(t.totalPrice || 0, t.currency)}`), /* @__PURE__ */ e.createElement("div", { className: "textContent" }, /* @__PURE__ */ e.createElement(b, { status: t.status })), /* @__PURE__ */ e.createElement("div", { className: "btnView" }, /* @__PURE__ */ e.createElement(
        H,
        {
          to: m.OrderHistoryDetail.makePath({
            orderNo: t.orderNo
          })
        },
        /* @__PURE__ */ e.createElement(n, { i18nKey: "OrderHistoryPage.view" }, "View")
      ))));
    })), this.renderPagination = () => {
      const { orderInfoList: r } = this.logic.state;
      if (!r)
        return;
      const { paging: t } = r, c = !!(t != null && t.next), u = !!(t != null && t.previous), d = this.props.page;
      return /* @__PURE__ */ e.createElement("div", { className: "paginationContainer" }, /* @__PURE__ */ e.createElement(
        g,
        {
          next: c && m.OrderHistory.withSearchParams({ page: d + 1 }),
          prev: u && m.OrderHistory.withSearchParams({ page: d - 1 })
        }
      ));
    };
    const { page: s } = a, o = ((i = N.getAppState().getUser()) == null ? void 0 : i.userId) || null;
    this.logic = new f({ page: s, userId: o }), this.logic.subscribe(() => this.setState({}));
  }
  componentDidMount() {
    this.props.isPreviewMode || this.logic.init();
  }
  render() {
    const { isFetching: a, orderInfoList: s, error: o } = this.logic.state, r = this.props.isPreviewMode ? L : s;
    return /* @__PURE__ */ e.createElement(O, { className: p.orderHistoryPage }, /* @__PURE__ */ e.createElement(C, null, /* @__PURE__ */ e.createElement(n, { i18nKey: "OrderHistoryPage.title" }, "Order History")), /* @__PURE__ */ e.createElement(S, null, a && /* @__PURE__ */ e.createElement(y, { className: "loading" }), !a && o && /* @__PURE__ */ e.createElement("div", { className: "errorContainer" }, /* @__PURE__ */ e.createElement(E, { error: o })), !a && r && r.data.length > 0 && this.renderTableOrder(r.data), !a && r && r.data.length === 0 && /* @__PURE__ */ e.createElement("div", { className: "noData" }, /* @__PURE__ */ e.createElement(n, { i18nKey: "OrderHistoryPage.dataNotFound" }, "Order history data not found")), !a && r && this.renderPagination()));
  }
}
const W = h(I, (l, a) => l.page !== a.page);
export {
  W as default
};
