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