import{i$ as R,fH as s,bL as g,iv as w,iG as A,hi as k,ie as C,j5 as E,iQ as O,an as F,aZ as x,aw as T,jG as q,h1 as z,ck as H,aD as U,cz as b,e5 as V,e8 as G,e9 as j,es as p,ea as _,fo as $,bd as B,hU as D,cI as u,gf as N,cN as Q}from"./strapi-ye6TfKul.js";import{u as W}from"./useAdminRoles-C08Egt77.js";const Z=V().shape({autoRegister:_().required(p.required),defaultRole:j().when("autoRegister",(e,t)=>e?t.required(p.required):t.nullable()),ssoLockedRoles:G().nullable().of(j().when("ssoLockedRoles",(e,t)=>e?t.required(p.required):t.nullable()))}),J=()=>{const{formatMessage:e}=w(),t=R(l=>l.admin_app.permissions),{toggleNotification:o}=A(),{_unstableFormatAPIError:m,_unstableFormatValidationErrors:h}=k(),{isLoading:i,data:n}=C(),[d,{isLoading:L}]=E(),{isLoading:M,allowedActions:{canUpdate:y,canRead:I}}=O({...t.settings?.sso,readRoles:t.settings?.roles.read??[]}),{roles:f,isLoading:P}=W(void 0,{skip:!I}),v=async(l,c)=>{try{const a=await d(l);if("error"in a){$(a.error)&&a.error.name==="ValidationError"?c.setErrors(h(a.error)):o({type:"danger",message:m(a.error)});return}o({type:"success",message:e({id:"notification.success.saved"})})}catch{o({type:"danger",message:e({id:"notification.error",defaultMessage:"An error occurred, please try again."})})}},S=P||M||i;return s.jsxs(s.Fragment,{children:[s.jsx(g.Title,{children:e({id:"Settings.PageTitle",defaultMessage:"Settings - {name}"},{name:"SSO"})}),s.jsx(g.Main,{"aria-busy":L||S,tabIndex:-1,children:s.jsx(F,{method:"PUT",onSubmit:v,validationSchema:Z,disabled:!y,initialValues:n||{autoRegister:!1,defaultRole:null,ssoLockedRoles:null},children:({modified:l,isSubmitting:c})=>s.jsxs(s.Fragment,{children:[s.jsx(x.Header,{primaryAction:s.jsx(q,{disabled:!l,loading:c,startIcon:s.jsx(z,{}),type:"submit",fullWidth:!0,children:e({id:"global.save",defaultMessage:"Save"})}),title:e({id:"Settings.sso.title",defaultMessage:"Single Sign-On"}),subtitle:e({id:"Settings.sso.description",defaultMessage:"Configure the settings for the Single Sign-On feature."}),secondaryAction:s.jsx(T,{label:e({id:"components.premiumFeature.title",defaultMessage:"Premium feature"})})}),s.jsx(x.Content,{children:c||S?s.jsx(g.Loading,{}):s.jsxs(H,{direction:"column",alignItems:"stretch",gap:4,background:"neutral0",padding:6,shadow:"filterShadow",hasRadius:!0,children:[s.jsx(U,{variant:"delta",tag:"h2",children:e({id:"global.settings",defaultMessage:"Settings"})}),s.jsx(b.Root,{gap:4,children:[{hint:e({id:"Settings.sso.form.registration.description",defaultMessage:"Create new user on SSO login if no account exists"}),label:e({id:"Settings.sso.form.registration.label",defaultMessage:"Auto-registration"}),name:"autoRegister",size:6,type:"boolean"},{hint:e({id:"Settings.sso.form.defaultRole.description",defaultMessage:"It will attach the new authenticated user to the selected role"}),label:e({id:"Settings.sso.form.defaultRole.label",defaultMessage:"Default role"}),name:"defaultRole",options:f.map(({id:a,name:r})=>({label:r,value:a.toString()})),placeholder:e({id:"components.InputSelect.option.placeholder",defaultMessage:"Choose here"}),size:6,type:"enumeration"},{hint:e({id:"Settings.sso.form.localAuthenticationLock.description",defaultMessage:"Select the roles for which you want to disable the local authentication"}),label:e({id:"Settings.sso.form.localAuthenticationLock.label",defaultMessage:"Local authentication lock-out"}),name:"ssoLockedRoles",options:f.map(({id:a,name:r})=>({label:r,value:a.toString()})),placeholder:e({id:"components.InputSelect.option.placeholder",defaultMessage:"Choose here"}),size:6,type:"multi"}].map(({size:a,...r})=>s.jsx(b.Item,{col:a,xs:12,direction:"column",alignItems:"stretch",children:s.jsx(K,{...r})},r.name))})]})})]})})})]})},K=e=>{switch(e.type){case"multi":return s.jsx(X,{...e});default:return s.jsx(B,{...e})}},X=({hint:e,label:t,name:o,options:m,...h})=>{const i=D(o);return s.jsxs(u.Root,{name:o,hint:e,error:i.error,children:[s.jsx(u.Label,{children:t}),s.jsx(N,{onChange:n=>i.onChange("ssoLockedRoles",n),onClear:()=>i.onChange("ssoLockedRoles",[]),value:i.value??[],withTags:!0,...h,children:m.map(({label:n,value:d})=>s.jsx(Q,{value:d,children:n},d))}),s.jsx(u.Hint,{}),s.jsx(u.Error,{})]})},se=()=>{const e=R(t=>t.admin_app.permissions.settings?.sso?.main);return s.jsx(g.Protect,{permissions:e,children:s.jsx(J,{})})};export{se as ProtectedSSO,J as SingleSignOnPage};
