"use strict";(globalThis.webpackChunkwp_graphql_headless_login=globalThis.webpackChunkwp_graphql_headless_login||[]).push([[767],{767:(e,s,i)=>{i.r(s),i.d(s,{default:()=>C});var t=i(427),n=i(609),o=i(723),l=i(582),a=i(143),r=i(93),c=i(790);function p({clientSlug:e,optionsKey:s,options:i,setOption:t}){const n=wpGraphQLLogin?.settings?.providers?.[e]?.[s]?.properties||{};return(0,c.jsx)(r.C,{fields:n,values:i,setValue:t,excludedProperties:["id","order"]})}const d={name:"",order:0,isEnabled:!1,clientOptions:{},loginOptions:{useAuthenticationCookie:!1}},g=(0,n.createContext)({activeClient:"",setActiveClient:()=>{},clientConfig:void 0,setClientConfig:()=>{},updateClient:()=>{},setClientOption:()=>{},setLoginOption:()=>{}}),h=({children:e})=>{const[s,i]=(0,n.useState)(Object.keys(wpGraphQLLogin?.settings.providers)?.[0]||""),[t,o]=(0,l.useEntityProp)("root","site",s),a=(0,n.useCallback)(((e,s)=>{const i={...t,[e]:s};o(i)}),[t,o]),r=(0,n.useCallback)((e=>{a("clientOptions",{...t?.clientOptions,...e})}),[t,a]),p=(0,n.useCallback)((e=>{a("loginOptions",{...t?.loginOptions,...e})}),[t,a]);return(0,n.useEffect)((()=>{void 0!==s&&void 0!==t&&0===Object.keys(t||{})?.length&&o({...d,slug:s.replace("wpgraphql_login_provider_","")})}),[t,o,s]),(0,c.jsx)(g.Provider,{value:{activeClient:s,setActiveClient:i,clientConfig:t,setClientConfig:o,updateClient:a,setClientOption:r,setLoginOption:p},children:e})},u=()=>(0,n.useContext)(g);var _=i(713),v=i(3);function x(){const{settings:e}=(0,v.t)(),{activeClient:s,clientConfig:i,setClientConfig:d,updateClient:g,setClientOption:h,setLoginOption:x}=u(),{saveEditedEntityRecord:j}=(0,a.useDispatch)(l.store),{lastError:m,isSaving:C,hasEdits:w}=(0,a.useSelect)((e=>({lastError:e(l.store)?.getLastEntitySaveError("root","site"),isSaving:e(l.store)?.isSavingEntityRecord("root","site"),hasEdits:e(l.store)?.hasEditsForEntityRecord("root","site")})),[]);(0,n.useEffect)((()=>{m&&(0,a.dispatch)("core/notices").createErrorNotice((0,o.sprintf)(
// translators: %s: Error message.
// translators: %s: Error message.
(0,o.__)("Error saving settings: %s","wp-graphql-headless-login"),m?.data?.params?.[s]||m?.message),{type:"snackbar",isDismissible:!0,explicitDismiss:!0})}),[m,s]),(0,n.useEffect)((()=>{const t=e?.wpgraphql_login_access_control||{};!t?.shouldBlockUnauthorizedDomains&&"wpgraphql_login_provider_siteToken"===s&&i?.isEnabled&&(g("isEnabled",!1),(0,a.dispatch)("core/notices").createErrorNotice((0,o.__)("The Site Token provider can only be enabled if `Access Control Settings: Block unauthorized domains` is enabled.","wp-graphql-headless-login"),{type:"snackbar",isDismissible:!0,explicitDismiss:!0}))}),[e?.wpgraphql_login_access_control,s,i,g]);const b=()=>wpGraphQLLogin.hooks.applyFilters("graphql_login_custom_client_settings",(0,c.jsx)(c.Fragment,{}),s,i);return s&&i?(0,c.jsxs)(c.Fragment,{children:[(0,c.jsxs)(t.PanelBody,{children:[(0,c.jsx)(t.PanelRow,{children:(0,c.jsx)("h2",{className:"components-panel__body-title",children:(0,o.sprintf)(
// translators: %s: Client slug.
// translators: %s: Client slug.
(0,o.__)("%s Settings","wp-graphql-headless-login"),wpGraphQLLogin?.settings?.providers?.[s]?.name?.default||"Provider")})}),(0,c.jsx)(r.C,{excludedProperties:["loginOptions","clientOptions","order"],values:i,fields:wpGraphQLLogin?.settings?.providers?.[s],setValue:e=>{d({...i,...e})}}),(0,c.jsx)(p,{clientSlug:s,optionsKey:"clientOptions",options:i?.clientOptions,setOption:h})]}),(0,c.jsxs)(t.PanelBody,{children:[(0,c.jsx)(t.PanelRow,{children:(0,c.jsxs)("h2",{className:"components-panel__body-title",children:[(0,o.__)("Login Settings","wp-graphql-headless-login"),(0,c.jsx)(t.Icon,{icon:"admin-users",className:"components-panel__icon",size:20})]})}),(0,c.jsx)(p,{clientSlug:s,optionsKey:"loginOptions",options:i?.loginOptions,setOption:x})]}),(0,c.jsx)(b,{}),(0,c.jsxs)(t.Button,{variant:"primary",onClick:()=>{(async()=>{await j("root","site",void 0,{[s]:i})&&(0,a.dispatch)("core/notices").createNotice("success","Settings saved",{type:"snackbar",isDismissible:!0})})()},disabled:!w,isBusy:C,children:[(0,o.__)("Save Providers","wp-graphql-headless-login"),C&&(0,c.jsx)(t.Spinner,{})]})]}):(0,c.jsx)(t.Placeholder,{icon:(0,c.jsx)(t.Icon,{icon:(0,c.jsx)(_.h,{})}),title:(0,o.__)("Loading…","wp-graphql-headless-login"),instructions:(0,o.__)("Please wait while the settings are loaded.","wp-graphql-headless-login")})}function j({provider:e}){var s;const[i]=(0,l.useEntityProp)("root","site",e),t=null!==(s=i?.isEnabled)&&void 0!==s&&s,n=t?(0,o.__)("Enabled","wp-graphql-headless-login"):(0,o.__)("Disabled","wp-graphql-headless-login");return(0,c.jsx)("div",{className:"gkD0Ce8Yd5uUqpPvYYB0",children:(0,c.jsx)("span",{className:t?"lPF8FLjhfMFOGtzovGVU":void 0,"aria-label":n,title:n})})}function m(){const e=Object.keys(wpGraphQLLogin?.settings?.providers||{}),{activeClient:s,setActiveClient:i}=u();return(0,c.jsx)(t.__experimentalNavigation,{activeItem:s,children:(0,c.jsx)(t.__experimentalNavigationMenu,{title:(0,o.__)("Providers","wp-graphql-headless-login"),children:e.length>0&&e.map((e=>(0,c.jsx)(t.__experimentalNavigationItem,{className:"yRYXYpZjKTexJX_rQFwE",item:e,title:wpGraphQLLogin?.settings?.providers?.[e]?.name?.default,icon:(0,c.jsx)(j,{provider:e}),onClick:()=>i(e)},e)))})})}const C=function(){return(0,c.jsx)(t.Flex,{align:"flex-start",children:(0,c.jsxs)(h,{children:[(0,c.jsx)(t.FlexItem,{className:"ZSsKd0oQhMbMP0pWT2bp",children:(0,c.jsx)(m,{})}),(0,c.jsx)(t.FlexBlock,{children:(0,c.jsx)(t.Panel,{className:"wp-graphql-headless-login__client",children:(0,c.jsx)(x,{})})})]})})}}}]);