import{a7 as P,aj as E,aS as T,b1 as C,P as I,b3 as O,an as R,ao as V,aG as _,r as B,b as u,j as e,E as F,aU as r,cj as N,Q as l,aH as v,ay as G,o as x,bf as w,g as U,az as J,b4 as K,cS as Q,a3 as W,a4 as Y,b0 as z}from"./index-ea7817a2.js";import{s as H}from"./scope.selectors-1aab3a9c.js";const M=P().shape({name:E.label("Name")}),$=["FEATURESTORE","PROJECT","JOB","DATASET_CREATE","KAFKA","DATASET_VIEW","SERVING","DATASET_DELETE","MODELREGISTRY"],X=({isEdit:n=!1,isLoading:o,initialData:s,onSubmit:j})=>{const t=T(),d=C(),[f,c]=I(),p=O(H),{control:m,handleSubmit:b,formState:{errors:k},register:y}=R({defaultValues:{name:s==null?void 0:s.name,scope:(s==null?void 0:s.scope)||$},resolver:V(M),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(F,{actions:e.jsx(r,{mr:"-15px",href:"https://docs.hopsworks.ai/".concat(N.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",...G("name",k)}),n&&!!(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(U,{primary:!0,children:s.prefix})]})]}),e.jsx(J,{name:"scope",control:m,render:({field:{onChange:a,value:g}})=>e.jsxs(x,{mt:"20px",children:[e.jsx(K,{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(Q,{label:"",value:g,options:p,onChange:a,tooltipProps:{disabled:!0}})]})}),!n&&e.jsx(x,{mt:"20px",children:e.jsx(W,{type:Y.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:b(j),children:n?"Save":"Create API key"})]})]})}),n&&e.jsx(z,{title:`Delete ${s==null?void 0:s.name}`,secondaryButtonProps:{children:"Back",onClick:c},isOpen:f,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};
