import { Ctx as s } from "./accelbyte-widgets33.mjs";
import { ItemType as o } from "./accelbyte-widgets185.mjs";
import { Container as r } from "unstated";
import { Platform as n } from "@accelbyte/sdk-platform";
class m extends r {
  constructor(t) {
    super(), this.props = t, this.state = {
      isFetching: !1,
      optionboxLists: null,
      error: null
    }, this.sdk = s.getAppState().getSdk();
  }
  getLimit() {
    return this.props.pageSize || 10;
  }
  getOffset(t) {
    return t ? (t - 1) * this.getLimit() : 0;
  }
  async init() {
    await this.fetchOptionboxLists();
  }
  async fetchOptionboxLists() {
    try {
      if (this.state.isFetching || (this.setState({
        isFetching: !0,
        optionboxLists: null
      }), !this.props.userId))
        return;
      const { userId: t, page: i } = this.props, e = await n.EntitlementApi(this.sdk).getEntitlements_ByUserId(t, {
        offset: this.getOffset(i),
        limit: this.getLimit(),
        entitlementClazz: o.enum.OPTIONBOX
      });
      this.setState({ optionboxLists: e });
    } catch (t) {
      this.setState({ error: t });
    } finally {
      this.setState({ isFetching: !1 });
    }
  }
}
export {
  m as PurchasedOptionboxLogic
};
