import{bg as E,bo as T,bI as P,y as C,bJ as O,aC as R,aD as B,ar as _,bc as i,r as N,t as b,j as e,W as $,a as t,aH as F,aY as J,L as x,bV as V,f as v,aZ as G,bG as U,aJ as c,df as W,a3 as Y,a5 as H,c5 as L,bA as w,cb as K,aE as q}from"./index-_eM6l4Nf.js";import{s as M}from"./scope.selectors-C6FB6Cbj.js";const X=_().shape({name:q.label("Name"),scope:K().required()}),Z=["FEATURESTORE","PROJECT","JOB","DATASET_CREATE","KAFKA","DATASET_VIEW","SERVING","DATASET_DELETE","MODELREGISTRY","USER","PYTHON_LIBRARIES"],D=({isEdit:r=!1,isLoading:l,initialData:s,onSubmit:j})=>{const{state:n}=E(),p=T(),m=P(),[f,o]=C(),a=O(M),{control:u,handleSubmit:y,formState:{errors:A},register:k}=R({defaultValues:{name:s==null?void 0:s.name,scope:(n==null?void 0:n.initialScope)??(s==null?void 0:s.scope)??Z},resolver:B(X),shouldUnregister:!1}),h=i({name:"scope",control:u}),S=a.length===h.length,I=N.useCallback(async()=>{s!=null&&s.name&&(await m.api.delete(s.name),o(),p(b.account.api.list))},[m.api,o,s,p]);return e.jsxs(e.Fragment,{children:[e.jsx($,{actions:e.jsx(c,{mr:"-15px",href:L("/user_guides/integrations/databricks/api_key/"),external:!0,target:"_blank",intent:"inline",children:"documentation ↗"}),title:r?"Edit API key":"Create new API key",children:e.jsxs(t,{flexDirection:"column",children:[e.jsxs(t,{children:[e.jsx(F,{...k("name"),label:"Name",readOnly:r,disabled:l,placeholder:"name of the API key",...J("name",A)}),r&&!!(s!=null&&s.prefix)&&e.jsxs(x,{mt:"25px",ml:"20px",children:[e.jsx(V,{mb:"3px",gray:!0,children:"API key prefix"}),e.jsx(v,{primary:!0,children:s.prefix})]})]}),e.jsx(G,{name:"scope",control:u,render:({field:{onChange:d,value:g}})=>e.jsxs(x,{mt:"20px",children:[e.jsx(U,{children:"Scope"}),S?e.jsx(c,{mb:"8px",ml:"-16px",intent:"inline",alignSelf:"flex-start",onClick:()=>d([]),children:"unselect all"}):e.jsx(c,{mb:"8px",ml:"-16px",intent:"inline",alignSelf:"flex-start",onClick:()=>d(a),children:"select all"}),e.jsx(W,{label:"",value:g,options:a,onChange:d,tooltipProps:{disabled:!0}})]})}),!r&&e.jsx(x,{mt:"20px",children:e.jsx(Y,{type:H.neutral,content:"You can edit scope later"})}),r&&e.jsx(t,{mt:"20px",children:e.jsx(c,{intent:"alert",onClick:o,disabled:l,children:"Delete API key"})}),e.jsxs(t,{mt:"20px",justifyContent:"flex-end",children:[e.jsx(c,{mr:"20px",type:"button",disabled:l,intent:"secondary",onClick:()=>p((n==null?void 0:n.redirectUrl)??b.account.api.list),children:"Back"}),e.jsx(c,{disabled:l||h.length===0,intent:"primary",onClick:y(j),children:r?"Save":"Create API key"})]})]})}),r&&e.jsx(w,{title:`Delete ${s==null?void 0:s.name}`,secondaryButtonProps:{children:"Back",onClick:o},isOpen:f,onClose:o,mainButtonProps:{children:"Delete API key",onClick:I},secondaryText:"Once you delete an API key, there is no going back. Please be certain."})]})};export{D as A};
