"use strict";(globalThis.webpackChunk_smart_cloud_gatey_admin=globalThis.webpackChunk_smart_cloud_gatey_admin||[]).push([[491],{491(e,s,t){t.r(s),t.d(s,{default:()=>h});var i=t(790),o=t(84),r=t(723),n=t(641),a=t(899),c=t(693),d=t(449),u=t(225),l=t(988),m=t(609),v=t(618),p=t(514),g=t(226),x=t(761);const f=v.Ik({customProviders:v.YO(v.Ik({id:v.Yj(),providerName:v.Yj().refine(e=>e&&e.trim().length>0,{message:"Custom provider name is required"}),providerTitle:v.Yj().optional(),icon:v.Yj().optional()}))}),P={customProviders:[]};function h({apiUrl:e,config:s,accountId:t,siteId:v,siteKey:h,onSave:j}){const[y,k]=(0,m.useState)(!1),[b,I]=(0,m.useState)(!1),T=(0,i.useForm)({mode:"uncontrolled",initialValues:{...P},validate:(0,l.s)(f)}),S=(0,m.useCallback)(async a=>{if(t&&v&&h){I(!0);try{const n={...s,customProviders:a.customProviders};delete n.subscriptionType;const d=await(0,p.D)(e,t,v,h,n);j(d),i.notifications.show({title:(0,r.__)("Settings saved",o.Xg),message:(0,r.__)("Form field settings saved successfully",o.Xg),color:"green",icon:(0,x.jsx)(c.A,{}),className:g.A.notification})}catch(e){console.error("Error saving form field settings:",e),i.notifications.show({title:(0,r.__)("Error occured",o.Xg),message:e.message,color:"red",icon:(0,x.jsx)(n.A,{}),className:g.A.notification})}finally{I(!1)}}else console.error("Missing account ID or site ID or site key")},[t,v,h,s,e,j]);return(0,m.useEffect)(()=>{queueMicrotask(()=>{if(!y&&s){const e={customProviders:[]};s.customProviders&&(e.customProviders=s.customProviders),T.setValues(e),k(!0)}})},[s,T,y]),(0,m.useEffect)(()=>{queueMicrotask(()=>{s&&k(!1)})},[s]),(0,x.jsxs)("form",{onSubmit:T.onSubmit(S),children:[(0,x.jsx)(i.Stack,{mb:"lg",children:(0,x.jsxs)(i.Card,{withBorder:!0,p:"xs",w:"100%",h:"100%",children:[(0,x.jsx)(i.Card.Section,{p:"md",children:(0,x.jsx)(i.Text,{c:"dimmed",size:"xs",children:"Add custom providers. Each custom provider must have a name."})}),T.getValues().customProviders?.map((e,s)=>(0,x.jsxs)(i.Flex,{direction:"row",gap:"xs",align:"center",children:[(0,x.jsx)(i.TextInput,{label:"Provider Name",...T.getInputProps(`customProviders.${s}.providerName`)},T.key(`customProviders.${s}.providerName`)),(0,x.jsx)(i.TextInput,{label:"Provider Title",...T.getInputProps(`customProviders.${s}.providerTitle`)},T.key(`customProviders.${s}.providerTitle`)),(0,x.jsx)(i.TextInput,{label:"Icon (in base64 format)",...T.getInputProps(`customProviders.${s}.icon`)},T.key(`customProviders.${s}.icon`)),(0,x.jsx)(i.Button,{variant:"subtle",size:"xs",mt:"0.3rem",onClick:()=>T.removeListItem("customProviders",s),children:(0,x.jsx)(u.A,{size:14,color:"red"})})]},T.key(`customProviders.${s}`))),(0,x.jsx)(i.Button,{variant:"subtle",mt:"xs",size:"xs",leftSection:(0,x.jsx)(d.A,{size:14}),onClick:()=>{T.insertListItem("customProviders",{id:(0,i.randomId)(),providerName:"",providerTitle:"",icon:""})},children:"Add Custom Provider"})]})}),(0,x.jsx)(i.Group,{justify:"flex-end",mt:"xl",children:(0,x.jsx)(i.Button,{type:"submit",variant:"gradient",loading:b,leftSection:(0,x.jsx)(a.A,{size:16}),children:"Save Social Providers Configuration"})})]})}},514(e,s,t){async function i(e,s,t,i,o){const r=await fetch(`${e}/account/${s}/site/${t}/settings`,{method:"PUT",headers:{"Content-Type":"application/json","X-Site-Key":i,"X-Plugin":"gatey"},body:JSON.stringify({settings:o})});if(!r.ok){const e=await r.text();throw new Error(e||`HTTP error! status: ${r.status}`)}return(await r.json()).settings}t.d(s,{D:()=>i})}}]);