import{a as w}from"./chunk-JCJEDJ2P.mjs";import{a as A}from"./chunk-I73BG5T4.mjs";import{b as I}from"./chunk-L4PHCRYX.mjs";import{CloseIcon as H}from"@baseapp-frontend/design-system/components/web/icons";import{TextField as S}from"@baseapp-frontend/design-system/components/web/inputs";import{setFormRelayErrors as W}from"@baseapp-frontend/utils";import{zodResolver as q}from"@hookform/resolvers/zod";import{LoadingButton as G}from"@mui/lab";import{Box as j,Button as J,Dialog as K,DialogActions as Q,DialogContent as X,DialogTitle as Y,IconButton as Z,Link as ee,Typography as v}from"@mui/material";import{useForm as oe}from"react-hook-form";import{ConnectionHandler as re}from"react-relay";import te from"slugify";import{jsx as n,jsxs as l}from"react/jsx-runtime";function $(e,o){return E(e)||V(e,o)||U(e,o)||R()}function R(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function U(e,o){if(e){if(typeof e=="string")return L(e,o);var r={}.toString.call(e).slice(8,-1);return r==="Object"&&e.constructor&&(r=e.constructor.name),r==="Map"||r==="Set"?Array.from(e):r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?L(e,o):void 0}}function L(e,o){(o==null||o>e.length)&&(o=e.length);for(var r=0,i=Array(o);r<o;r++)i[r]=e[r];return i}function V(e,o){var r=e==null?null:typeof Symbol<"u"&&e[Symbol.iterator]||e["@@iterator"];if(r!=null){var i,d,c,s,m=[],a=!0,f=!1;try{if(c=(r=r.call(e)).next,o===0){if(Object(r)!==r)return;a=!1}else for(;!(a=(i=c.call(r)).done)&&(m.push(i.value),m.length!==o);a=!0);}catch(u){f=!0,d=u}finally{try{if(!a&&r.return!=null&&(s=r.return(),Object(s)!==s))return}finally{if(f)throw d}}return m}}function E(e){if(Array.isArray(e))return e}var D=0,ne=function(o){var r=o.addNewProfileLabel,i=r===void 0?"New organization":r,d=o.termsAndConditionsUrl,c=d===void 0?"":d,s=o.addNewProfileDescription,m=s===void 0?"Create an organization and invite multiple members to manage and collaborate.":s,a=o.submitLabel,f=a===void 0?"Create Organization":a,u=o.onClose,O=o.open,_=o.setOpen,M=o.userId,t=oe({mode:"onChange",defaultValues:{name:"",urlPath:""},resolver:q(w)}),T=I(),C=$(T,2),N=C[0],g=C[1],h=function(){_(!1),t.reset(),u?.()},k=function(P){if(!g){D+=1;var B=D.toString(),F=re.getConnectionID(M,"ProfilesListFragment_profiles");N({variables:{input:{name:P.name,urlPath:P.urlPath,clientMutationId:B},connections:[F]},onCompleted:function(b,z){var y;if(z){console.error(z);return}var p=b==null||(y=b.organizationCreate)===null||y===void 0?void 0:y.errors;W(t,p),p!=null&&p.length||h()},onError:console.error})}};return l(K,{open:O,onClose:h,"aria-labelledby":"organization-modal-title","aria-describedby":"organization-modal-description",PaperProps:{sx:{borderRadius:{xs:0,sm:2},minWidth:{xs:"100%",sm:0},margin:{xs:0,sm:2},maxWidth:{sm:366},height:{xs:"100%",sm:"auto"},minHeight:{xs:"100%",sm:"auto"}}},children:[n(Y,{id:"organization-modal-title",children:l(j,{sx:{display:"flex",alignItems:"center",gap:2,justifyContent:"space-between"},children:[n(v,{variant:"h6",children:i}),n(Z,{onClick:h,children:n(H,{})})]})}),l(A,{onSubmit:t.handleSubmit(k),children:[l(X,{sx:{display:"flex",flexDirection:"column",gap:4},id:"organization-modal-description",children:[n(v,{color:"text.secondary",children:m}),l(j,{display:"flex",flexDirection:"column",gap:2,children:[n(S,{label:"Name",name:"name",size:"medium",control:t.control,onBlur:function(){t.getValues("urlPath")||(t.setValue("urlPath",te(t.getValues("name").toLocaleLowerCase())),t.trigger("urlPath"))}}),n(S,{label:"URL Path",name:"urlPath",size:"medium",control:t.control}),l(v,{color:"text.primary",children:["Upon confirming, you agree to our"," ",n(ee,{display:"inline",href:c,target:"_blank",children:"Terms and Conditions."})]})]})]}),l(Q,{sx:{justifyContent:"flex-end"},children:[n(J,{variant:"outlined",color:"inherit",onClick:h,sx:{width:"auto"},children:"Cancel"}),n(G,{variant:"contained",color:"inherit",sx:{width:"auto"},type:"submit",loading:g,disabled:g||Object.keys(t.formState.errors).length>0||!t.formState.isValid,children:f})]})]})]})},ve=ne;export{ve as a};
//# sourceMappingURL=chunk-SNEI432X.mjs.map