import{bg as I,bo as P,bI as T,y as C,bJ as O,aC as R,aD as N,ar as _,bc as $,r as i,q as b,j as e,b as B,$ as t,b2 as F,aN as V,L as a,bV as v,f as G,aO as J,bG as U,b1 as c,df as L,a3 as Y,a5 as q,c5 as w,bA as H,cb as K,aE as W}from"./index-Cc-6WbPt.js";import{s as M}from"./scope.selectors-C6FB6Cbj.js";const X=_().shape({name:W.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}=I(),p=P(),m=T(),[f,o]=C(),d=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:N(X),shouldUnregister:!1}),h=$({name:"scope",control:u}),S=d.length===h.length,g=i.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(B,{actions:e.jsx(c,{mr:"-15px",href:w("/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",...V("name",A)}),r&&!!(s!=null&&s.prefix)&&e.jsxs(a,{mt:"25px",ml:"20px",children:[e.jsx(v,{mb:"3px",gray:!0,children:"API key prefix"}),e.jsx(G,{primary:!0,children:s.prefix})]})]}),e.jsx(J,{name:"scope",control:u,render:({field:{onChange:x,value:E}})=>e.jsxs(a,{mt:"20px",children:[e.jsx(U,{children:"Scope"}),S?e.jsx(c,{mb:"8px",ml:"-16px",intent:"inline",alignSelf:"flex-start",onClick:()=>x([]),children:"unselect all"}):e.jsx(c,{mb:"8px",ml:"-16px",intent:"inline",alignSelf:"flex-start",onClick:()=>x(d),children:"select all"}),e.jsx(L,{label:"",value:E,options:d,onChange:x,tooltipProps:{disabled:!0}})]})}),!r&&e.jsx(a,{mt:"20px",children:e.jsx(Y,{type:q.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(H,{title:`Delete ${s==null?void 0:s.name}`,secondaryButtonProps:{children:"Back",onClick:o},isOpen:f,onClose:o,mainButtonProps:{children:"Delete API key",onClick:g},secondaryText:"Once you delete an API key, there is no going back. Please be certain."})]})};export{D as A};
