"use client";
import { j as s } from "../../../node_modules/.pnpm/react@19.1.0/node_modules/react/jsx-runtime.mjs";
import { useState as N, useEffect as F } from "react";
import { getPlayStreakDays as O, getMidnightUTCTimestamp as W, getPlaytimePercentage as Z } from "../../../node_modules/.pnpm/@hyperplay_utils@0.3.18/node_modules/@hyperplay/utils/dist/index.es.mjs";
import { RingProgress as A } from "@mantine/core";
import i from "../../../node_modules/.pnpm/classnames@2.5.1/node_modules/classnames/index.mjs";
import { ReactComponent as v } from "../../assets/images/LightningBolt.svg.mjs";
import { ReactComponent as G } from "../../assets/images/Clock.svg.mjs";
import e from "./index.module.scss.mjs";
function H({
  currentStreakInDays: t,
  requiredStreakInDays: o
}) {
  const n = [];
  if (o <= 24)
    for (let a = 0; a < o; ++a)
      n.push(a < t);
  return /* @__PURE__ */ s.jsxs("div", { className: e.progressIconsContainer, children: [
    n.map((a, c) => /* @__PURE__ */ s.jsx(
      v,
      {
        className: i(e.streakIcon, a && e.filled)
      },
      `lightningBolt:${c}`
    )),
    /* @__PURE__ */ s.jsx(v, {})
  ] });
}
function q({
  currentStreakInDays: t,
  requiredStreakInDays: o,
  minimumSessionTimeInSeconds: n,
  accumulatedPlaytimeTodayInSeconds: a,
  lastPlaySessionCompletedDateTimeUTC: c,
  dateTimeCurrentSessionStartedInMsSinceEpoch: T,
  rightSection: x,
  streakIsProgressing: C,
  i18n: r = {
    streakProgress: "Streak Progress",
    days: "days",
    playToStart: "Play this game to start your streak!",
    progressTowardsStreak: "progress towards today's streak.",
    playEachDay: "Play each day so your streak won't reset!",
    streakCompleted: "Streak completed! Claim your rewards now.",
    now: "Now",
    dayResets: "Day resets:",
    sync: "Sync Progress"
  }
}) {
  ({ requiredStreakInDays: o, currentStreakInDays: t } = O({
    lastPlaySessionCompletedDateTimeUTC: c,
    requiredStreakInDays: o,
    currentStreakInDays: t
  }));
  const p = t >= o;
  function y() {
    const l = W() - Date.now().valueOf();
    if (l <= 0)
      return r.now;
    const E = Math.floor(l / 1e3) % 60, M = Math.floor(l / 1e3 / 60) % 60, B = Math.floor(l / 1e3 / 60 / 60), h = (z) => String(z).padStart(2, "0");
    return `${h(B)}:${h(M)}:${h(E)}`;
  }
  const [$, L] = N(y());
  let j;
  C && (j = T);
  const u = () => Z({
    minimumSessionTimeInSeconds: n,
    accumulatedPlaytimeTodayInSeconds: a,
    lastPlaySessionCompletedDateTimeUTC: c,
    dateTimeCurrentSessionStartedInMsSinceEpoch: j
  }), [m, k] = N(u()), R = !!t || m > 0;
  function b() {
    p || L(y()), C && m < 100 && k(u());
  }
  F(() => {
    const l = setInterval(() => b(), 1e3);
    return () => clearInterval(l);
  }, []);
  let P = "var(--color-neutral-600)", d = "", g = 0, f = r.playToStart;
  R && (g = m, d = e.inProgress, f = `${g}% ${r.progressTowardsStreak} ${r.playEachDay}`), p && (d = e.finished, P = "var(--color-success-300)", g = 0, f = r.streakCompleted);
  let S = "var(--color-alert-300)";
  m >= 100 && (d = e.finished, S = "var(--color-success-300)");
  let w = null;
  return p || (w = /* @__PURE__ */ s.jsxs("div", { className: i("caption", e.rewardCountdownContainer), children: [
    /* @__PURE__ */ s.jsx(G, { className: e.clock }),
    r.dayResets,
    /* @__PURE__ */ s.jsx("em", { children: $ })
  ] })), /* @__PURE__ */ s.jsxs("div", { className: e.rootContainer, children: [
    w,
    /* @__PURE__ */ s.jsxs("div", { className: e.progressContainer, children: [
      /* @__PURE__ */ s.jsxs("div", { children: [
        /* @__PURE__ */ s.jsx("div", { className: "body", children: r.streakProgress }),
        /* @__PURE__ */ s.jsxs("div", { className: i("title", e.daysLeftText), children: [
          /* @__PURE__ */ s.jsx("em", { children: `${t}` }),
          ` / ${o} ${r.days}`
        ] })
      ] }),
      x ? /* @__PURE__ */ s.jsx("div", { className: e.rightSection, children: x }) : /* @__PURE__ */ s.jsx(
        H,
        {
          currentStreakInDays: t,
          requiredStreakInDays: o
        }
      )
    ] }),
    /* @__PURE__ */ s.jsx("hr", {}),
    /* @__PURE__ */ s.jsxs("div", { className: i("body-sm", e.bottomContainer), children: [
      /* @__PURE__ */ s.jsx(
        A,
        {
          size: 40,
          thickness: 2,
          classNames: {
            root: e.ringProgressRoot,
            svg: e.ringProgressSvg,
            label: e.ringProgressLabel
          },
          label: /* @__PURE__ */ s.jsx(
            v,
            {
              className: i(
                e.circleLightning,
                d
              )
            }
          ),
          rootColor: P,
          sections: [
            {
              value: g,
              color: S
            }
          ]
        }
      ),
      f
    ] })
  ] });
}
export {
  q as StreakProgress
};
//# sourceMappingURL=index.mjs.map
