import e, { useState as C, useEffect as x, useCallback as ie } from "react";
import L from "classnames";
import { B as M, b as ee, c as V, d as me } from "./Button-c97a7217.mjs";
import { Trans as E } from "react-i18next";
import { U as ue } from "./UrlUtils-45b0efe7.mjs";
import { T as p, S as Re } from "./Select-2a6c2da9.mjs";
import { u as U } from "./useAppConfigs-0fb5df89.mjs";
import { a as Te, u as fe } from "./useUserInfo-ad7006e5.mjs";
import { b as ve, A as F, i as H, u as ge, E as Ue, F as N, W as pe, a as Pe } from "./FetchConfigsUtils-476a602b.mjs";
import { L as Le, a as be } from "./Loading-16af3910.mjs";
import { C as we } from "./CircleCheckIcon-8f97f219.mjs";
import { t as te } from "./i18n-c7e26598.mjs";
import { u as D } from "./useCompanyLogo-b952c2f7.mjs";
import { a as Ce, b as ke } from "./useAppState-d73a6c6c.mjs";
import { L as Me, U as Fe, P as De } from "./UnlinkAccountConfirmDialog-2c41ee1f.mjs";
import { P as Ge } from "./ProfileImage-6c73026b.mjs";
import { M as Se, b as Oe } from "./Modal-39216476.mjs";
import { A as Ke } from "./Alert-c2425f39.mjs";
import { A as xe } from "./Alert-1277e378.mjs";
import { XCircle as Ve } from "react-feather";
import { Platform as he } from "@accelbyte/sdk-platform";
import { Iam as oe, IamOAuthClient as He } from "@accelbyte/sdk-iam";
import "./Env-161a418e.mjs";
import "@accelbyte/sdk";
import "./FormGroup-9051ef94.mjs";
import "./InputLabel-760cfc94.mjs";
import "react-select";
import "@accelbyte/sdk-basic";
import "./RouteUtils-f2d71427.mjs";
import "zod";
import "uuid";
import "axios";
import "flat";
import "i18next";
import "date-fns";
import "./SSRHelper-8eb361ff.mjs";
import "./useDiscoveryConfigs-cf63cd60.mjs";
import "@accelbyte/sdk-gdpr";
import "@accelbyte/sdk-legal";
import "./CommonError-e27d39d7.mjs";
import "./Dialog-b2e1c8bb.mjs";
import "react-dom";
import "./InfoIcon-c86fd057.mjs";
function Be({ onLinkAccount: a, onReclaim: r, className: s }) {
  const {
    state: { twitchDropData: o, twitchDropGamesData: c }
  } = U(), n = o == null ? void 0 : o.streamerInfo.data, t = o == null ? void 0 : o.backgroundConfig.data, l = t == null ? void 0 : t.backgroundOverlay, u = t == null ? void 0 : t.background;
  return /* @__PURE__ */ e.createElement(
    "div",
    {
      className: L("twitchDropLandingPage twitchDropLayout", s, {
        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("${u}")` }
    },
    /* @__PURE__ */ e.createElement("div", { className: "relative" }, /* @__PURE__ */ e.createElement(p, { 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(p, { tag: "p" }, "Participate on the event, watch Twitch streams, and earn rewards."), /* @__PURE__ */ e.createElement(p, { 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: V.TEXT }, n == null ? void 0 : n.streamButton.label))), c && c.length > 0 && /* @__PURE__ */ e.createElement(p, { tag: "p", className: "twitchDropLandingPage__bottomCta" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.landing.bottomCta" }, "Have problem claiming Twitch Drops? ", /* @__PURE__ */ e.createElement("button", { onClick: r }, "Re-claim here"))))
  );
}
function _e({ className: a }) {
  const { state: r } = Te(), { state: s } = ve(), o = () => {
    r.push(s.twitchDrops.claim.link);
  };
  function c() {
    r.push(s.twitchDrops.claim.makePath({ query: { step: "reclaim" } }));
  }
  return /* @__PURE__ */ e.createElement(
    Be,
    {
      onLinkAccount: o,
      onReclaim: c,
      className: L("twitchDropLandingPage twitchDropLayout", a)
    }
  );
}
function Xt() {
  return /* @__PURE__ */ e.createElement(_e, null);
}
const G = ({ children: a, className: r, isMultipleGame: s }) => /* @__PURE__ */ e.createElement("div", { className: L("twitchCard", r, s ? "multipleGame" : "") }, a);
function O({
  logo: a,
  title: r,
  subtitle: s,
  children: o,
  className: c,
  backgroundURL: n,
  backgroundOverlay: t,
  errorAlert: l
}) {
  return /* @__PURE__ */ e.createElement(
    "div",
    {
      className: L("twitchDropLayout relative", c, {
        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(${n})` }
    },
    /* @__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" })), (r || s) && /* @__PURE__ */ e.createElement("div", { className: "twitchDropLayout__titleContainer" }, r && /* @__PURE__ */ e.createElement(p, { tag: "h1", className: "twitchDropLayout__title" }, r), s && /* @__PURE__ */ e.createElement(p, { tag: "p", className: "twitchDropLayout__subtitle" }, s)), o)
  );
}
const Ye = "https://www.twitch.tv/drops/inventory", We = ({ className: a, logo: r, isPreview: s, isMultipleGame: o }) => {
  const {
    state: { twitchDropData: c }
  } = U(), { companyLogo: n } = D(F.TWITCHDROP, "header"), t = Ce();
  return /* @__PURE__ */ e.createElement(
    O,
    {
      backgroundOverlay: c == null ? void 0 : c.backgroundConfig.data.backgroundOverlay,
      backgroundURL: c == null ? void 0 : c.backgroundConfig.data.background,
      logo: r || n,
      className: L("linkedFormPanel linkLayout", a)
    },
    /* @__PURE__ */ e.createElement(G, { isMultipleGame: o }, /* @__PURE__ */ e.createElement(p, { 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(p, { 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.")), s ? /* @__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: Ye, 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: () => !s && t.logout(),
        buttonType: ee.PLAIN,
        buttonStyle: V.TEXT,
        hasOutline: !1
      },
      te("Navigation.links.logout")
    ))
  );
}, je = ({ 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: r, displayName: s, email: o, className: c, bottomCta: n }) => a ? /* @__PURE__ */ e.createElement("div", { className: "flex w-full flex-col gap-2 text-left" }, /* @__PURE__ */ e.createElement("div", { className: L(c, "userInfoCard") }, /* @__PURE__ */ e.createElement("div", { className: "avatarContainer" }, /* @__PURE__ */ e.createElement(Ge, { imageLink: r, className: "avatarImage" })), /* @__PURE__ */ e.createElement("div", { className: "userInfoContainer" }, /* @__PURE__ */ e.createElement(p, { tag: "p", className: "displayName" }, s), o && /* @__PURE__ */ e.createElement(p, { tag: "p", className: "email" }, o))), n && /* @__PURE__ */ e.createElement("div", { className: "bottomCta" }, n)) : /* @__PURE__ */ e.createElement("div", { className: "flex flex-col items-center gap-2" }, /* @__PURE__ */ e.createElement("div", { className: L(c, "userInfoCardDisplayNameOnly") }, /* @__PURE__ */ e.createElement(p, { tag: "p", isCentered: !0, className: "displayName" }, s)), n && /* @__PURE__ */ e.createElement("div", { className: "bottomCta" }, n)), ye = (a) => {
  const { user: r, avatarURL: s, isLoading: o, onLink: c, error: n, accountConflictInformation: t, logo: l, isPreview: u, isMultipleGame: h } = a, {
    state: { twitchDropData: g }
  } = U(), y = Ce(), { companyLogo: S } = D(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 || S,
      className: L("linkFormPanel linkLayout", a.className),
      errorAlert: /* @__PURE__ */ e.createElement(Me, { error: n, accountConflictInformation: t })
    },
    /* @__PURE__ */ e.createElement(G, { isMultipleGame: h }, /* @__PURE__ */ e.createElement(p, { tag: "h2" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.linkFormPanel.title" }, "Link to Twitch")), /* @__PURE__ */ e.createElement(p, { 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: s,
        displayName: r.displayName,
        email: r.emailAddress,
        bottomCta: /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.linkFormPanel.logout" }, "Not you?", " ", /* @__PURE__ */ e.createElement("a", { className: "btnLogout", onClick: () => !u && y.logout() }, "Logout"))
      }
    ), /* @__PURE__ */ e.createElement(M, { loadingIndicator: "SPINNER", onClick: c, isLoading: o, className: "btnTwitch" }, /* @__PURE__ */ e.createElement("div", { className: "btnItemContainer" }, /* @__PURE__ */ e.createElement(je, 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 Qe = ({ options: a = [], ...r }) => {
  var s;
  return a.length <= 1 ? /* @__PURE__ */ e.createElement("div", { className: "singleDrop" }, /* @__PURE__ */ e.createElement(p, { tag: "p", className: "gameDisplay" }, (s = a[0]) == null ? void 0 : s.label)) : /* @__PURE__ */ e.createElement("div", { className: "multiDrops" }, /* @__PURE__ */ e.createElement(
    Re,
    {
      label: /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.select.title" }, "Choose a game"),
      options: a,
      className: "selectContainer inputLabel",
      ...r
    }
  ));
};
function ze({ onCancel: a, onClaim: r, visible: s, isPreview: o, isMultipleGame: c, gameData: n }) {
  const [t, l] = C(n[0]), [u, h] = C(!1), g = (I) => {
    l(I);
  }, y = async () => {
    h(!0);
    const I = n.find((R) => R.value === t.value);
    I && await r(I.namespace, t.value, I.clientId, I.label), h(!1);
  }, S = c ? "multipleGame" : "";
  return /* @__PURE__ */ e.createElement(
    Se,
    {
      visible: s,
      className: `twitchDropPage__claimModal ${S}`,
      overlayClassName: S,
      isPreviewMode: o,
      overlayBackground: o ? { position: "absolute" } : void 0
    },
    /* @__PURE__ */ e.createElement(Oe, null, /* @__PURE__ */ e.createElement(p, { tag: "h2", fontSize: "lg", isCentered: !0 }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.modal.title" }, "Claim Drops")), /* @__PURE__ */ e.createElement(p, { 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(Qe, { options: n, 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: V.TEXT,
        hasOutline: !1
      },
      te("common.cancel")
    ), /* @__PURE__ */ e.createElement(
      M,
      {
        isLoading: u,
        onClick: y,
        buttonType: ee.FLAT,
        buttonFontSize: me.MEDIUM,
        buttonStyle: V.PRIMARY,
        disabled: !t
      },
      te("common.claim")
    )))
  );
}
const Je = ({ displayName: a, onUnlink: r, onClaim: s, className: o, logo: c, hasDropEntitlements: n, isMultipleGame: t }) => {
  const [l, u] = C(!1), [h, g] = C(!1), {
    state: { twitchDropData: y, twitchDropGamesData: S }
  } = U(), { companyLogo: I } = D(F.TWITCHDROP, "header");
  x(() => {
    n || u(!1);
  }, [n]);
  const R = async () => {
    u(!0);
  };
  return /* @__PURE__ */ e.createElement(
    O,
    {
      backgroundOverlay: y == null ? void 0 : y.backgroundConfig.data.backgroundOverlay,
      backgroundURL: y == null ? void 0 : y.backgroundConfig.data.background,
      logo: c || I,
      title: te("TwitchDropPage.reclaim.title"),
      subtitle: te("TwitchDropPage.reclaim.subtitle"),
      className: L("reclaimLayout", o)
    },
    /* @__PURE__ */ e.createElement(G, { className: "reclaimPanel", isMultipleGame: t }, !n && /* @__PURE__ */ e.createElement(Ke, { className: "w-full rounded-none", type: xe.info }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.twitchReclaimForm.card.noItem" }, "You have no drop items to claim.")), /* @__PURE__ */ e.createElement(p, { 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: R, buttonStyle: V.PRIMARY }, /* @__PURE__ */ e.createElement(E, { i18nKey: "LinkTwitchPage.twitchReclaimForm.card.claimButton" }, "Claim Now"))),
    /* @__PURE__ */ e.createElement(
      ze,
      {
        visible: l,
        onClaim: s,
        gameData: S || [],
        onCancel: () => u(!1),
        isPreview: !0
      }
    ),
    h && /* @__PURE__ */ e.createElement(
      Fe,
      {
        platformId: H.Enum.twitch,
        onCancel: () => g(!1),
        onConfirm: r
      }
    )
  );
};
const Xe = ({ onRetry: a, className: r, logo: s, isMultipleGame: o }) => {
  const {
    state: { twitchDropData: c }
  } = U(), { companyLogo: n } = D(F.TWITCHDROP, "header");
  return /* @__PURE__ */ e.createElement(
    O,
    {
      backgroundOverlay: c == null ? void 0 : c.backgroundConfig.data.backgroundOverlay,
      backgroundURL: c == null ? void 0 : c.backgroundConfig.data.background,
      logo: s || n,
      title: /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.error_panel.title" }, "Oops… something went wrong"),
      className: L("claimErrorPanel", r)
    },
    /* @__PURE__ */ e.createElement(G, { isMultipleGame: o }, /* @__PURE__ */ e.createElement("div", null, /* @__PURE__ */ e.createElement(p, { tag: "p" }, /* @__PURE__ */ e.createElement(E, { i18nKey: "TwitchDropPage.claim.error.message1" }, "There was a problem claiming your Twitch drop.")), /* @__PURE__ */ e.createElement(p, { 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 qe = "data:image/png;base64, ";
function Ze({ items: a, isMultipleGame: r, isPreviewMode: s }) {
  return /* @__PURE__ */ e.createElement("div", { className: L("itemListContainer", s ? "inPreview" : "") }, /* @__PURE__ */ e.createElement("div", { className: L("itemsRow", s ? "inPreview" : "") }, a.map((o, c) => /* @__PURE__ */ e.createElement("div", { key: c }, /* @__PURE__ */ e.createElement("div", { className: L("cardItem", r ? "multipleGame" : "") }, /* @__PURE__ */ e.createElement("div", { className: "itemImageContainer" }, /* @__PURE__ */ e.createElement("img", { src: o.imageUrl || qe, className: "m-auto w-3/4", alt: "drop-image" })), /* @__PURE__ */ e.createElement("div", { className: "itemName" }, /* @__PURE__ */ e.createElement(p, { tag: "h3", className: "text-3xl font-medium" }, o.name || "Item Name")), /* @__PURE__ */ e.createElement("div", { className: "h-auto" }, /* @__PURE__ */ e.createElement(p, { tag: "p" }, "Claimed")))))));
}
function $e(a) {
  const { logo: r, visible: s, isPreview: o, gameName: c, dropItems: n, onClose: t, isMultipleGame: l } = a;
  return x(() => {
    const u = (h) => {
      h.key === "Escape" && t();
    };
    return window.addEventListener("keydown", u), () => {
      window.removeEventListener("keydown", u);
    };
  }, []), /* @__PURE__ */ e.createElement(
    Se,
    {
      visible: s,
      className: L("twitchDropPage__successModal", o ? "inPreview" : "", l ? "multipleGame" : ""),
      isPreviewMode: o,
      overlayBackground: o ? { 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(Ve, { onClick: t }), /* @__PURE__ */ e.createElement("span", null, "Esc"))), r && /* @__PURE__ */ e.createElement("div", { className: "twitchDropLayout__logo" }, /* @__PURE__ */ e.createElement("img", { src: r, alt: "logo" })), /* @__PURE__ */ e.createElement(p, { 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: c }), " game.", /* @__PURE__ */ e.createElement("br", null), "The items will be sent to your in-game inventory."), /* @__PURE__ */ e.createElement("div", { className: L("listContainer", o ? "inPreview" : "") }, /* @__PURE__ */ e.createElement(Ze, { items: n, isMultipleGame: l, isPreviewMode: o })))
  );
}
const et = ({
  className: a,
  logo: r,
  isPreviewModalOpen: s,
  itemList: o,
  gameName: c,
  namespace: n,
  isMultipleGame: t,
  isPreview: l
}) => {
  const [u, h] = C(o.length !== 0), {
    state: { twitchDropData: g }
  } = U(), { companyLogo: y } = D(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: r || y,
      title: "Re-claim Twitch Drops",
      className: a
    },
    /* @__PURE__ */ e.createElement(G, { className: "claimSuccessPanel", isMultipleGame: t }, /* @__PURE__ */ e.createElement(we, { className: "icon", checked: !0, fill: !0 }), /* @__PURE__ */ e.createElement(p, { tag: "p" }, "All Done! You've successfully claimed your drops.")),
    /* @__PURE__ */ e.createElement(
      $e,
      {
        gameName: c,
        visible: s ?? u,
        isPreview: l,
        dropItems: o,
        backgroundURL: g == null ? void 0 : g.backgroundConfig.data.background,
        logo: r || y,
        namespace: n,
        onClose: () => h(!1),
        isMultipleGame: t
      }
    )
  );
};
function Ie(a) {
  const { message: r, className: s, logo: o, isMultipleGame: c } = a, {
    state: { twitchDropData: n }
  } = U(), { companyLogo: t } = D(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: o || t,
      className: L("loadingPanel", s),
      title: r
    },
    /* @__PURE__ */ e.createElement(G, { className: "loadingCard", isMultipleGame: c }, /* @__PURE__ */ e.createElement("div", { className: "spinnerWrapper" }, /* @__PURE__ */ e.createElement(Le, { 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 tt = ({ displayName: a, logo: r, onRelogin: s, className: o, isMultipleGame: c }) => {
  const {
    state: { twitchDropData: n }
  } = U(), { companyLogo: t } = D(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 || t,
      className: o
    },
    /* @__PURE__ */ e.createElement(G, { className: "contentPanel", isMultipleGame: c }, /* @__PURE__ */ e.createElement(p, { 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: s, buttonStyle: V.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))($ || {}), A = /* @__PURE__ */ ((a) => (a.VALIDATING = "validating", a.SUCCESS = "success", a.FAILED = "failed", a))(A || {});
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", at = "twitch-drop-thumbnail";
function nt({ displayName: a, validateStatus: r, retryStatus: s, onLink: o, className: c }) {
  const [n, t] = C("HOME"), [l, u] = C(!0), [h, g] = C(!1), [y, S] = C(""), [I, R] = C(""), [P, ce] = C(""), [B, ae] = C(""), [_, v] = C([]), { mutations: re } = ke(), {
    state: { user: b }
  } = fe(), [K] = ge();
  x(() => {
    const i = sessionStorage.getItem(J), d = sessionStorage.getItem(X), T = sessionStorage.getItem(q), w = sessionStorage.getItem(Z);
    i && d && w && T && (S(i), R(d), ae(w), ce(T), sessionStorage.removeItem(J), sessionStorage.removeItem(X), sessionStorage.removeItem(Z), sessionStorage.removeItem(q), r && t("VALIDATE"), s && !h && r === A.SUCCESS && Y(d, i, T, w, !0)), n === "VALIDATE" && (r === A.SUCCESS ? t("CLAIM") : r === A.FAILED && t("INCORRECT_TWITCH_ACCOUNT"));
  }, [n, r, _, s]);
  const se = async () => {
    await re.unLinkAccount(H.Enum.twitch), window.location.reload();
  }, Y = async (i, d = y, T, w, f) => {
    if (b != null && b.userId)
      try {
        sessionStorage.setItem(J, d), sessionStorage.setItem(X, i), sessionStorage.setItem(q, T), sessionStorage.setItem(Z, w), f && g(!0);
        const m = await he.IapApi(K, { namespace: i }).updateUserMeIapTwitchSync({ gameId: d });
        m.length === 0 && (u(!1), t("HOME")), m.length > 0 && (await j(m, i), u(!0), t("SUCCESS"));
      } catch (m) {
        u(!0), f ? t("ERROR") : le(m, d, i, T, w);
      }
  }, le = async (i, d, T, w, f) => {
    var m, k;
    if (Ue.isAxiosError(i)) {
      const z = (k = (m = i == null ? void 0 : i.response) == null ? void 0 : m.data) == null ? void 0 : k.errorCode;
      if (z === $.INVALID_PLATFORM_TOKEN && n !== "CLAIM")
        sessionStorage.setItem(J, d), sessionStorage.setItem(X, T), sessionStorage.setItem(q, w), sessionStorage.setItem(Z, f), o(!0, T, w);
      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, w, f);
        } catch {
          t("ERROR");
        }
      else
        t("ERROR");
    } else
      t("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((m) => !!m.itemSku).map((m) => m.itemSku ? W(m.itemSku, d) : null), f = (await Promise.all(T)).map((m) => {
      var z;
      let k = null;
      return m != null && m.images && (k = ((z = m.images.find((Ne) => Ne.as === at)) == null ? void 0 : z.imageUrl) || m.images[0].imageUrl), {
        name: (m == null ? void 0 : m.name) || "",
        imageUrl: k
      };
    }).sort((m, k) => m.name < k.name ? -1 : m.name > k.name ? 1 : 0);
    v(f);
  }, ne = () => {
    sessionStorage.setItem(J, y), sessionStorage.setItem(X, I), sessionStorage.setItem(q, P), sessionStorage.setItem(Z, B), o(!0, I, P);
  }, Q = () => {
    t("HOME");
  };
  return /* @__PURE__ */ e.createElement(e.Fragment, null, n === "HOME" && /* @__PURE__ */ e.createElement(
    Je,
    {
      displayName: a ?? "",
      onUnlink: se,
      onClaim: Y,
      className: c,
      hasDropEntitlements: l
    }
  ), n === "VALIDATE" && /* @__PURE__ */ e.createElement(Ie, { message: "Validating user account...", className: c }), n === "CLAIM" && /* @__PURE__ */ e.createElement(Ie, { message: "Claiming your drops...", className: c }), n === "SUCCESS" && /* @__PURE__ */ e.createElement(
    et,
    {
      namespace: I,
      gameName: B,
      itemList: _,
      className: c
    }
  ), n === "ERROR" && /* @__PURE__ */ e.createElement(Xe, { onRetry: Q, className: c }), n === "INCORRECT_TWITCH_ACCOUNT" && /* @__PURE__ */ e.createElement(tt, { displayName: a ?? "", onRelogin: ne, className: c }));
}
const ot = {
  useTwitchDrop: () => {
    const [a] = ge(), [r, s] = C({
      linkedTwitchAccount: null,
      linkedTwitchAccountError: null,
      linkedTwitchAccountFetchStatus: N.IDLE,
      loginURL: null,
      loginURLError: null,
      loginURLFetchStatus: N.IDLE
    }), o = ie((t) => {
      s((l) => ({
        ...l,
        ...t
      }));
    }, []), c = ie(
      async (t) => {
        let l = null, u = null;
        try {
          return o({ linkedTwitchAccountError: null, linkedTwitchAccountFetchStatus: N.FETCHING }), l = (await oe.UsersApi(a).getPlatforms_ByUserId(t)).data.find((g) => g.platformId === H.enum.twitch) || null, { data: l };
        } catch (h) {
          return u = pe.getErrorType(h), { error: u };
        } finally {
          o({ linkedTwitchAccount: l, linkedTwitchAccountError: u, linkedTwitchAccountFetchStatus: N.IDLE });
        }
      },
      [a]
    ), n = ie(
      async (t, l, u) => {
        let h = null, g = null;
        try {
          return o({ loginURLError: null, loginURLFetchStatus: N.FETCHING }), h = (await oe.UsersApi(a, { namespace: u }).getWebLinkMeUsers_ByPlatformId(H.enum.twitch, {
            redirectUri: t,
            clientId: l
          })).third_party_url, { data: h };
        } catch (y) {
          return g = pe.getErrorType(y), { error: g };
        } finally {
          o({ loginURL: h, loginURLError: g, loginURLFetchStatus: N.IDLE });
        }
      },
      [a]
    );
    return {
      state: r,
      mutations: {
        fetchLinkedTwitchAccount: c,
        fetchTwitchLoginURL: n
      }
    };
  }
}, ct = "AB-Twitch_drops-claim-game_client_id", rt = (a) => {
  const [r, s] = e.useState({
    validateStatus: null,
    retryStatus: !1,
    isExchangingToken: !1
  }), { validateStatus: o, retryStatus: c, isExchangingToken: n } = r, {
    state: { user: t, userProfile: l }
  } = fe(), {
    state: { linkedTwitchAccount: u, linkedTwitchAccountFetchStatus: h, loginURLFetchStatus: g },
    mutations: { fetchLinkedTwitchAccount: y, fetchTwitchLoginURL: S }
  } = ot.useTwitchDrop(), { state: I } = Te(), [R] = ge(), [P] = Pe(), {
    state: { requestStatusFetchStatus: ce, accountConflictInformation: B, requestStatusError: ae },
    mutations: _
  } = ke(), v = (i) => {
    s((d) => ({
      ...d,
      ...i
    }));
  };
  x(() => (!u && (t != null && t.userId) && y(t.userId), () => {
    _.resetErrorState();
  }), []), x(() => {
    const i = K() ? A.VALIDATING : null;
    v({ validateStatus: i });
  }, [I.location.search]), x(() => {
    const i = K();
    i && (t != null && t.userId) && re(i, t == null ? void 0 : t.userId);
    const d = se();
    d && !i && Y(d);
  }, [t == null ? void 0 : t.userId, I.location.search]);
  const re = async (i, d) => {
    try {
      v({ isExchangingToken: !0 });
      const T = sessionStorage.getItem(ct) || "", w = R.assembly().config, f = await He.exchangeTokenOauthByPlatformId(
        H.Enum.twitch,
        T,
        {
          platform_token: i,
          client_id: T,
          createHeadless: !1,
          skipSetCookie: !0
        },
        w
      );
      if (f.error)
        throw f.error;
      let m = "";
      f.response.data.namespace === P.namespace ? m = f.response.data.user_id : f.response.data.platform_user_id && (m = (await oe.UsersApi(R).getUser_ByPlatformId_ByPlatformUserId(
        H.Enum.twitch,
        f.response.data.platform_user_id
      )).userId), v({
        validateStatus: m === d ? A.SUCCESS : A.FAILED,
        retryStatus: !0
      });
    } catch {
      v({
        validateStatus: A.FAILED
      });
    } finally {
      v({ isExchangingToken: !1 }), I.replace(j());
    }
  }, b = () => {
    const i = new URLSearchParams(I.location.search);
    return i.get("step") === "reclaim" || i.get("state") === "reclaim";
  }, K = () => new URLSearchParams(I.location.search).get("code"), se = () => new URLSearchParams(I.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 {
        I.replace(j());
      }
  }, le = (i) => {
    v({
      validateStatus: (i == null ? void 0 : i.errorCode) === $.TWITCH_ACCOUNT_ALREADY_LINKED ? A.SUCCESS : A.FAILED
    });
  }, W = async (i = !1, d, T) => {
    const w = ue.getRedirectUrl(P.redirectURI, j()), f = await S(w, T || P.clientId, d);
    if (!f.error) {
      const m = f.data;
      if (m)
        if (i) {
          const k = new URL(m);
          k.searchParams.set("force_verify", "true"), d && k.searchParams.set("redirect_uri", ue.getRedirectUrl(P.redirectURI, "/twitch-drops/claim?step=reclaim")), window.location.href = k.toString();
        } else
          window.location.href = m;
    }
  }, j = () => I.location.pathname + (b() ? "?state=reclaim" : ""), ne = g === N.FETCHING, Q = n || ce === N.FETCHING || h === N.FETCHING;
  return /* @__PURE__ */ e.createElement(e.Fragment, null, Q && /* @__PURE__ */ e.createElement(Le, { className: be.tall }), !b() && !Q && t && /* @__PURE__ */ e.createElement(e.Fragment, null, u ? /* @__PURE__ */ e.createElement(We, { className: a.className }) : /* @__PURE__ */ e.createElement(
    ye,
    {
      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, u ? /* @__PURE__ */ e.createElement(
    nt,
    {
      displayName: (u == null ? void 0 : u.displayName) ?? "",
      validateStatus: o,
      retryStatus: c,
      onLink: W,
      className: a.className
    }
  ) : /* @__PURE__ */ e.createElement(
    ye,
    {
      user: t,
      avatarURL: (l == null ? void 0 : l.avatarUrl) ?? "",
      onLink: W,
      isLoading: ne,
      error: ae,
      accountConflictInformation: B,
      className: a.className
    }
  )));
};
function qt() {
  return /* @__PURE__ */ e.createElement(De, null, /* @__PURE__ */ e.createElement(rt, null));
}
export {
  Xt as TwitchDropLandingWidget,
  qt as TwitchDropWidget
};
