import{bg as I,bo as P,bH as T,y as C,bI 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 U,L as x,bU as v,f as V,aO as G,bF as H,b1 as c,de as J,a3 as L,a5 as Y,c4 as q,bz as w,ca as K,aE as W}from"./index-46ma1THH.js";import{s as z}from"./scope.selectors-C6FB6Cbj.js";const M=_().shape({name:W.label("Name"),scope:K().required()}),X=["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(),a=O(z),{control:u,handleSubmit:y,formState:{errors:k},register:A}=R({defaultValues:{name:s==null?void 0:s.name,scope:(n==null?void 0:n.initialScope)??(s==null?void 0:s.scope)??X},resolver:N(M),shouldUnregister:!1}),h=$({name:"scope",control:u}),S=a.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:q("/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,{...A("name"),label:"Name",readOnly:r,disabled:l,placeholder:"name of the API key",...U("name",k)}),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:E}})=>e.jsxs(x,{mt:"20px",children:[e.jsx(H,{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(J,{label:"",value:E,options:a,onChange:d,tooltipProps:{disabled:!0}})]})}),!r&&e.jsx(x,{mt:"20px",children:e.jsx(L,{type:Y.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:g},secondaryText:"Once you delete an API key, there is no going back. Please be certain."})]})};export{D as A};
