import{aj as g,aC as C,c6 as P,bw as T,aD as I,c as R,aL as O,az as B,aA as N,bk as _,r as v,s as h,j as e,m as F,aG as n,c1 as V,B as o,aM as U,b8 as $,e as x,bS as w,Q as G,b9 as K,bK as Y,cU as H,af as J,ag as L,bE as M}from"./index-dP1W1_bd.js";import{s as Q}from"./scope.selectors-C6FB6Cbj.js";const W=g().shape({name:C.label("Name"),scope:P().required()}),q=["FEATURESTORE","PROJECT","JOB","DATASET_CREATE","KAFKA","DATASET_VIEW","SERVING","DATASET_DELETE","MODELREGISTRY","USER","PYTHON_LIBRARIES"],X=({isEdit:r=!1,isLoading:l,initialData:s,onSubmit:j})=>{const t=T(),d=I(),[b,c]=R(),p=O(Q),{control:m,handleSubmit:k,formState:{errors:A},register:f}=B({defaultValues:{name:s==null?void 0:s.name,scope:(s==null?void 0:s.scope)||q},resolver:N(W),shouldUnregister:!1}),u=_({name:"scope",control:m}),y=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(F,{actions:e.jsx(n,{mr:"-15px",href:V("/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(U,{...f("name"),label:"Name",readOnly:r,disabled:l,placeholder:"name of the API key",...$("name",A)}),r&&!!(s!=null&&s.prefix)&&e.jsxs(x,{mt:"25px",ml:"20px",children:[e.jsx(w,{mb:"3px",gray:!0,children:"API key prefix"}),e.jsx(G,{primary:!0,children:s.prefix})]})]}),e.jsx(K,{name:"scope",control:m,render:({field:{onChange:a,value:E}})=>e.jsxs(x,{mt:"20px",children:[e.jsx(Y,{children:"Scope"}),y?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:E,options:p,onChange:a,tooltipProps:{disabled:!0}})]})}),!r&&e.jsx(x,{mt:"20px",children:e.jsx(J,{type:L.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:k(j),children:r?"Save":"Create API key"})]})]})}),r&&e.jsx(M,{title:`Delete ${s==null?void 0:s.name}`,secondaryButtonProps:{children:"Back",onClick:c},isOpen:b,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{X as A};
