import e, { useMemo as Re, useState as w, useEffect as V, useCallback as ie } from "react";
import L from "classnames";
import { B as M, b as ee, a as x, e as Te, h as ve, t as te, l as me } from "./useRoutes-367960a3.mjs";
import { Trans as E } from "react-i18next";
import { U as ue } from "./UrlUtils-1bad2fa2.mjs";
import { T as h } from "./Typography-fd0ebec3.mjs";
import { u as P, d as fe, a as Ue, f as Le } from "./index-28007ca6.mjs";
import { a as Ce, b as Pe } from "./LoadingPage-d6d2cc0b.mjs";
import { C as we } from "./CircleCheckIcon-8f97f219.mjs";
import { A as F, L as H, c as ke, u as ge, E as be, F as R, W as pe, d as Me } from "./Env-92498313.mjs";
import { u as G } from "./useCompanyLogo-e4bed311.mjs";
import { L as Fe, U as Ge, P as De } from "./UnlinkAccountConfirmDialog-ff3d10fe.mjs";
import { P as Oe } from "./ProfileImage-64f9d3cd.mjs";
import { M as Se, b as Ke } from "./Modal-05e5e3d2.mjs";
import { S as Ve } from "./Select-934e9e99.mjs";
import { A as xe } from "./Alert-98fe02c6.mjs";
import { A as He } from "./Alert-1277e378.mjs";
import { XCircle as Be } from "react-feather";
import { Platform as he } from "@accelbyte/sdk-platform";
import { Iam as oe, IamOAuthClient as _e } from "@accelbyte/sdk-iam";
import "flat";
import "i18next";
import "date-fns";
import "@accelbyte/sdk";
import "./utils.mjs";
import "zod";
import "uuid";
import "./merge-78dc87d6.mjs";
import "@accelbyte/sdk-legal";
import "react-dom";
import "buffer";
import "react-toastify";
import "@accelbyte/sdk-gdpr";
import "@accelbyte/sdk-basic";
import "axios";
import "./CommonError-b56f12ad.mjs";
import "./ErrorLayout-d232f96c.mjs";
import "./InputLabel-760cfc94.mjs";
import "react-select";
import "./InfoIcon-c86fd057.mjs";
function Ye({ onLinkAccount: a, onReclaim: c, className: r }) {
  const {
    state: { twitchDropData: s }
  } = P(), n = s == null ? void 0 : s.streamerInfo.data, o = s == null ? void 0 : s.gameList.data.games, t = s == null ? void 0 : s.backgroundConfig.data, l = t == null ? void 0 : t.backgroundOverlay, m = t == null ? void 0 : t.background;
  return /* @__PURE__ */ e.createElement(
    "div",
    {
      className: L("twitchDropLandingPage twitchDropLayout", r, {
        gradient: (l == null ? void 0 : l.isEnabled) && (l == null ? void 0 : l.type) === "gradient",
        full: (l == null ? void 0 : l.isEnabled) && (l == null ? void 0 : l.type) === "full"
      }),
      style: { backgroundImage: `url("${m}")` }
    },
    /* @__PURE__ */ e.createElement("div", { className: "relative" }, /* @__PURE__ */ e.createElement(h, { tag: "h1", className: "twitchDropLandingPage__title" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.twitchDrops" }, "Twitch Drops")), /* @__PURE__ */ e.createElement("div", { className: "twitchDropLandingPage__subtitle" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.landing.subtitle" }, /* @__PURE__ */ e.createElement(h, { tag: "p" }, "Participate on the event, watch Twitch streams, and earn rewards."), /* @__PURE__ */ e.createElement(h, { tag: "p" }, "Get started by linking your Twitch account."))), /* @__PURE__ */ e.createElement("div", { className: "twitchDropLandingPage__buttonGroup" }, /* @__PURE__ */ e.createElement(M, { onClick: a }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.landing.linkAccount" }, "Link Account")), (n == null ? void 0 : n.isStreamButtonEnabled) && /* @__PURE__ */ e.createElement("a", { href: ue.fixUrl(n == null ? void 0 : n.streamButton.url), target: "_blank", rel: "noreferrer" }, /* @__PURE__ */ e.createElement(M, { buttonType: ee.OUTLINED, buttonStyle: x.TEXT }, n == null ? void 0 : n.streamButton.label))), o && o.length > 0 && /* @__PURE__ */ e.createElement(h, { tag: "p", className: "twitchDropLandingPage__bottomCta" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.landing.bottomCta" }, "Have problem claiming Twitch Drops? ", /* @__PURE__ */ e.createElement("button", { onClick: c }, "Re-claim here"))))
  );
}
function We({ className: a }) {
  const { state: c } = Te(), { state: r } = ve(), s = () => {
    c.push(r.twitchDrops.claim.link);
  };
  function n() {
    c.push(r.twitchDrops.claim.makePath({ query: { step: "reclaim" } }));
  }
  return /* @__PURE__ */ e.createElement(
    Ye,
    {
      onLinkAccount: s,
      onReclaim: n,
      className: L("twitchDropLandingPage twitchDropLayout", a)
    }
  );
}
function Jt() {
  return /* @__PURE__ */ e.createElement(We, null);
}
const D = ({ children: a, className: c, isMultipleGame: r }) => /* @__PURE__ */ e.createElement("div", { className: L("twitchCard", c, r ? "multipleGame" : "") }, a);
function O({
  logo: a,
  title: c,
  subtitle: r,
  children: s,
  className: n,
  backgroundURL: o,
  backgroundOverlay: t,
  errorAlert: l
}) {
  return /* @__PURE__ */ e.createElement(
    "div",
    {
      className: L("twitchDropLayout relative", n, {
        gradient: (t == null ? void 0 : t.isEnabled) && (t == null ? void 0 : t.type) === "gradient",
        full: (t == null ? void 0 : t.isEnabled) && (t == null ? void 0 : t.type) === "full"
      }),
      style: { backgroundImage: `url(${o})` }
    },
    /* @__PURE__ */ e.createElement("div", { className: "twitchDropLayout__innerContainer" }, /* @__PURE__ */ e.createElement("div", { className: "twitchDropLayout__errorContainer" }, l), a && /* @__PURE__ */ e.createElement("div", { className: "twitchDropLayout__logo" }, /* @__PURE__ */ e.createElement("img", { src: a, alt: "logo" })), (c || r) && /* @__PURE__ */ e.createElement("div", { className: "twitchDropLayout__titleContainer" }, c && /* @__PURE__ */ e.createElement(h, { tag: "h1", className: "twitchDropLayout__title" }, c), r && /* @__PURE__ */ e.createElement(h, { tag: "p", className: "twitchDropLayout__subtitle" }, r)), s)
  );
}
const je = "https://www.twitch.tv/drops/inventory", Qe = ({ className: a, logo: c, isPreview: r, isMultipleGame: s }) => {
  const {
    state: { twitchDropData: n }
  } = P(), { companyLogo: o } = G(F.TWITCHDROP, "header"), t = fe();
  return /* @__PURE__ */ e.createElement(
    O,
    {
      backgroundOverlay: n == null ? void 0 : n.backgroundConfig.data.backgroundOverlay,
      backgroundURL: n == null ? void 0 : n.backgroundConfig.data.background,
      logo: c || o,
      className: L("linkedFormPanel linkLayout", a)
    },
    /* @__PURE__ */ e.createElement(D, { isMultipleGame: s }, /* @__PURE__ */ e.createElement(h, { tag: "h2" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.linkedFormPanel.title" }, "Twitch Account Linked")), /* @__PURE__ */ e.createElement(we, { className: "icon", checked: !0, fill: !0 }), /* @__PURE__ */ e.createElement(h, { tag: "p" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.linkedFormPanel.instruction" }, "Your account is now linked to Twitch. To claim your Drop items, please go to Twitch Inventory page.")), r ? /* @__PURE__ */ e.createElement("div", { className: "btn btn-primary btnGoToInventory cursor-pointer" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.linkedFormPanel.goToInventory" }, "Go To Twitch Inventory")) : /* @__PURE__ */ e.createElement("a", { target: "_blank", rel: "noreferrer", href: je, className: "btn btn-primary btnGoToInventory" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.linkedFormPanel.goToInventory" }, "Go To Twitch Inventory"))),
    /* @__PURE__ */ e.createElement("div", { className: "btnLogout" }, /* @__PURE__ */ e.createElement(
      M,
      {
        onClick: () => !r && t.logout(),
        buttonType: ee.PLAIN,
        buttonStyle: x.TEXT,
        hasOutline: !1
      },
      te("Navigation.links.logout")
    ))
  );
}, ze = ({ className: a }) => /* @__PURE__ */ e.createElement("i", { className: a }, /* @__PURE__ */ e.createElement("svg", { width: "16", height: "17", viewBox: "0 0 16 17", fill: "none", xmlns: "http://www.w3.org/2000/svg" }, /* @__PURE__ */ e.createElement(
  "path",
  {
    fillRule: "evenodd",
    clipRule: "evenodd",
    d: "M1.125 0L0 2.875V14.625H4V16.75H6.25L8.375 14.625H11.625L16 10.25V0H1.125ZM14.5 9.5L12 12H8L5.875 14.125V12H2.5V1.5H14.5V9.5ZM12 4.375V8.75H10.5V4.375H12ZM8 4.375V8.75H6.5V4.375H8Z",
    fill: "white"
  }
)));
const de = ({ withAvatar: a, avatarURL: c, displayName: r, email: s, className: n, bottomCta: o }) => {
  const {
    state: { flags: t },
    hasFeature: l
  } = Ue(), m = Re(() => l("isAvatarVisible"), [t]);
  return a ? /* @__PURE__ */ e.createElement("div", { className: "flex w-full flex-col gap-2 text-left" }, /* @__PURE__ */ e.createElement("div", { className: L(n, "userInfoCard") }, m && /* @__PURE__ */ e.createElement("div", { className: "avatarContainer" }, /* @__PURE__ */ e.createElement(Oe, { imageLink: c, className: "avatarImage" })), /* @__PURE__ */ e.createElement("div", { className: "userInfoContainer" }, /* @__PURE__ */ e.createElement(h, { tag: "p", className: "displayName" }, r), s && /* @__PURE__ */ e.createElement(h, { tag: "p", className: "email" }, s))), o && /* @__PURE__ */ e.createElement("div", { className: "bottomCta" }, o)) : /* @__PURE__ */ e.createElement("div", { className: "flex flex-col items-center gap-2" }, /* @__PURE__ */ e.createElement("div", { className: L(n, "userInfoCardDisplayNameOnly") }, /* @__PURE__ */ e.createElement(h, { tag: "p", isCentered: !0, className: "displayName" }, r)), o && /* @__PURE__ */ e.createElement("div", { className: "bottomCta" }, o));
}, Ie = (a) => {
  const { user: c, avatarURL: r, isLoading: s, onLink: n, error: o, accountConflictInformation: t, logo: l, isPreview: m, isMultipleGame: I } = a, {
    state: { twitchDropData: g }
  } = P(), p = fe(), { companyLogo: A } = G(F.TWITCHDROP, "header");
  return /* @__PURE__ */ e.createElement(
    O,
    {
      backgroundOverlay: g == null ? void 0 : g.backgroundConfig.data.backgroundOverlay,
      backgroundURL: g == null ? void 0 : g.backgroundConfig.data.background,
      logo: l || A,
      className: L("linkFormPanel linkLayout", a.className),
      errorAlert: /* @__PURE__ */ e.createElement(Fe, { error: o, accountConflictInformation: t })
    },
    /* @__PURE__ */ e.createElement(D, { isMultipleGame: I }, /* @__PURE__ */ e.createElement(h, { tag: "h2" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.linkFormPanel.title" }, "Link to Twitch")), /* @__PURE__ */ e.createElement(h, { tag: "p", className: "instructionMessage" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.linkFormPanel.instruction" }, "To get the Drop items, please link your account with Twitch first")), /* @__PURE__ */ e.createElement(
      de,
      {
        withAvatar: !0,
        avatarURL: r,
        displayName: c.displayName,
        email: c.emailAddress,
        bottomCta: /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.linkFormPanel.logout" }, "Not you?", " ", /* @__PURE__ */ e.createElement("a", { className: "btnLogout", onClick: () => !m && p.logout() }, "Logout"))
      }
    ), /* @__PURE__ */ e.createElement(M, { loadingIndicator: "SPINNER", onClick: n, isLoading: s, className: "btnTwitch" }, /* @__PURE__ */ e.createElement("div", { className: "btnItemContainer" }, /* @__PURE__ */ e.createElement(ze, null), /* @__PURE__ */ e.createElement("span", { className: "btnText" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.linkFormPanel.linkButton" }, "Link to Twitch")))))
  );
}, Ee = (a) => /* @__PURE__ */ e.createElement(M, { buttonType: ee.FLAT, buttonFontSize: me.MEDIUM, ...a });
const Je = ({ options: a = [], ...c }) => {
  var r;
  return a.length <= 1 ? /* @__PURE__ */ e.createElement("div", { className: "singleDrop" }, /* @__PURE__ */ e.createElement(h, { tag: "p", className: "gameDisplay" }, (r = a[0]) == null ? void 0 : r.label)) : /* @__PURE__ */ e.createElement("div", { className: "multiDrops" }, /* @__PURE__ */ e.createElement(
    Ve,
    {
      label: /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.select.title" }, "Choose a game"),
      options: a,
      className: "selectContainer inputLabel",
      ...c
    }
  ));
};
function Xe({ onCancel: a, onClaim: c, visible: r, isPreview: s, isMultipleGame: n, gameData: o }) {
  const [t, l] = w(o[0]), [m, I] = w(!1), g = (y) => {
    l(y);
  }, p = async () => {
    I(!0);
    const y = o.find((v) => v.value === t.value);
    y && await c(y.namespace, t.value, y.clientId, y.label), I(!1);
  }, A = n ? "multipleGame" : "";
  return /* @__PURE__ */ e.createElement(
    Se,
    {
      visible: r,
      className: `twitchDropPage__claimModal ${A}`,
      overlayClassName: A,
      isPreviewMode: s,
      overlayBackground: s ? { position: "absolute" } : void 0
    },
    /* @__PURE__ */ e.createElement(Ke, null, /* @__PURE__ */ e.createElement(h, { tag: "h2", fontSize: "lg", isCentered: !0 }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.modal.title" }, "Claim Drops")), /* @__PURE__ */ e.createElement(h, { tag: "p", isCentered: !0 }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.modal.subtitle" }, "Do you want to claim game drops with this Twitch account?", /* @__PURE__ */ e.createElement("br", null), "This action may require you to re-login to Twitch.")), /* @__PURE__ */ e.createElement(Je, { options: o, onChange: g, isFullWidth: !0, placeholder: "Choose a game", value: t }), /* @__PURE__ */ e.createElement("div", { className: "buttonContainer" }, /* @__PURE__ */ e.createElement(
      M,
      {
        onClick: a,
        buttonType: ee.PLAIN,
        buttonFontSize: me.MEDIUM,
        buttonStyle: x.TEXT,
        hasOutline: !1
      },
      te("common.cancel")
    ), /* @__PURE__ */ e.createElement(
      M,
      {
        isLoading: m,
        onClick: p,
        buttonType: ee.FLAT,
        buttonFontSize: me.MEDIUM,
        buttonStyle: x.PRIMARY,
        disabled: !t
      },
      te("common.claim")
    )))
  );
}
const qe = ({ displayName: a, onUnlink: c, onClaim: r, className: s, logo: n, hasDropEntitlements: o, isMultipleGame: t }) => {
  const [l, m] = w(!1), [I, g] = w(!1), {
    state: { twitchDropData: p }
  } = P(), { companyLogo: A } = G(F.TWITCHDROP, "header");
  V(() => {
    o || m(!1);
  }, [o]);
  const y = async () => {
    m(!0);
  }, v = p == null ? void 0 : p.gameList.data.games.map((S) => ({ value: S.gameId, label: S.gameName, namespace: S.namespace, clientId: S.clientId }));
  return /* @__PURE__ */ e.createElement(
    O,
    {
      backgroundOverlay: p == null ? void 0 : p.backgroundConfig.data.backgroundOverlay,
      backgroundURL: p == null ? void 0 : p.backgroundConfig.data.background,
      logo: n || A,
      title: te("TwitchDropPage.reclaim.title"),
      subtitle: te("TwitchDropPage.reclaim.subtitle"),
      className: L("reclaimLayout", s)
    },
    /* @__PURE__ */ e.createElement(D, { className: "reclaimPanel", isMultipleGame: t }, !o && /* @__PURE__ */ e.createElement(xe, { className: "w-full rounded-none", type: He.info }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.twitchReclaimForm.card.noItem" }, "You have no drop items to claim.")), /* @__PURE__ */ e.createElement(h, { tag: "p" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.twitchReclaimForm.card.instruction" }, "You have linked your Twitch account. Claim your drops now.")), /* @__PURE__ */ e.createElement(
      de,
      {
        displayName: a,
        bottomCta: /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.twitchReclaimForm.card.unlink" }, "Not your correct Twitch account?", " ", /* @__PURE__ */ e.createElement(
          "button",
          {
            onClick: () => {
              g(!0);
            }
          },
          "Unlink"
        ))
      }
    ), /* @__PURE__ */ e.createElement(Ee, { onClick: y, buttonStyle: x.PRIMARY }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.twitchReclaimForm.card.claimButton" }, "Claim Now"))),
    /* @__PURE__ */ e.createElement(
      Xe,
      {
        visible: l,
        onClaim: r,
        gameData: v || [],
        onCancel: () => m(!1),
        isPreview: !0
      }
    ),
    I && /* @__PURE__ */ e.createElement(
      Ge,
      {
        platformId: H.Enum.twitch,
        onCancel: () => g(!1),
        onConfirm: c
      }
    )
  );
};
const Ze = ({ onRetry: a, className: c, logo: r, isMultipleGame: s }) => {
  const {
    state: { twitchDropData: n }
  } = P(), { companyLogo: o } = G(F.TWITCHDROP, "header");
  return /* @__PURE__ */ e.createElement(
    O,
    {
      backgroundOverlay: n == null ? void 0 : n.backgroundConfig.data.backgroundOverlay,
      backgroundURL: n == null ? void 0 : n.backgroundConfig.data.background,
      logo: r || o,
      title: /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.error_panel.title" }, "Oops… something went wrong"),
      className: L("claimErrorPanel", c)
    },
    /* @__PURE__ */ e.createElement(D, { isMultipleGame: s }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(h, { tag: "p" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.error.message1" }, "There was a problem claiming your Twitch drop.")), /* @__PURE__ */ e.createElement(h, { tag: "p" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.error.message2" }, "If the problem persists, please try logging in again or contact our Customer Support."))), /* @__PURE__ */ e.createElement(Ee, { onClick: a }, /* @__PURE__ */ e.createElement(E, { i18nKey: "common.button.retry" }, "Retry")))
  );
};
const $e = "data:image/png;base64, ";
function et({ items: a, isMultipleGame: c, isPreviewMode: r }) {
  return /* @__PURE__ */ e.createElement("div", { className: L("itemListContainer", r ? "inPreview" : "") }, /* @__PURE__ */ e.createElement("div", { className: L("itemsRow", r ? "inPreview" : "") }, a.map((s, n) => /* @__PURE__ */ e.createElement("div", { key: n }, /* @__PURE__ */ e.createElement("div", { className: L("cardItem", c ? "multipleGame" : "") }, /* @__PURE__ */ e.createElement("div", { className: "itemImageContainer" }, /* @__PURE__ */ e.createElement("img", { src: s.imageUrl || $e, className: "m-auto w-3/4", alt: "drop-image" })), /* @__PURE__ */ e.createElement("div", { className: "itemName" }, /* @__PURE__ */ e.createElement(h, { tag: "h3", className: "text-3xl font-medium" }, s.name || "Item Name")), /* @__PURE__ */ e.createElement("div", { className: "h-auto" }, /* @__PURE__ */ e.createElement(h, { tag: "p" }, "Claimed")))))));
}
function tt(a) {
  const { logo: c, visible: r, isPreview: s, gameName: n, dropItems: o, onClose: t, isMultipleGame: l } = a;
  return V(() => {
    const m = (I) => {
      I.key === "Escape" && t();
    };
    return window.addEventListener("keydown", m), () => {
      window.removeEventListener("keydown", m);
    };
  }, []), /* @__PURE__ */ e.createElement(
    Se,
    {
      visible: r,
      className: L("twitchDropPage__successModal", s ? "inPreview" : "", l ? "multipleGame" : ""),
      isPreviewMode: s,
      overlayBackground: s ? { position: "absolute" } : void 0
    },
    /* @__PURE__ */ e.createElement("div", { className: "containertwitch" }, /* @__PURE__ */ e.createElement("div", { className: "containertwitch" }, /* @__PURE__ */ e.createElement("button", { className: "closeButton" }, /* @__PURE__ */ e.createElement(Be, { onClick: t }), /* @__PURE__ */ e.createElement("span", null, "Esc"))), c && /* @__PURE__ */ e.createElement("div", { className: "twitchDropLayout__logo" }, /* @__PURE__ */ e.createElement("img", { src: c, alt: "logo" })), /* @__PURE__ */ e.createElement(h, { tag: "h1", className: "twitchDropLayout__title" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.modal.congratulations" }, "Congratulations!")), /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.modal.success" }, "You`ve claimed your drops for the ", /* @__PURE__ */ e.createElement("b", null, { gameName: n }), " game.", /* @__PURE__ */ e.createElement("br", null), "The items will be sent to your in-game inventory."), /* @__PURE__ */ e.createElement("div", { className: L("listContainer", s ? "inPreview" : "") }, /* @__PURE__ */ e.createElement(et, { items: o, isMultipleGame: l, isPreviewMode: s })))
  );
}
const at = ({
  className: a,
  logo: c,
  isPreviewModalOpen: r,
  itemList: s,
  gameName: n,
  namespace: o,
  isMultipleGame: t,
  isPreview: l
}) => {
  const [m, I] = w(s.length !== 0), {
    state: { twitchDropData: g }
  } = P(), { companyLogo: p } = G(F.TWITCHDROP, "header");
  return /* @__PURE__ */ e.createElement(
    O,
    {
      backgroundOverlay: g == null ? void 0 : g.backgroundConfig.data.backgroundOverlay,
      backgroundURL: g == null ? void 0 : g.backgroundConfig.data.background,
      logo: c || p,
      title: "Re-claim Twitch Drops",
      className: a
    },
    /* @__PURE__ */ e.createElement(D, { className: "claimSuccessPanel", isMultipleGame: t }, /* @__PURE__ */ e.createElement(we, { className: "icon", checked: !0, fill: !0 }), /* @__PURE__ */ e.createElement(h, { tag: "p" }, "All Done! You've successfully claimed your drops.")),
    /* @__PURE__ */ e.createElement(
      tt,
      {
        gameName: n,
        visible: r ?? m,
        isPreview: l,
        dropItems: s,
        backgroundURL: g == null ? void 0 : g.backgroundConfig.data.background,
        logo: c || p,
        namespace: o,
        onClose: () => I(!1),
        isMultipleGame: t
      }
    )
  );
};
function ye(a) {
  const { message: c, className: r, logo: s, isMultipleGame: n } = a, {
    state: { twitchDropData: o }
  } = P(), { companyLogo: t } = G(F.TWITCHDROP, "header");
  return /* @__PURE__ */ e.createElement(
    O,
    {
      backgroundOverlay: o == null ? void 0 : o.backgroundConfig.data.backgroundOverlay,
      backgroundURL: o == null ? void 0 : o.backgroundConfig.data.background,
      logo: s || t,
      className: L("loadingPanel", r),
      title: c
    },
    /* @__PURE__ */ e.createElement(D, { className: "loadingCard", isMultipleGame: n }, /* @__PURE__ */ e.createElement("div", { className: "spinnerWrapper" }, /* @__PURE__ */ e.createElement(Ce, { loadingType: "SPINNER" })), /* @__PURE__ */ e.createElement("div", { className: "subMessageContainer" }, /* @__PURE__ */ e.createElement("span", { className: "message" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchLoading.message" }, "You will be redirected a few seconds"))))
  );
}
const nt = ({ displayName: a, logo: c, onRelogin: r, className: s, isMultipleGame: n }) => {
  const {
    state: { twitchDropData: o }
  } = P(), { companyLogo: t } = G(F.TWITCHDROP, "header");
  return /* @__PURE__ */ e.createElement(
    O,
    {
      backgroundOverlay: o == null ? void 0 : o.backgroundConfig.data.backgroundOverlay,
      backgroundURL: o == null ? void 0 : o.backgroundConfig.data.background,
      logo: c || t,
      className: s
    },
    /* @__PURE__ */ e.createElement(D, { className: "contentPanel", isMultipleGame: n }, /* @__PURE__ */ e.createElement(h, { tag: "p" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.panel.wrongAccount" }, "You are logged in using different account, please re-login using Twitch account below:")), /* @__PURE__ */ e.createElement(de, { displayName: a }), /* @__PURE__ */ e.createElement(Ee, { onClick: r, buttonStyle: x.PRIMARY }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.panel.relogin" }, "RELOGIN")))
  );
};
var $ = /* @__PURE__ */ ((a) => (a[a.INVALID_PLATFORM_TOKEN = 39125] = "INVALID_PLATFORM_TOKEN", a[a.ERROR_USER_ID_NOT_LINKED = 39126] = "ERROR_USER_ID_NOT_LINKED", a[a.ERROR_USER_ID_NOT_LINKED_ALTERNATIVE = 20017] = "ERROR_USER_ID_NOT_LINKED_ALTERNATIVE", a[a.TWITCH_ACCOUNT_ALREADY_LINKED = 10172] = "TWITCH_ACCOUNT_ALREADY_LINKED", a))($ || {}), N = /* @__PURE__ */ ((a) => (a.VALIDATING = "validating", a.SUCCESS = "success", a.FAILED = "failed", a))(N || {});
const J = "AB-Twitch_drops-claim-game_id", X = "AB-Twitch_drops-claim-game_namespace", q = "AB-Twitch_drops-claim-game_client_id", Z = "AB-Twitch_drops-claim-game_name", ot = "twitch-drop-thumbnail";
function st({ displayName: a, validateStatus: c, retryStatus: r, onLink: s, className: n }) {
  const [o, t] = w(
    "HOME"
    /* HOME */
  ), [l, m] = w(!0), [I, g] = w(!1), [p, A] = w(""), [y, v] = w(""), [S, se] = w(""), [B, ae] = w(""), [_, U] = w([]), { mutations: ce } = Le(), {
    state: { user: b }
  } = ke(), [K] = ge();
  V(() => {
    const i = sessionStorage.getItem(J), d = sessionStorage.getItem(X), T = sessionStorage.getItem(q), C = sessionStorage.getItem(Z);
    i && d && C && T && (A(i), v(d), ae(C), se(T), sessionStorage.removeItem(J), sessionStorage.removeItem(X), sessionStorage.removeItem(Z), sessionStorage.removeItem(q), c && t(
      "VALIDATE"
      /* VALIDATE */
    ), r && !I && c === N.SUCCESS && Y(d, i, T, C, !0)), o === "VALIDATE" && (c === N.SUCCESS ? t(
      "CLAIM"
      /* CLAIM */
    ) : c === N.FAILED && t(
      "INCORRECT_TWITCH_ACCOUNT"
      /* INCORRECT_TWITCH_ACCOUNT */
    ));
  }, [o, c, _, r]);
  const re = async () => {
    await ce.unLinkAccount(H.Enum.twitch), window.location.reload();
  }, Y = async (i, d = p, T, C, f) => {
    if (b != null && b.userId)
      try {
        sessionStorage.setItem(J, d), sessionStorage.setItem(X, i), sessionStorage.setItem(q, T), sessionStorage.setItem(Z, C), f && g(!0);
        const u = await he.IapApi(K, { namespace: i }).updateUserMeIapTwitchSync({ gameId: d });
        u.length === 0 && (m(!1), t(
          "HOME"
          /* HOME */
        )), u.length > 0 && (await j(u, i), m(!0), t(
          "SUCCESS"
          /* SUCCESS */
        ));
      } catch (u) {
        m(!0), f ? t(
          "ERROR"
          /* ERROR */
        ) : le(u, d, i, T, C);
      }
  }, le = async (i, d, T, C, f) => {
    var u, k;
    if (be.isAxiosError(i)) {
      const z = (k = (u = i == null ? void 0 : i.response) == null ? void 0 : u.data) == null ? void 0 : k.errorCode;
      if (z === $.INVALID_PLATFORM_TOKEN && o !== "CLAIM")
        sessionStorage.setItem(J, d), sessionStorage.setItem(X, T), sessionStorage.setItem(q, C), sessionStorage.setItem(Z, f), s(!0, T, C);
      else if ([$.ERROR_USER_ID_NOT_LINKED, $.ERROR_USER_ID_NOT_LINKED_ALTERNATIVE].includes(z))
        try {
          await oe.UsersApi(K).createUserMePlatformJustice_ByTargetNamespace(T), await Y(T, d, C, f);
        } catch {
          t(
            "ERROR"
            /* ERROR */
          );
        }
      else
        t(
          "ERROR"
          /* ERROR */
        );
    } else
      t(
        "ERROR"
        /* ERROR */
      );
  }, W = async (i, d) => {
    try {
      return await he.ItemApi(K, { namespace: d }).getItemsBySku({ sku: i });
    } catch {
      return null;
    }
  }, j = async (i, d) => {
    const T = i.filter((u) => !!u.itemSku).map((u) => u.itemSku ? W(u.itemSku, d) : null), f = (await Promise.all(T)).map((u) => {
      var z;
      let k = null;
      return u != null && u.images && (k = ((z = u.images.find((Ne) => Ne.as === ot)) == null ? void 0 : z.imageUrl) || u.images[0].imageUrl), {
        name: (u == null ? void 0 : u.name) || "",
        imageUrl: k
      };
    }).sort((u, k) => u.name < k.name ? -1 : u.name > k.name ? 1 : 0);
    U(f);
  }, ne = () => {
    sessionStorage.setItem(J, p), sessionStorage.setItem(X, y), sessionStorage.setItem(q, S), sessionStorage.setItem(Z, B), s(!0, y, S);
  }, Q = () => {
    t(
      "HOME"
      /* HOME */
    );
  };
  return /* @__PURE__ */ e.createElement(e.Fragment, null, o === "HOME" && /* @__PURE__ */ e.createElement(
    qe,
    {
      displayName: a ?? "",
      onUnlink: re,
      onClaim: Y,
      className: n,
      hasDropEntitlements: l
    }
  ), o === "VALIDATE" && /* @__PURE__ */ e.createElement(ye, { message: "Validating user account...", className: n }), o === "CLAIM" && /* @__PURE__ */ e.createElement(ye, { message: "Claiming your drops...", className: n }), o === "SUCCESS" && /* @__PURE__ */ e.createElement(
    at,
    {
      namespace: y,
      gameName: B,
      itemList: _,
      className: n
    }
  ), o === "ERROR" && /* @__PURE__ */ e.createElement(Ze, { onRetry: Q, className: n }), o === "INCORRECT_TWITCH_ACCOUNT" && /* @__PURE__ */ e.createElement(nt, { displayName: a ?? "", onRelogin: ne, className: n }));
}
const ct = {
  useTwitchDrop: () => {
    const [a] = ge(), [c, r] = w({
      linkedTwitchAccount: null,
      linkedTwitchAccountError: null,
      linkedTwitchAccountFetchStatus: R.IDLE,
      loginURL: null,
      loginURLError: null,
      loginURLFetchStatus: R.IDLE
    }), s = ie((t) => {
      r((l) => ({
        ...l,
        ...t
      }));
    }, []), n = ie(
      async (t) => {
        let l = null, m = null;
        try {
          return s({ linkedTwitchAccountError: null, linkedTwitchAccountFetchStatus: R.FETCHING }), l = (await oe.UsersApi(a).getPlatforms_ByUserId(t)).data.find((g) => g.platformId === H.enum.twitch) || null, { data: l };
        } catch (I) {
          return m = pe.getErrorType(I), { error: m };
        } finally {
          s({ linkedTwitchAccount: l, linkedTwitchAccountError: m, linkedTwitchAccountFetchStatus: R.IDLE });
        }
      },
      [a]
    ), o = ie(
      async (t, l, m) => {
        let I = null, g = null;
        try {
          return s({ loginURLError: null, loginURLFetchStatus: R.FETCHING }), I = (await oe.UsersApi(a, { namespace: m }).getWebLinkMeUsers_ByPlatformId(H.enum.twitch, {
            redirectUri: t,
            clientId: l
          })).third_party_url, { data: I };
        } catch (p) {
          return g = pe.getErrorType(p), { error: g };
        } finally {
          s({ loginURL: I, loginURLError: g, loginURLFetchStatus: R.IDLE });
        }
      },
      [a]
    );
    return {
      state: c,
      mutations: {
        fetchLinkedTwitchAccount: n,
        fetchTwitchLoginURL: o
      }
    };
  }
}, rt = "AB-Twitch_drops-claim-game_client_id", lt = (a) => {
  const [c, r] = e.useState({
    validateStatus: null,
    retryStatus: !1,
    isExchangingToken: !1
  }), { validateStatus: s, retryStatus: n, isExchangingToken: o } = c, {
    state: { user: t, userProfile: l }
  } = ke(), {
    state: { linkedTwitchAccount: m, linkedTwitchAccountFetchStatus: I, loginURLFetchStatus: g },
    mutations: { fetchLinkedTwitchAccount: p, fetchTwitchLoginURL: A }
  } = ct.useTwitchDrop(), { state: y } = Te(), [v] = ge(), [S] = Me(), {
    state: { requestStatusFetchStatus: se, accountConflictInformation: B, requestStatusError: ae },
    mutations: _
  } = Le(), U = (i) => {
    r((d) => ({
      ...d,
      ...i
    }));
  };
  V(() => (!m && (t != null && t.userId) && p(t.userId), () => {
    _.resetErrorState();
  }), []), V(() => {
    const i = K() ? N.VALIDATING : null;
    U({ validateStatus: i });
  }, [y.location.search]), V(() => {
    const i = K();
    i && (t != null && t.userId) && ce(i, t == null ? void 0 : t.userId);
    const d = re();
    d && !i && Y(d);
  }, [t == null ? void 0 : t.userId, y.location.search]);
  const ce = async (i, d) => {
    try {
      U({ isExchangingToken: !0 });
      const T = sessionStorage.getItem(rt) || "", C = v.assembly().config, f = await _e.exchangeTokenOauthByPlatformId(
        H.Enum.twitch,
        T,
        {
          platform_token: i,
          client_id: T,
          createHeadless: !1,
          skipSetCookie: !0
        },
        C
      );
      if (f.error)
        throw f.error;
      let u = "";
      f.response.data.namespace === S.namespace ? u = f.response.data.user_id : f.response.data.platform_user_id && (u = (await oe.UsersApi(v).getUser_ByPlatformId_ByPlatformUserId(
        H.Enum.twitch,
        f.response.data.platform_user_id
      )).userId), U({
        validateStatus: u === d ? N.SUCCESS : N.FAILED,
        retryStatus: !0
      });
    } catch {
      U({
        validateStatus: N.FAILED
      });
    } finally {
      U({ isExchangingToken: !1 }), y.replace(j());
    }
  }, b = () => {
    const i = new URLSearchParams(y.location.search);
    return i.get("step") === "reclaim" || i.get("state") === "reclaim";
  }, K = () => new URLSearchParams(y.location.search).get("code"), re = () => new URLSearchParams(y.location.search).get("requestId"), Y = async (i) => {
    if (i && t)
      try {
        const d = await _.requestStatus(i);
        if (d.error)
          throw d.error;
        le(d.data.error);
      } finally {
        y.replace(j());
      }
  }, le = (i) => {
    U({
      validateStatus: (i == null ? void 0 : i.errorCode) === $.TWITCH_ACCOUNT_ALREADY_LINKED ? N.SUCCESS : N.FAILED
    });
  }, W = async (i = !1, d, T) => {
    const C = ue.getRedirectUrl(S.redirectURI, j()), f = await A(C, T || S.clientId, d);
    if (!f.error) {
      const u = f.data;
      if (u)
        if (i) {
          const k = new URL(u);
          k.searchParams.set("force_verify", "true"), d && k.searchParams.set("redirect_uri", ue.getRedirectUrl(S.redirectURI, "/twitch-drops/claim?step=reclaim")), window.location.href = k.toString();
        } else
          window.location.href = u;
    }
  }, j = () => y.location.pathname + (b() ? "?state=reclaim" : ""), ne = g === R.FETCHING, Q = o || se === R.FETCHING || I === R.FETCHING;
  return /* @__PURE__ */ e.createElement(e.Fragment, null, Q && /* @__PURE__ */ e.createElement(Ce, { className: Pe.tall }), !b() && !Q && t && /* @__PURE__ */ e.createElement(e.Fragment, null, m ? /* @__PURE__ */ e.createElement(Qe, { className: a.className }) : /* @__PURE__ */ e.createElement(
    Ie,
    {
      user: t,
      avatarURL: (l == null ? void 0 : l.avatarUrl) ?? "",
      onLink: W,
      isLoading: ne,
      error: ae,
      accountConflictInformation: B,
      className: a.className
    }
  )), b() && !Q && t && /* @__PURE__ */ e.createElement(e.Fragment, null, m ? /* @__PURE__ */ e.createElement(
    st,
    {
      displayName: (m == null ? void 0 : m.displayName) ?? "",
      validateStatus: s,
      retryStatus: n,
      onLink: W,
      className: a.className
    }
  ) : /* @__PURE__ */ e.createElement(
    Ie,
    {
      user: t,
      avatarURL: (l == null ? void 0 : l.avatarUrl) ?? "",
      onLink: W,
      isLoading: ne,
      error: ae,
      accountConflictInformation: B,
      className: a.className
    }
  )));
};
function Xt() {
  return /* @__PURE__ */ e.createElement(De, null, /* @__PURE__ */ e.createElement(lt, null));
}
export {
  Jt as TwitchDropLandingWidget,
  Xt as TwitchDropWidget
};
