import{a7 as P,ai as T,aR as C,b0 as E,l as I,b2 as O,am as R,an as F,aF as _,r as B,e as u,j as e,K as N,aT as r,ci as V,a as l,aG as v,ax as K,O as x,be as U,f as w,ay as G,b3 as Y,cP as i,a3 as J,a4 as W,a$ as $}from"./index-d6499a22.js";import{s as M}from"./scope.selectors-1aab3a9c.js";const q=P().shape({name:T.label("Name")}),z=["FEATURESTORE","PROJECT","JOB","DATASET_CREATE","KAFKA","DATASET_VIEW","SERVING","DATASET_DELETE","MODELREGISTRY"],Q=({isEdit:n=!1,isLoading:o,initialData:s,onSubmit:f})=>{const t=C(),d=E(),[j,c]=I(),p=O(M),{control:m,handleSubmit:k,formState:{errors:b},register:y}=R({defaultValues:{name:s==null?void 0:s.name,scope:(s==null?void 0:s.scope)||z},resolver:F(q),shouldUnregister:!1}),h=_({name:"scope",control:m}),A=p.length===h.length,S=B.useCallback(async()=>{s!=null&&s.name&&(await d.api.delete(s.name),c(),t(u.account.api.list))},[d.api,c,s,t]);return e.jsxs(e.Fragment,{children:[e.jsx(N,{actions:e.jsx(r,{mr:"-15px",href:"https://docs.hopsworks.ai/".concat(V.docsVersion,"/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(l,{flexDirection:"column",children:[e.jsxs(l,{children:[e.jsx(v,{...y("name"),label:"Name",readOnly:n,disabled:o,placeholder:"name of the API key",...K("name",b)}),n&&!!(s!=null&&s.prefix)&&e.jsxs(x,{mt:"25px",ml:"20px",children:[e.jsx(U,{mb:"3px",gray:!0,children:"API key prefix"}),e.jsx(w,{primary:!0,children:s.prefix})]})]}),e.jsx(G,{name:"scope",control:m,render:({field:{onChange:a,value:g}})=>e.jsxs(x,{mt:"20px",children:[e.jsx(Y,{children:"Scope"}),A?e.jsx(r,{mb:"8px",ml:"-16px",intent:"inline",alignSelf:"flex-start",onClick:()=>a([]),children:"unselect all"}):e.jsx(r,{mb:"8px",ml:"-16px",intent:"inline",alignSelf:"flex-start",onClick:()=>a(p),children:"select all"}),e.jsx(i,{label:"",value:g,options:p,onChange:a,tooltipProps:{disabled:!0}})]})}),!n&&e.jsx(x,{mt:"20px",children:e.jsx(J,{type:W.neutral,content:"You can edit scope later"})}),n&&e.jsx(l,{mt:"20px",children:e.jsx(r,{intent:"alert",onClick:c,disabled:o,children:"Delete API key"})}),e.jsxs(l,{mt:"20px",justifyContent:"flex-end",children:[e.jsx(r,{mr:"20px",type:"button",disabled:o,intent:"secondary",onClick:()=>t(u.account.api.list),children:"Back"}),e.jsx(r,{disabled:o||h.length===0,intent:"primary",onClick:k(f),children:n?"Save":"Create API key"})]})]})}),n&&e.jsx($,{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{Q as A};
