import{o as ae,n as ce,h as le,as as pe,ic as ie,r as p,aR as me,u as de,gy as ue,id as xe,ie as he,aE as ge,am as fe,an as je,W as ye,cT as be,aQ as Ce,j as e,K as Se,a as h,a3 as Te,a4 as ke,O as S,be as B,f as G,aG as M,ae as Q,aO as Oe,af as we,Z as Ie,ax as q,b3 as A,ay as ve,aH as Ne,ct as T,fq as k,aT as g,a_ as Pe,aS as Fe,g as Re,e as H,c as K,a7 as Ve,ck as _e,ai as ze}from"./index-d6499a22.js";import{g as $e}from"./Project-92985c5d.js";import{b as Be,p as Ge,d as Me,D as U,e as Qe,f as qe,g as Ae,a as He,c as W}from"./utils-2832fe88.js";import{z as Ke}from"./zipObj-e651182a.js";var Ue=ae(function(s){return ce(s.length,function(t,l){var i=Array.prototype.slice.call(arguments,0);return i[0]=l,i[1]=t,s.apply(this,i)})}),We=le(function(r,s){return pe(Ue(ie)(r),s)});const Ze=We,Ye={"> label":{mt:"20px","&:first-of-type":{mt:0}}},De=(r,s)=>Ve().shape({description:_e.label("Description"),name:ze.notOneOf(r,"This name is already in use").label("Name").when("description",{is:t=>s,then:t=>t.notRequired(),otherwise:t=>t.required()})}),Je=({error:r,initialProtocol:s=k.aws,isLoading:t,isDisabled:l,onSubmit:i,onDelete:O,isEdit:o,initialData:n})=>{const Z=me(),{id:m,fsId:d}=de(),{currentData:w}=ue({pId:+m,fsId:+d}),{currentData:f,isLoading:Y}=xe({pId:+m,fsId:+d}),[I,{data:j,isLoading:D}]=he(),y=p.useCallback(c=>Be(De(Ze([(n==null?void 0:n.name)||""],ge("name",w??[])),o))(c),[n==null?void 0:n.name,w,o]),[J,L]=p.useState(y(s)),v=p.useMemo(()=>f?Ge.concat(Me.filter(c=>f.includes(c.key))):[],[f]),{control:N,formState:{errors:u},register:b,setValue:X,clearErrors:P,handleSubmit:E,reset:ee,watch:te,getValues:F}=fe({defaultValues:{storageConnectorType:s,...n},shouldUnregister:!1,resolver:je(J)});let R="";const x=Object.keys(u).length;x>0&&(R=x===1?`${x.toString()} error`:`${x.toString()} errors`);const[V,se,a,..._]=te(["name","description","storageConnectorType",...U]),oe=p.useMemo(()=>Qe(Ke(U,_),a),[_,a]),re=p.useMemo(()=>qe(a),[a]);p.useEffect(()=>{L(y(a))},[a,y]);const ne=p.useCallback(()=>{const c=F(),C=ye(be("type",He(c.storageConnectorType)),Ae(c.storageConnectorType))(c);I({pId:+m,fsId:+d,data:C})},[I,m,d,F]),z=Ce();return e.jsxs("form",{autoComplete:"off",onSubmit:E(i),children:[e.jsxs(Se,{title:o?"Edit storage connector":"Set up storage connector",contentProps:{overflow:"visible"},mb:"100px",pb:z?"75px":0,children:[e.jsxs(h,{sx:Ye,flexDirection:"column",children:[r&&e.jsx(Te,{type:ke.error,content:"Can’t connect to the server. Check your URL and credentials."}),o&&!!n&&e.jsxs(h,{children:[e.jsxs(S,{mr:"20px",children:[e.jsx(B,{gray:!0,children:"Name"}),e.jsx(G,{mt:"4px",primary:!0,children:n.name})]}),e.jsxs(S,{children:[e.jsx(B,{gray:!0,children:"Protocol"}),e.jsx(G,{mt:"4px",primary:!0,children:$e(v,s)})]})]}),e.jsxs(h,{mb:"20px",children:[!o&&e.jsx(M,{label:"Name",...b("name"),disabled:t||l,placeholder:"name of the source",labelAction:e.jsx(Q,{position:Oe.right,mainText:"Only alphanumeric characters, dash or underscore",children:e.jsx(we,{ml:"5px",mt:"-1px",size:"sm",icon:Ie.info_block})}),...q("name",u)}),e.jsx(M,{labelProps:{flexGrow:1,mt:o?"20px":0,marginLeft:o?0:"20px"},label:"Description",...b("description"),optional:!0,disabled:t||l,placeholder:"description",...q("description",u)})]}),!o&&e.jsxs(S,{children:[e.jsx(A,{mt:0,mb:"8px",children:"Protocol"}),e.jsx(ve,{control:N,name:"storageConnectorType",render:({field:{onChange:c,value:C}})=>e.jsx(Ne,{flexDirection:"row",mr:"30px",disabled:o||t||Y,value:C,options:v,onChange:$=>{ee({name:V,description:se,storageConnectorType:$}),P(),c($)}})})]}),e.jsx(T,{mt:o?"0":"20px",legend:"Parameters"}),e.jsx(re,{setValue:X,errors:u,register:b,control:N,isDisabled:t||l,clearErrors:P},"form"),e.jsx(T,{mb:"10px",legend:"Quick test connection"}),e.jsxs(h,{sx:{gap:"20px"},flexDirection:"row",alignItems:"center",children:[e.jsx(Q,{mainText:`Not yet supported for ${a}`,disabled:a===k.snowflake,children:e.jsx(g,{width:"fit-content",intent:"secondary",disabled:t||l||a!==k.snowflake,onClick:ne,isLoading:D,type:"button",children:"Test connection"})}),e.jsx(A,{children:j&&e.jsx(Le,{connectionOutput:j.connectionOutput,statusCode:j.statusCode})})]}),o&&O&&e.jsxs(e.Fragment,{children:[e.jsx(T,{legend:"Danger zone"}),e.jsx(g,{width:"fit-content",intent:"alert",disabled:t||l,onClick:O,type:"button",children:"Delete the storage connector"})]})]}),t&&e.jsx(Pe,{})]}),e.jsx(Fe,{title:W(V,24),firstValue:W(oe,50),errorsValue:R,mainButton:e.jsx(g,{disabled:t||l,intent:"primary",type:"submit",children:o?"Save":"Setup storage connector"}),secondaryButton:e.jsx(g,{type:"button",disabled:t,intent:"secondary",onClick:()=>Z(Re(H.storageConnector.list,H.project.value,{id:m,fsId:d})),children:"Back"}),hasScrollOnScreen:z})]})},st=p.memo(Je),Le=({connectionOutput:r,statusCode:s})=>s!==0?e.jsxs(K,{color:"red",children:[e.jsx("b",{children:"Connection Failure"})," ",e.jsx("br",{})," ",r]}):e.jsx(K,{color:"green",children:e.jsx("b",{children:r})});export{st as S};
