import t,{useEffect as g,useState as s}from"react";import{useNavigate as h}from"react-router-dom";import{Button as y}from"@redocly/theme/components/Button/Button";import{H3 as v}from"@redocly/theme/components/Typography/H3";import{H4 as S}from"@redocly/theme/components/Typography/H4";import{Admonition as w}from"@redocly/theme/components/Admonition/Admonition";import{getBaseDataAttributes as P,getPathnameForLocale as E,withPathPrefix as L}from"@redocly/theme/core/utils";import{ServerRoutes as b}from"../../../../constants/api";import{telemetry as k}from"../../telemetry/index.js";import{buildLoginUrl as O}from"../../../../utils/auth/build-login-url";import{usePageProps as T}from"../../../providers/page-data/hooks";import{Wrapper as C,HeadingSection as R}from"./styled";import{DevLoginForm as A}from"./DevLoginForm";import{useL10nConfig as F}from"../../hooks";async function x(r){try{const{status:o}=await fetch(L(b.AUTHORIZATION),{method:"POST",body:JSON.stringify(r)});return o}catch(o){console.error(o)}}function K(){const{defaultLocale:r,locales:o,currentLocale:c}=F(),l=h(),[a,d]=s({values:{teams:[],email:"example@example.com"}}),[i,u]=s();g(()=>{const e=new URLSearchParams(window.location.search);u(e.get("redirectTo")||void 0)},[]);const n=T(),m=n?.authIdps,p=(n.rbac?.teams||[]).filter(e=>e!=="*"),f=async()=>{await x(a.values)===200&&(l(i||"/"),window.location.reload())};return t.createElement(C,null,t.createElement(R,null,t.createElement(v,{"data-cy":"login-title"},"Dev-mode login"),t.createElement(w,{type:"warning",name:"This is dev mode login simulator."},"Any email works and password is not checked.")),t.createElement(t.Fragment,null,t.createElement(A,{teams:p,formState:a,setFormState:d,onSubmit:f}),Object.keys(m||{}).length>0&&t.createElement(S,null,"Use SSO:"),Object.values(m||{}).map(e=>t.createElement("div",{key:e.idpId},t.createElement(y,{fullWidth:!0,size:"large","data-cy":"idp-login",to:O(e.idpId,E("",r,c,o),i),onClick:()=>k.sendLoginProviderClickedMessage([{...P("loginProvider","button"),provider:e.type}])},e.title||e.type)))))}export{K as default};
