import t,{useEffect as g,useState as l}from"react";import{useNavigate as h}from"react-router-dom";import{Button as y}from"@redocly/theme/components/Button/Button";import{H3 as S}from"@redocly/theme/components/Typography/H3";import{H4 as v}from"@redocly/theme/components/Typography/H4";import{Admonition as w}from"@redocly/theme/components/Admonition/Admonition";import{getPathnameForLocale as E,withPathPrefix as P}from"@redocly/theme/core/utils";import{ServerRoutes as L}from"../../../../constants/index.js";import{otelTelemetry as T}from"../../telemetry/otel/telemetry";import{buildClientLoginUrl as b}from"../../utils";import{usePageProps as k}from"../../../providers/page-data/hooks";import{Wrapper as O,HeadingSection as C}from"./styled";import{DevLoginForm as R}from"./DevLoginForm";import{useL10nConfig as F}from"../../hooks";async function U(r){try{const{status:o}=await fetch(P(L.AUTHORIZATION),{method:"POST",body:JSON.stringify(r)});return o}catch(o){console.error(o)}}function G(){const{defaultLocale:r,locales:o,currentLocale:s}=F(),c=h(),[n,d]=l({values:{teams:[],email:"example@example.com"}}),[i,u]=l();g(()=>{const e=new URLSearchParams(window.location.search);u(e.get("redirectTo")||void 0)},[]);const a=k(),m=a?.authIdps,p=(a.rbac?.teams||[]).filter(e=>e!=="*"),f=async()=>{await U(n.values)===200&&(c(i||"/"),window.location.reload())};return t.createElement(O,null,t.createElement(C,null,t.createElement(S,{"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(R,{teams:p,formState:n,setFormState:d,onSubmit:f}),Object.keys(m||{}).length>0&&t.createElement(v,null,"Use SSO:"),Object.values(m||{}).map(e=>t.createElement("div",{key:e.idpId},t.createElement("a",{href:b(e.idpId,e.type,E("",r,s,o),a.loginUrls,i)},t.createElement(y,{fullWidth:!0,size:"large","data-cy":"idp-login",onClick:()=>T.send({type:"login_provider_button.clicked",payload:{provider:e.type}})},e.title||e.type))))))}export{G as default};
