import{bp as E,bx as I,bW as T,w as C,bX as R,aA as O,aB as F,bd as _,r as B,x as j,j as e,f as N,q as t,aH as i,aY as v,F as a,c7 as w,d as J,aZ as U,bl as V,aJ as c,ds as Y,a4 as $,a5 as q,ci as H,bJ as W,Z as G,co as K,dt as M}from"./index-Cox3ZWL0.js";import{s as Z}from"./scope.selectors-C6FB6Cbj.js";const z=G().shape({name:M.label("Name"),scope:K().required()}),L=["FEATURESTORE","PROJECT","JOB","DATASET_CREATE","KAFKA","DATASET_VIEW","SERVING","DATASET_DELETE","MODELREGISTRY","USER","PYTHON_LIBRARIES"],D=({isEdit:n=!1,isLoading:l,initialData:s,onSubmit:b})=>{const{state:r}=E(),p=I(),m=T(),[A,o]=C(),d=R(Z),{control:u,handleSubmit:f,formState:{errors:k},register:y}=O({defaultValues:{name:s==null?void 0:s.name,scope:(r==null?void 0:r.initialScope)??(s==null?void 0:s.scope)??L},resolver:F(z),shouldUnregister:!1}),h=_({name:"scope",control:u}),S=d.length===h.length,P=B.useCallback(async()=>{s!=null&&s.name&&(await m.api.delete(s.name),o(),p(j.account.api.list))},[m.api,o,s,p]);return e.jsxs(e.Fragment,{children:[e.jsx(N,{actions:e.jsx(c,{mr:"-15px",href:H("/user_guides/integrations/databricks/api_key/"),external:!0,target:"_blank",intent:"inline",children:"documentation ↗"}),title:n?"Edit API key":"Create new API key",children:e.jsxs(t,{flexDirection:"column",children:[e.jsxs(t,{children:[e.jsx(i,{...y("name"),label:"Name",readOnly:n,disabled:l,placeholder:"name of the API key",...v("name",k)}),n&&!!(s!=null&&s.prefix)&&e.jsxs(a,{mt:"25px",ml:"20px",children:[e.jsx(w,{mb:"3px",gray:!0,children:"API key prefix"}),e.jsx(J,{primary:!0,children:s.prefix})]})]}),e.jsx(U,{name:"scope",control:u,render:({field:{onChange:x,value:g}})=>e.jsxs(a,{mt:"20px",children:[e.jsx(V,{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(Y,{label:"",value:g,options:d,onChange:x,tooltipProps:{disabled:!0}})]})}),!n&&e.jsx(a,{mt:"20px",children:e.jsx($,{type:q.neutral,content:"You can edit scope later"})}),n&&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((r==null?void 0:r.redirectUrl)??j.account.api.list),children:"Back"}),e.jsx(c,{disabled:l||h.length===0,intent:"primary",onClick:f(b),children:n?"Save":"Create API key"})]})]})}),n&&e.jsx(W,{title:`Delete ${s==null?void 0:s.name}`,secondaryButtonProps:{children:"Back",onClick:o},isOpen:A,onClose:o,mainButtonProps:{children:"Delete API key",onClick:P},secondaryText:"Once you delete an API key, there is no going back. Please be certain."})]})};export{D as A};
