class LisioStatsController {
  private static _current: LisioStatsController;

  private constructor() {}

  public static get current() {
    if (!this._current) {
      this._current = new LisioStatsController();
    }
    return this._current;
  }

  public incrementNbOpen() {
    const fetchOptions = {
      headers: {
        "Content-Type": "application/json",
      },
      mode: "no-cors",
      method: "POST",
      body: JSON.stringify({
        col: "nbOpen",
        nd: window.location.origin.toString().replace(/http(s)?:\/\/ /g, ""),
      }),
    } as RequestInit;
    fetch(
      `${import.meta.env.VITE_PHP_SERVER}/addStats.php`,
      fetchOptions,
    ).catch((error) => {
      console.log(error);
    });
  }
}

export default LisioStatsController;
