import{j as e,r as o}from"./vendor-react-wBh_31cN.js";import{j as b,u as C}from"./vendor-redux-CJZrIb6x.js";import{aq as E,G as S}from"./index-dNe6i2rS.js";import{C as P,a as A,b as F,c as T}from"./card-BeQtvmcJ.js";import{I as K}from"./input-DFI7JniT.js";import{L as y}from"./label-gPWmc6ow.js";import{V as h}from"./value-7N0Keti9.js";import{u as q}from"./useTitle-DQo_L6Ox.js";import{u as z}from"./useSortedProjects-DPrT0V3d.js";import{L as H}from"./login-card-BOJLXRQB.js";import{C as M}from"./combobox-QqI9aNup.js";import{c as V,u as Y,a as _}from"./vendor-router-D1GqFWiT.js";import"./vendor-utils-OeoE2qq_.js";import"./vendor-icons-BUUmD6ht.js";import"./vendor-radix-BRyWS4bQ.js";import"./vendor-grid-CeFlDWv4.js";import"./index-DURBtSjL.js";import"./apply-CIuXDHQi.js";import"./concat-CTXo1gGM.js";import"./sortBy-COer1Ia5.js";import"./juxt-B5kKHsyp.js";import"./converge-D7u3m7i4.js";import"./includes-ucXR_9jq.js";import"./Hero-ILcN0sPk.js";import"./theme-colors-BFneJNsI.js";import"./LoginHelp-B1LeTy5S.js";import"./getHopsDoc-B_Rq_F9V.js";import"./input-group-gxy3DSmS.js";import"./textarea-BJVuSob1.js";import"./vendor-recharts-DmJlpLaF.js";const R=({projects:s,selectedProject:r,onChange:p})=>{const i=s.map(n=>({value:n.name,label:n.name}));return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx(y,{children:"Project"}),e.jsx(M,{options:i,value:r,onChange:n=>{n&&p(n)},placeholder:"Select a project..."})]})},B=/^[a-zA-Z0-9_-]{1,45}$/,Ne=()=>{q("Complete CLI Setup");const{flowId:s}=V(),r=b(),p=Y(),i=_(),{completed:n,error:N,suggestedKeyName:l}=C(t=>t.tokenFlow),{token:x}=C(t=>t.auth),{data:w,isLoading:L}=z({skip:!x}),c=o.useMemo(()=>(w||[]).map(t=>({id:t.projectId,name:t.projectName})),[w]),[a,j]=o.useState(null),[d,g]=o.useState(""),k=C(t=>{var f;return(f=t.loading.effects.tokenFlow)==null?void 0:f.complete});o.useEffect(()=>{r.tokenFlow.reset(),g(""),j(null)},[r,s]),o.useEffect(()=>{s&&l===null&&r.tokenFlow.fetchInfo(s)},[r,s,l]),o.useEffect(()=>{l&&!d&&g(l)},[l,d]),o.useEffect(()=>{c&&c.length>0&&!a&&j(c[0].name)},[c,a]),o.useEffect(()=>{if(!x){const t=i.pathname+i.search;p("/login",{state:t})}},[x,p,i.pathname,i.search]);const m=d.trim(),u=o.useMemo(()=>m===""||B.test(m),[m]),v=o.useCallback(async()=>{if(!s||!a||!u)return;const t=c.find(f=>f.name===a);if(t)try{await r.tokenFlow.complete({flowId:s,projectId:t.id,projectName:t.name,keyName:m||void 0})}catch{}},[r,s,a,c,m,u]),I=N?{error:!0,status:0,message:N.message}:null;return L?e.jsx("div",{className:"flex h-screen items-center justify-center",children:e.jsx(E,{})}):e.jsx(H,{loginHelp:!1,register:!1,login:!1,error:I,children:e.jsx("div",{className:"flex flex-col gap-5",children:e.jsxs(P,{className:"w-[466px]",children:[e.jsx(A,{children:e.jsx(F,{children:"Complete CLI Setup"})}),e.jsx(T,{children:n?e.jsxs("div",{className:"flex flex-col gap-4 items-center",children:[e.jsx(h,{primary:!0,className:"text-lg font-bold text-quartz-label-green",children:"✓ Authentication Successful!"}),e.jsxs(h,{children:["Your CLI has been authenticated with project:"," ",a]}),e.jsx(h,{className:"text-quartz-gray",children:"You can now close this window and return to the CLI."})]}):e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsx(h,{children:"Select a project to use with the Hopsworks CLI:"}),e.jsx(R,{projects:c,selectedProject:a,onChange:j}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(y,{children:"API key name"}),e.jsx(K,{value:d,onChange:t=>g(t.target.value),placeholder:"e.g. dowling-laptop"}),!u&&e.jsx("span",{className:"text-xs text-destructive",children:"Use letters, digits, underscore, or hyphen (1–45 chars)."})]}),e.jsx(S,{type:"button",onClick:v,disabled:!a||!u||k,loading:k,children:"Complete Authentication"})]})})]})})})};export{Ne as default};
