1import{o as O}from"./rolldown-runtime-ChpBd9eV.js";import{a as P,n as I}from"./vendor-react-DcWoBPJp.js";import{Ho as E,Sn as L,_i as j,ls as p,mr as F,vo as U,zo as u}from"./vendor-ui-hcrcJjHJ.js";import{u as $}from"./chunk-QUQL4437-DKXSrjJr.js";import{l as q}from"./authAnalytics-DK9RBC7g.js";import{o as d}from"./authErrors-BJPPLK2J.js";import{i as D}from"./AuthService-RwBp9Rl0.js";import{r as B}from"./AuthContext-CWrypuf9.js";import{d as J,m as T,u as G}from"./index-CL2aAkkR.js";import{n as v,t as k}from"./Card-DIl7dpPH.js";import"./Card-Ca1N5Y9h.js";import{t as H}from"./Input-CdbxVNBC.js";import"./Input-SP1-zVGg.js";import{n as M}from"./signupAttribution-gfL6X79o.js";import{clearOAuthSession as C,getOAuthSession as z}from"./GoogleCallbackPage-oUXDCuLN.js";var l=O(P(),1),e=I();function R({company:r,selected:n,onSelect:s}){return(0,e.jsx)("div",{onClick:s,className:` 2 relative cursor-pointer rounded-xl border-2 p-4 transition-all duration-200 3 ${n?"border-purple-500 bg-purple-500/10 shadow-lg shadow-purple-500/10":"border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600 bg-white dark:bg-gray-800/50"} 4 `,children:(0,e.jsxs)("div",{className:"flex items-start gap-3",children:[(0,e.jsx)("div",{className:` 5 flex h-10 w-10 items-center justify-center rounded-lg 6 ${n?"bg-purple-500 text-white":"bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-400"} 7 `,children:(0,e.jsx)(p,{className:"h-5 w-5"})}),(0,e.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,e.jsx)("h3",{className:"font-semibold text-gray-900 dark:text-white truncate",children:r.name}),(0,e.jsx)(W,{policy:r.joinPolicy})]}),n&&(0,e.jsx)(u,{className:"h-5 w-5 text-purple-500 flex-shrink-0"})]})})}function W({policy:r}){const n={auto_approve:{label:"Auto-approve",className:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400",icon:u},require_approval:{label:"Requires approval",className:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400",icon:U},closed:{label:"Invite only",className:"bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-400",icon:p}},s=n[r]||n.closed,c=s.icon;return(0,e.jsxs)("span",{className:` 8 inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium mt-1 9 ${s.className} 10 `,children:[(0,e.jsx)(c,{className:"h-3 w-3"}),s.label]})}function de(){const[r,n]=(0,l.useState)(null),[s,c]=(0,l.useState)(null),[t,g]=(0,l.useState)(!1),[m,w]=(0,l.useState)(""),[h,y]=(0,l.useState)(!1),[b,o]=(0,l.useState)(""),i=$(),{setAuthenticatedUser:f}=B();(0,l.useEffect)(()=>{const a=z();if(!a){d.warn("No OAuth session found, redirecting to signup"),i("/signup",{replace:!0,state:{reason:"oauth_session_expired",message:"Please restart the signup process"}});return}n(a),d.info("Loaded OAuth session for company selection:",{companiesCount:a.availableCompanies.length,canCreateCompany:a.canCreateCompany})},[i]);const S=(0,l.useCallback)(a=>{c(a),g(!1),o("")},[]),_=(0,l.useCallback)(()=>{c(null),g(!0),o("")},[]),A=(0,l.useCallback)(async()=>{if(r){if(!t&&!s){o("Please select a company or choose to create a new one");return}if(t&&!m.trim()){o("Please enter a company name");return}y(!0),o("");try{d.info("Completing OAuth company selection:",{selectedCompanyId:s,createNewCompany:t,newCompanyName:t?m:void 0});const a=await D.selectOAuthCompany(r.selectionToken||"",r.keycloakUserId,r.realm||"",r.userEmail||"",s||void 0,t);C(),q(a.identity.id),f(a.identity),M("google_oauth_company_selection",a.identity.id,{create_new_company:t}),d.info("OAuth company selection successful, redirecting to default landing"),i(G,{replace:!0})}catch(a){d.error("OAuth company selection failed:",a);let N="Failed to complete signup. Please try again.";a instanceof Error&&(N=a.message),o(N)}finally{y(!1)}}},[r,s,t,m,i,f]);if(!r)return(0,e.jsx)("div",{className:"min-h-screen bg-gradient-to-br from-slate-900 via-purple-900 to-slate-900 flex items-center justify-center p-4",children:(0,e.jsx)(k,{className:"bg-white/95 backdrop-blur-sm shadow-2xl border-0 max-w-md w-full",children:(0,e.jsxs)(v,{className:"p-8 text-center",children:[(0,e.jsx)(j,{className:"h-8 w-8 text-purple-600 animate-spin mx-auto mb-4"}),(0,e.jsx)("p",{className:"text-gray-600",children:"Loading..."})]})})});const x=r.availableCompanies.length>0;return(0,e.jsxs)("div",{className:"min-h-screen bg-gradient-to-br from-slate-900 via-purple-900 to-slate-900 flex items-center justify-center p-4",children:[(0,e.jsx)("div",{className:"absolute inset-0 overflow-hidden",children:(0,e.jsxs)("div",{className:"absolute -inset-10 opacity-50",children:[(0,e.jsx)("div",{className:"absolute top-1/4 left-1/4 w-64 h-64 bg-purple-500 rounded-full mix-blend-multiply filter blur-xl animate-pulse"}),(0,e.jsx)("div",{className:"absolute top-3/4 right-1/4 w-64 h-64 bg-blue-500 rounded-full mix-blend-multiply filter blur-xl animate-pulse animation-delay-2000"}),(0,e.jsx)("div",{className:"absolute bottom-1/4 left-1/3 w-64 h-64 bg-indigo-500 rounded-full mix-blend-multiply filter blur-xl animate-pulse animation-delay-4000"})]})}),(0,e.jsx)("div",{className:"relative w-full max-w-lg mx-auto",children:(0,e.jsx)(k,{className:"bg-white/95 dar
10k:bg-gray-900/95 backdrop-blur-sm shadow-2xl border-0",children:(0,e.jsxs)(v,{className:"p-8",children:[(0,e.jsxs)("div",{className:"flex items-center justify-center gap-2 mb-6",children:[(0,e.jsx)("div",{className:"p-2 bg-gradient-to-br from-purple-500 to-indigo-600 rounded-lg",children:(0,e.jsx)(L,{className:"h-6 w-6 text-white"})}),(0,e.jsx)("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"UnaGo AI"})]}),(0,e.jsxs)("div",{className:"text-center mb-6",children:[(0,e.jsx)("h2",{className:"text-xl font-semibold text-gray-900 dark:text-white mb-2",children:"Choose Your Company"}),r.userName&&(0,e.jsxs)("p",{className:"text-gray-600 dark:text-gray-400",children:["Welcome, ",r.userName,"! Select a company to join or create a new one."]})]}),b&&(0,e.jsxs)(J,{className:"mb-6 border-red-200 bg-red-50 dark:border-red-800 dark:bg-red-900/20",children:[(0,e.jsx)(E,{className:"h-4 w-4 text-red-600 dark:text-red-400"}),(0,e.jsx)("div",{className:"text-red-700 dark:text-red-300 text-sm font-medium",children:b})]}),(0,e.jsxs)("div",{className:"space-y-4 mb-6",children:[x&&(0,e.jsxs)("div",{children:[(0,e.jsx)("p",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-3",children:"Available Companies"}),(0,e.jsx)("div",{className:"space-y-3",children:r.availableCompanies.map(a=>(0,e.jsx)(R,{company:a,selected:s===a.id&&!t,onSelect:()=>S(a.id)},a.id))})]}),!x&&(0,e.jsxs)("div",{className:"text-center py-6 bg-gray-50 dark:bg-gray-800/50 rounded-xl border border-gray-200 dark:border-gray-700",children:[(0,e.jsx)(p,{className:"h-12 w-12 text-gray-400 mx-auto mb-3"}),(0,e.jsx)("p",{className:"text-gray-600 dark:text-gray-400 text-sm",children:"No existing companies match your email domain."}),(0,e.jsx)("p",{className:"text-gray-500 dark:text-gray-500 text-xs mt-1",children:"Create a new company to get started."})]}),x&&r.canCreateCompany&&(0,e.jsxs)("div",{className:"relative py-2",children:[(0,e.jsx)("div",{className:"absolute inset-0 flex items-center",children:(0,e.jsx)("div",{className:"w-full border-t border-gray-200 dark:border-gray-700"})}),(0,e.jsx)("div",{className:"relative flex justify-center",children:(0,e.jsx)("span",{className:"bg-white dark:bg-gray-900 px-3 text-sm text-gray-500 dark:text-gray-400",children:"or"})})]}),r.canCreateCompany&&(0,e.jsxs)("div",{children:[(0,e.jsx)("div",{onClick:_,className:` 11 cursor-pointer rounded-xl border-2 p-4 transition-all duration-200 12 ${t?"border-purple-500 bg-purple-500/10 shadow-lg shadow-purple-500/10":"border-dashed border-gray-300 dark:border-gray-600 hover:border-gray-400 dark:hover:border-gray-500 bg-gray-50/50 dark:bg-gray-800/30"} 13 `,children:(0,e.jsxs)("div",{className:"flex items-center gap-3",children:[(0,e.jsx)("div",{className:` 14 flex h-10 w-10 items-center justify-center rounded-lg 15 ${t?"bg-purple-500 text-white":"bg-gray-200 dark:bg-gray-700 text-gray-500 dark:text-gray-400"} 16 `,children:(0,e.jsx)(F,{className:"h-5 w-5"})}),(0,e.jsxs)("div",{className:"flex-1",children:[(0,e.jsx)("h3",{className:"font-semibold text-gray-900 dark:text-white",children:"Create New Company"}),(0,e.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Start fresh with your own company"})]}),t&&(0,e.jsx)(u,{className:"h-5 w-5 text-purple-500 flex-shrink-0"})]})}),t&&(0,e.jsxs)("div",{className:"mt-4 p-4 bg-gray-50 dark:bg-gray-800/50 rounded-lg",children:[(0,e.jsx)("label",{htmlFor:"company-name",className:"text-sm font-medium text-gray-700 dark:text-gray-300 block mb-2",children:"Company Name"}),(0,e.jsx)(H,{id:"company-name",type:"text",value:m,onChange:a=>w(a.target.value),placeholder:"Enter your company name",className:"mt-2",autoFocus:!0})]})]})]}),(0,e.jsx)(T,{onClick:A,disabled:h||!s&&!t,className:"w-full h-11 bg-gradient-to-r from-purple-500 to-indigo-600 hover:from-purple-600 hover:to-indigo-700 text-white font-medium",children:h?(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)(j,{className:"h-4 w-4 animate-spin mr-2"}),"Processing..."]}):t?"Create Company & Continue":s?"Join Company & Continue":"Select an Option"}),(0,e.jsx)("div",{className:"mt-4 text-center",children:(0,e.jsx)("button",{type:"button",onClick:()=>{C(),i("/signup",{replace:!0})},className:"text-sm text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300 transition-colors",children:"Cancel and start over"})})]})})})]})}export{de as OAuthCompanySelectionPage,de 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.