1import{a as e,j as s}from"./query-vendor-DZMRrbMU.js";import{s as n,G as t,e as a}from"./firebase-vendor-CX_xv3XA.js";import{H as i,C as r,g as c,h as l,i as o,d,c as x,am as h,an as m,ao as u}from"./index-Ww_mg2y_.js";import{ac as j,f as p,ab as f,q as g}from"./icon-vendor-BVA9AJ-N.js";import"./ui-vendor-BNlO3lKu.js";import"./form-vendor-BbpM4sBQ.js";import"./date-vendor-CXQvy03X.js";function y(){const[y,w]=e.useState("ready"),[v,b]=e.useState(null),[N,C]=e.useState(""),[k,M]=e.useState(""),S=new URLSearchParams(window.location.search),A=S.get("flow"),T=S.get("port"),F=S.get("sessionId"),H=S.get("txn"),z=T?parseInt(T,10):NaN,q=!isNaN(z)&&z>=1024&&z<=65535&&String(z)===T?z:null,I=async()=>{if(q&&F){w("signing-in"),b(null);try{const e=await n(h,m),s=t.credentialFromResult(e);if(!(null==s?void 0:s.idToken))throw new Error("Failed to get Google credential");const a=new URL(`http://localhost:${q}/auth-callback`),i="localhost"===a.hostname||"127.0.0.1"===a.hostname,r=Number(a.port),c=Number.isInteger(r)&&r>=1024&&r<=65535;if("http:"!==a.protocol||!i||!c)throw new Error("Invalid desktop callback target; refusing to send credentials.");w("sending");const l=await fetch(a.toString(),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:F,googleIdToken:s.idToken,googleAccessToken:s.accessToken})});if(!l.ok){const e=await l.json().catch(()=>({}));throw new Error(e.error||"Failed to connect to desktop app")}w("success")}catch(e){if("auth/popup-closed-by-user"===e.code||"auth/cancelled-popup-request"===e.code)return void w("ready");b(e.message||"An error occurred"),w("error")}}},B=async e=>{if(H){w("signing-in"),b(null);try{const s=await e();await(async e=>{const s=await e.getIdToken(),n=e.refreshToken;try{await fetch("/api/auth/register",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:"{}"})}catch(i){}w("sending");const t=await fetch("https://mcp.hobbymonitor.com/callback/firebase",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({txn:H,firebaseIdToken:s,firebaseRefreshToken:n})});if(!t.ok){const e=await t.json().catch(()=>({}));throw new Error(e.error||"Failed to complete connection")}const{redirectTo:a}=await t.json();if(!a)throw new Error("No redirect returned");w("success"),window.location.href=a})(s.user)}catch(s){if("auth/popup-closed-by-user"===s.code||"auth/cancelled-popup-request"===s.code)return void w("ready");b(s.message||"An error occurred"),w("error")}}},E=()=>B(()=>n(h,m)),P=()=>B(()=>n(h,u)),R=e=>{e.preventDefault(),B(()=>a(h,N,k))};if(!A)return s.jsxs(s.Fragment,{children:[s.jsxs(i,{children:[s.jsx("title",{children:"Connect - HobbyMonitor"}),s.jsx("meta",{name:"robots",content:"noindex"})]}),s.jsx("div",{className:"container py-12 flex flex-col items-center justify-center min-h-[75vh]",children:s.jsx(r,{className:"w-full max-w-md",children:s.jsxs(c,{children:[s.jsxs("div",{className:"flex items-center gap-2 text-destructive",children:[s.jsx(j,{className:"h-5 w-5"}),s.jsx(l,{children:"Invalid Request"})]}),s.jsx(o,{children:"This page is used to connect external apps to your HobbyMonitor account. Please open it from the app you want to connect."})]})})})]});if("desktop"===A){return q&&F?s.jsxs(s.Fragment,{children:[s.jsxs(i,{children:[s.jsx("title",{children:"Connect Desktop Scanner - HobbyMonitor"}),s.jsx("meta",{name:"robots",content:"noindex"})]}),s.jsx("div",{className:"container py-12 flex flex-col items-center justify-center min-h-[75vh]",children:s.jsxs(r,{className:"w-full max-w-md",children:[s.jsxs(c,{className:"text-center",children:[s.jsx("div",{className:"flex justify-center mb-4",children:s.jsx("div",{className:"w-16 h-16 bg-primary/10 rounded-full flex items-center justify-center",children:s.jsx(p,{className:"h-8 w-8 text-primary"})})}),s.jsx(l,{children:"success"===y?"Connected!":"Connect Desktop Scanner"}),s.jsx(o,{children:"success"===y?"You can close this tab and return to the app.":"Sign in with Google to connect the HobbyMonitor desktop scanner."})]}),s.jsx(d,{className:"space-y-4",children:"success"===y?s.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[s.jsx(f,{className:"h-12 w-12 text-green-600"}),s.jsx("p",{className:"text-sm text-muted-foreground text-center",children:"Your desktop app is now signed in."})]}):"error"===y?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{className:"bg-destructive/10 text-destructive text-sm p-3 rounded-md",children:v}),s.jsx(x,{className:"w-full",variant:"outline",onClick:()=>{w("ready"),b(null)},children:"Try Again"})]}):s.jsx(x,{className:"w-full",onClick:I,disabled:"ready"!==y,children:"signing-in"===y?s.jsxs(s.Fragment,{children:[s.jsx(g,{className:"h-4 w-4 animate-spin"})," Signing in..."]}):"sending"===y?s.jsxs(s.Fragment,{children:[s.jsx(g,{className:"h-4 w-4 animate-spin"})," Connecting to app..."]}):s.jsxs(s.Fragment,{children:[s.jsxs("svg",{className:"h-4 w-4",viewBox:"0 0 18 18",fill:"none",children:[s.jsx("path",{d:"M17.64 9.205c0-.639-.057-1.252-.164-1.841H9v3.481h4.844a4.14 4.14 0 01-1.796 2.716v2.259h2.908c1.702-1.567 2.684-3.875 2.684-6.615z",fill:"#4285F4"}),s.jsx("path",{d:"M9 18c2.43 0 4.467-.806 5.956-2.18l-2.908-2.259c-.806.54-1.837.86-3.048.86-2.344 0-4.328-1.584-5.036-3.711H.957v2.332A8.997 8.997 0 009 18z",fill:"#34A853"}),s.jsx("path",{d:"M3.964 10.71A5.41 5.41 0 013.682 9c0-.593.102-1.17.282-1.71V4.958H.957A8.997 8.997 0 000 9c0 1.452.348 2.827.957 4.042l3.007-2.332z",fill:"#FBBC05"}),s.jsx("path",{d:"M9 3.58c1.321 0 2.508.454 3.44 1.345l2.582-2.58C13.463.891 11.426 0 9 0A8.997 8.997 0 00.95
17 4.958L3.964 6.29C4.672 4.163 6.656 2.58 9 2.58z",fill:"#EA4335"})]}),"Sign in with Google"]})})})]})})]}):s.jsxs(s.Fragment,{children:[s.jsxs(i,{children:[s.jsx("title",{children:"Connect Desktop - HobbyMonitor"}),s.jsx("meta",{name:"robots",content:"noindex"})]}),s.jsx("div",{className:"container py-12 flex flex-col items-center justify-center min-h-[75vh]",children:s.jsx(r,{className:"w-full max-w-md",children:s.jsxs(c,{children:[s.jsxs("div",{className:"flex items-center gap-2 text-destructive",children:[s.jsx(j,{className:"h-5 w-5"}),s.jsx(l,{children:"Invalid Request"})]}),s.jsx(o,{children:"Missing connection parameters. Please sign in from the HobbyMonitor desktop app."})]})})})]})}return"mcp"===A?H?s.jsxs(s.Fragment,{children:[s.jsxs(i,{children:[s.jsx("title",{children:"Connect to HobbyMonitor"}),s.jsx("meta",{name:"robots",content:"noindex"})]}),s.jsx("div",{className:"container py-12 flex flex-col items-center justify-center min-h-[75vh]",children:s.jsxs(r,{className:"w-full max-w-md",children:[s.jsxs(c,{className:"text-center",children:[s.jsx(l,{children:"success"===y?"Connected!":"Connect to HobbyMonitor"}),s.jsx(o,{children:"success"===y?"Returning you to the app...":"Sign in to authorize access to your HobbyMonitor account."})]}),s.jsx(d,{className:"space-y-4",children:"success"===y?s.jsxs("div",{className:"flex flex-col items-center gap-3 py-4",children:[s.jsx(f,{className:"h-12 w-12 text-green-600"}),s.jsx(g,{className:"h-4 w-4 animate-spin"})]}):"error"===y?s.jsxs("div",{className:"space-y-3",children:[s.jsx("div",{className:"bg-destructive/10 text-destructive text-sm p-3 rounded-md",children:v}),s.jsx(x,{className:"w-full",variant:"outline",onClick:()=>{w("ready"),b(null)},children:"Try Again"})]}):s.jsxs("div",{className:"space-y-4",children:[("signing-in"===y||"sending"===y)&&s.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-muted-foreground py-1",children:[s.jsx(g,{className:"h-4 w-4 animate-spin"}),"sending"===y?"Authorizing...":"Signing in..."]}),s.jsxs("form",{onSubmit:R,className:"space-y-3",children:[s.jsx("input",{type:"email",required:!0,placeholder:"Email",autoComplete:"email",value:N,onChange:e=>C(e.target.value),disabled:"ready"!==y,className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm"}),s.jsx("input",{type:"password",required:!0,placeholder:"Password",autoComplete:"current-password",value:k,onChange:e=>M(e.target.value),disabled:"ready"!==y,className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm"}),s.jsx(x,{type:"submit",className:"w-full",disabled:"ready"!==y,children:"Sign in"})]}),s.jsxs("div",{className:"relative",children:[s.jsx("div",{className:"absolute inset-0 flex items-center",children:s.jsx("span",{className:"w-full border-t"})}),s.jsx("div",{className:"relative flex justify-center text-xs uppercase",children:s.jsx("span",{className:"bg-background px-2 text-muted-foreground",children:"or"})})]}),s.jsxs(x,{variant:"outline",className:"w-full",onClick:E,disabled:"ready"!==y,children:[s.jsxs("svg",{className:"h-4 w-4",viewBox:"0 0 18 18",fill:"none",children:[s.jsx("path",{d:"M17.64 9.205c0-.639-.057-1.252-.164-1.841H9v3.481h4.844a4.14 4.14 0 01-1.796 2.716v2.259h2.908c1.702-1.567 2.684-3.875 2.684-6.615z",fill:"#4285F4"}),s.jsx("path",{d:"M9 18c2.43 0 4.467-.806 5.956-2.18l-2.908-2.259c-.806.54-1.837.86-3.048.86-2.344 0-4.328-1.584-5.036-3.711H.957v2.332A8.997 8.997 0 009 18z",fill:"#34A853"}),s.jsx("path",{d:"M3.964 10.71A5.41 5.41 0 013.682 9c0-.593.102-1.17.282-1.71V4.958H.957A8.997 8.997 0 000 9c0 1.452.348 2.827.957 4.042l3.007-2.332z",fill:"#FBBC05"}),s.jsx("path",{d:"M9 3.58c1.321 0 2.508.454 3.44 1.345l2.582-2.58C13.463.891 11.426 0 9 0A8.997 8.997 0 00.957 4.958L3.964 6.29C4.672 4.163 6.656 2.58 9 2.58z",fill:"#EA4335"})]}),"Continue with Google"]}),s.jsxs(x,{variant:"outline",className:"w-full",onClick:P,disabled:"ready"!==y,children:[s.jsx("svg",{className:"h-4 w-4",viewBox:"0 0 384 512",fill:"currentColor",children:s.jsx("path",{d:"M318.7 268.7c-.2-36.7 16.4-64.4 50-84.8-18.8-26.9-47.2-41.7-84.7-44.6-35.5-2.8-74.3 20.7-88.5 20.7-15 0-49.4-19.7-76.4-19.7C63.3 141.2 4 184.8 4 273.5q0 39.3 14.4 81.2c12.8 36.7 59 126.7 107.2 125.2 25.2-.6 43-17.9 75.8-17.9 31.8 0 48.3 17.9 76.4 17.9 48.6-.7 90.4-82.5 102.6-119.3-65.2-30.7-61.7-90-61.7-91.9zm-56.6-164.2c27.3-32.4 24.8-61.9 24-72.5-24.1 1.4-52 16.4-67.9 34.9-17.5 19.8-27.8 44.3-25.6 71.9 26.1 2 49.9-11.4 69.5-34.3z"})}),"Continue with Apple"]})]})})]})})]}):s.jsxs(s.Fragment,{children:[s.jsxs(i,{children:[s.jsx("title",{children:"Connect - HobbyMonitor"}),s.jsx("meta",{name:"robots",content:"noindex"})]}),s.jsx("div",{className:"container py-12 flex flex-col items-center justify-center min-h-[75vh]",children:s.jsx(r,{className:"w-full max-w-md",children:s.jsxs(c,{children:[s.jsxs("div",{className:"flex items-center gap-2 text-destructive",children:[s.jsx(j,{className:"h-5 w-5"}),s.jsx(l,{children:"Invalid Request"})]}),s.jsx(o,{children:"Missing connection token. Please start the connection from your app."})]})})})]}):s.jsxs(s.Fragment,{children:[s.jsxs(i,{children:[s.jsx("title",{children:"Connect - HobbyMonitor"}),s.jsx("meta",{name:"robots",content:"noindex"})]}),s.jsx("div",{className:"container py-12 flex flex-col items-center justify-center min-h-[75vh]",children:s.jsx(r,{className:"w-full max-w-md",children:s.jsxs(c,{children:[s.jsxs("div",{className:"flex items-center gap-2 text-destructive",children:[s.jsx(j,{className:"h-5 w-5"}),s.jsx(l,{children:"Unknown Flow"})]}),s.jsxs(o,{children:['The requested connection flow "',A,'" is not recognized.']})]})})})]})}export{y as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.