import{al as E,aG as P,cd as I,bp as T,bI as C,w as R,bK as O,aD as B,aE as $,bc as V,r as _,s as h,j as e,y as w,b4 as n,c5 as F,B as o,b5 as G,aR as N,d,bV as v,b as J,aS as K,bG as U,c$ as H,ah as W,ai as Y,bA as q}from"./index-C1DmWO_C.js";import{s as M}from"./scope.selectors-C6FB6Cbj.js";const i=E().shape({name:P.label("Name"),scope:I().required()}),z=["FEATURESTORE","PROJECT","JOB","DATASET_CREATE","KAFKA","DATASET_VIEW","SERVING","DATASET_DELETE","MODELREGISTRY","USER"],Z=({isEdit:r=!1,isLoading:l,initialData:s,onSubmit:b})=>{const t=T(),x=C(),[j,c]=R(),p=O(M),{control:m,handleSubmit:y,formState:{errors:f},register:k}=B({defaultValues:{name:s==null?void 0:s.name,scope:(s==null?void 0:s.scope)||z},resolver:$(i),shouldUnregister:!1}),u=V({name:"scope",control:m}),A=p.length===u.length,S=_.useCallback(async()=>{s!=null&&s.name&&(await x.api.delete(s.name),c(),t(h.account.api.list))},[x.api,c,s,t]);return e.jsxs(e.Fragment,{children:[e.jsx(w,{actions:e.jsx(n,{mr:"-15px",href:F("/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(G,{...k("name"),label:"Name",readOnly:r,disabled:l,placeholder:"name of the API key",...N("name",f)}),r&&!!(s!=null&&s.prefix)&&e.jsxs(d,{mt:"25px",ml:"20px",children:[e.jsx(v,{mb:"3px",gray:!0,children:"API key prefix"}),e.jsx(J,{primary:!0,children:s.prefix})]})]}),e.jsx(K,{name:"scope",control:m,render:({field:{onChange:a,value:g}})=>e.jsxs(d,{mt:"20px",children:[e.jsx(U,{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(d,{mt:"20px",children:e.jsx(W,{type:Y.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:y(b),children:r?"Save":"Create API key"})]})]})}),r&&e.jsx(q,{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};
