import { subYears as n, endOfDay as i } from "date-fns";
import { Container as h } from "unstated";
import { z as p } from "zod";
import { Ctx as c } from "./accelbyte-widgets33.mjs";
const f = 10, D = n(new Date(), 1), S = p.enum(["email", "password", "displayname", "dateofbirth"]);
class A extends h {
  constructor(a) {
    super(), this.formatDate = (t) => t.toISOString(), this.updateUrlParamByDateChange = () => {
      const t = this.props.appState.state.appHistory, { startDate: e, endDate: s } = this.state;
      if (t) {
        const r = new URLSearchParams();
        r.append("startdate", e), r.append("enddate", s);
        const o = e && s ? `&${r}` : "";
        t.replace(`${t.location.pathname}?page=1${o}`), this.fetchAccountHistoryData();
      }
    }, this.changeStartDate = (t) => {
      t && !Array.isArray(t) && this.setState({ startDate: this.formatDate(t) }, () => {
        this.state.endDate && this.updateUrlParamByDateChange();
      });
    }, this.changeEndDate = (t) => {
      t && !Array.isArray(t) && this.setState({ endDate: this.formatDate(i(t)) }, () => {
        this.state.startDate && this.updateUrlParamByDateChange();
      });
    }, this.props = a, this.state = {
      startDate: a.startDate || this.formatDate(D),
      endDate: a.endDate || this.formatDate(i(new Date())),
      hasNext: !0,
      offset: 0
    }, this.appState = c.getAppState();
  }
  getLimit() {
    return this.props.pageSize || f;
  }
  getOffset(a) {
    return a ? (a - 1) * this.getLimit() : 0;
  }
  async fetchAccountHistoryData() {
    const { userId: a, type: t } = this.props, { startDate: e, endDate: s } = this.state;
    this.appState.getUserManager().fetchAccountHistory({ userId: a, type: t, startDate: e, endDate: s, offset: this.getOffset(this.props.page), pageSize: this.getLimit() });
  }
}
export {
  A as AccountHistoryLogic,
  S as EditableInputWithHistory
};
