import{ae as E,ax as P,bH as T,b4 as C,bf as I,w as O,bh as R,au as $,av as v,aO as F,r as V,q as h,j as e,Q as _,b6 as n,b$ as B,d as o,aR as N,aE as w,c as x,br as G,p as J,aF as Y,aV as q,cv as H,aa as K,ab as Q,be as U}from"./index-CK33qGU_.js";import{s as W}from"./scope.selectors-C6FB6Cbj.js";const M=E().shape({name:P.label("Name"),scope:T().required()}),z=["FEATURESTORE","PROJECT","JOB","DATASET_CREATE","KAFKA","DATASET_VIEW","SERVING","DATASET_DELETE","MODELREGISTRY"],Z=({isEdit:r=!1,isLoading:l,initialData:s,onSubmit:b})=>{const t=C(),d=I(),[j,c]=O(),p=R(W),{control:m,handleSubmit:f,formState:{errors:k},register:y}=$({defaultValues:{name:s==null?void 0:s.name,scope:(s==null?void 0:s.scope)||z},resolver:v(M),shouldUnregister:!1}),u=F({name:"scope",control:m}),A=p.length===u.length,S=V.useCallback(async()=>{s!=null&&s.name&&(await d.api.delete(s.name),c(),t(h.account.api.list))},[d.api,c,s,t]);return e.jsxs(e.Fragment,{children:[e.jsx(_,{actions:e.jsx(n,{mr:"-15px",href:B("/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(o,{flexDirection:"column",children:[e.jsxs(o,{children:[e.jsx(N,{...y("name"),label:"Name",readOnly:r,disabled:l,placeholder:"name of the API key",...w("name",k)}),r&&!!(s!=null&&s.prefix)&&e.jsxs(x,{mt:"25px",ml:"20px",children:[e.jsx(G,{mb:"3px",gray:!0,children:"API key prefix"}),e.jsx(J,{primary:!0,children:s.prefix})]})]}),e.jsx(Y,{name:"scope",control:m,render:({field:{onChange:a,value:g}})=>e.jsxs(x,{mt:"20px",children:[e.jsx(q,{children:"Scope"}),A?e.jsx(n,{mb:"8px",ml:"-16px",intent:"inline",alignSelf:"flex-start",onClick:()=>a([]),children:"unselect all"}):e.jsx(n,{mb:"8px",ml:"-16px",intent:"inline",alignSelf:"flex-start",onClick:()=>a(p),children:"select all"}),e.jsx(H,{label:"",value:g,options:p,onChange:a,tooltipProps:{disabled:!0}})]})}),!r&&e.jsx(x,{mt:"20px",children:e.jsx(K,{type:Q.neutral,content:"You can edit scope later"})}),r&&e.jsx(o,{mt:"20px",children:e.jsx(n,{intent:"alert",onClick:c,disabled:l,children:"Delete API key"})}),e.jsxs(o,{mt:"20px",justifyContent:"flex-end",children:[e.jsx(n,{mr:"20px",type:"button",disabled:l,intent:"secondary",onClick:()=>t(h.account.api.list),children:"Back"}),e.jsx(n,{disabled:l||u.length===0,intent:"primary",onClick:f(b),children:r?"Save":"Create API key"})]})]})}),r&&e.jsx(U,{title:`Delete ${s==null?void 0:s.name}`,secondaryButtonProps:{children:"Back",onClick:c},isOpen:j,onClose:c,mainButtonProps:{children:"Delete API key",onClick:S},secondaryText:"Once you delete an API key, there is no going back. Please be certain."})]})};export{Z as A};
