"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("./LoginIcon-ac34cdc4.js"),e=require("react"),v=require("react-i18next"),m=require("./useRoutes-df841412.js"),g=require("./Env-a6f11491.js"),P=require("@accelbyte/sdk-iam"),C=require("./CommonError-3e91e7d2.js"),L=require("./ArrowIcon-c2b12c44.js"),h=require("./LoadingPage-03a67d0f.js"),S=require("./ProfileImage-52ff6047.js"),d=require("classnames"),N=require("./index-dae188cc.js"),b=require("./LogoutIcon-bcb108a7.js"),w=require("./index-929f0913.js");require("react-feather");require("flat");require("i18next");require("date-fns");require("@accelbyte/sdk");require("./utils.js");require("zod");require("uuid");require("axios");require("@accelbyte/sdk-basic");require("./ErrorLayout-10fb8a78.js");require("./UrlUtils-33beea49.js");require("./merge-a4eeca79.js");require("@accelbyte/sdk-legal");require("react-dom");require("buffer");require("react-toastify");require("@accelbyte/sdk-gdpr");const U=({currentLocation:t,returnPath:s})=>{const{state:o}=m.useRoutes(),[r]=g.useSdk(),a=!t.includes(o.error.index.link)&&t||null,i=()=>{const l=new P.IamUserAuthorizationClient(r).createLoginURL(s||a);window.location.replace(l)};return e.createElement("div",{className:"loginButtonContainer"},e.createElement(m.Button,{className:"loginButton",buttonType:m.ButtonType.TEXT,buttonStyle:m.ButtonStyle.WHITE,onClick:i},e.createElement(y.LoginIcon,null),e.createElement(v.Trans,{i18nKey:"Navigation.links.login"},"Login")))};const F=({user:t,userProfile:s,isFetching:o,wallet:r,error:n,toggleMenu:a,isMenuShown:i,isDisableUsername:l})=>{const{state:{flags:c},hasFeature:u}=N.useDiscoveryConfigs(),f=e.useMemo(()=>u("isAvatarVisible"),[c]),E=()=>P.EligibleUser.safeParse(t).success?l?t.displayName||t.userName:t.userName||t.displayName:null;return e.createElement("div",{className:d("userProfileDropdown",i&&"open"),onClick:()=>a()},!o&&n&&e.createElement(C.CommonError,{error:n}),!o&&!n?e.createElement(e.Fragment,null,f&&e.createElement(S.ProfileImage,{imageLink:s&&s.avatarUrl||"",className:"userProfileImage"}),e.createElement("div",{className:"userProfileContainer"},e.createElement("p",{className:"userProfileDisplayName"},E()),r&&e.createElement("p",{className:"userProfileWallet"},r.currencySymbol," ",r.balance)),e.createElement(L.ArrowIcon,{className:d(L.ArrowIconStyles.down,"arrowSize")})):e.createElement(h.Loading,null))};const T=({onLogout:t,showMenu:s,onClick:o,userDropdownMenus:r})=>{const n=!s,{state:{flags:a},hasFeature:i}=N.useDiscoveryConfigs(),l=e.useMemo(()=>i("isGetLauncherVisible"),[a]);return e.createElement("nav",{className:d("userProfileNavContainer",n&&"closed",!l&&"right-0")},r==null?void 0:r.map((c,u)=>e.createElement("div",{key:`menuLink-${u}`},e.createElement(w.NavLink,{className:"userProfileNavLink",to:c.pathname,onClick:o},c.icon&&e.createElement("i",{className:"userProfileNavLinkIcon"},c.icon),e.createElement("span",null,c.label)),c.isWithDivider&&e.createElement("div",{className:"navigationDivider"}))),e.createElement("button",{className:"userProfileNavLink",onClick:()=>{t(),o()}},e.createElement(b.LogoutIcon,{className:"userProfileNavLinkIcon"}),e.createElement("span",null,e.createElement(v.Trans,{i18nKey:"Navigation.links.logout"},"Logout"))))};function A({onLogout:t,returnPath:s,isDisableUsername:o,userDropdownMenus:r}){const{state:{location:n}}=m.useHistory(),a=n.pathname,{state:{user:i}}=g.useUserInfo();return e.createElement(e.Fragment,null,!i&&e.createElement(U,{currentLocation:a,returnPath:s}),i&&e.createElement(B,{user:i,userDropdownMenus:r,onLogout:t,isDisableUsername:o}))}function B({userDropdownMenus:t,user:s,onLogout:o,isDisableUsername:r}){const[n,a]=e.useState(!1),i=e.useRef(null),{state:{userProfile:l,userProfileFetchStatus:c,userFetchStatus:u}}=g.useUserInfo(),f=N.useAppState(),E=c===g.FetchStatus.FETCHING||u===g.FetchStatus.FETCHING;e.useEffect(()=>{const q=k=>{n&&!k.composedPath().includes(i.current)&&a(!1)};return window.addEventListener("click",q),()=>{window.removeEventListener("click",q)}},[n]);const p=async()=>{await f.logout(),o&&o()},I=()=>{a(!n)};return e.createElement("div",{className:"userAccountContainer",ref:i},e.createElement(F,{user:s,userProfile:l,wallet:null,error:null,isFetching:E,toggleMenu:I,isMenuShown:n,isDisableUsername:r}),e.createElement(T,{onClick:()=>a(!1),onLogout:p,showMenu:n,userDropdownMenus:t}))}exports.LoginWidget=A;
