import { Ctx as r } from "./accelbyte-widgets33.mjs";
import { Container as o } from "unstated";
import { Platform as a } from "@accelbyte/sdk-platform";
class g extends o {
  constructor(t) {
    super(), this.props = t, this.state = {
      isFetching: !1,
      orderInfoList: null,
      error: null
    }, this.sdk = r.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: e, status: s } = this.props;
      if (!e)
        return;
      const i = await a.OrderApi(this.sdk).getOrders_ByUserId(e, {
        status: s,
        offset: this.getOffset(t),
        limit: this.getLimit()
      });
      await this.setState({ orderInfoList: i });
    } catch (t) {
      this.setState({ error: t });
    } finally {
      await this.setState({ isFetching: !1 });
    }
  }
}
export {
  g as OrderListLogic
};
