{"version":3,"file":"GoogleSSOButton.y-QkK-Rq.mjs","names":["useState"],"sources":["https:/framerusercontent.com/modules/pS5f8pJdZBhLfGhiCDvm/vK2OsbG5kLjCJKMLBokD/GoogleSSOButton.js"],"sourcesContent":["//@ts-ignore\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useState}from\"react\";//@ts-ignore\nimport{addPropertyControls,ControlType}from\"framer\";const LAST_USED_SSO_STORAGE_KEY=\"ara:lastUsedSsoProvider\";const LAST_USED_SSO_EVENT=\"ara:last-used-sso\";const LAST_USED_BADGE_STYLE={position:\"absolute\",top:-8,right:-12,padding:\"4px 10px\",borderRadius:\"8px 8px 8px 0\",background:\"rgba(255, 255, 255, 0.14)\",color:\"rgba(255, 255, 255, 0.9)\",fontFamily:\"Sentient\",fontSize:10,fontWeight:500,letterSpacing:\"0.08em\",textTransform:\"uppercase\",boxShadow:\"rgba(0, 0, 0, 0.25) 0px 2px 6px\",pointerEvents:\"none\",backdropFilter:\"blur(6px)\"};const readLastUsedProvider=()=>{if(typeof window===\"undefined\")return null;try{return localStorage.getItem(LAST_USED_SSO_STORAGE_KEY);}catch{return null;}};const markLastUsedSSO=provider=>{if(typeof window===\"undefined\")return;try{localStorage.setItem(LAST_USED_SSO_STORAGE_KEY,provider);window.dispatchEvent(new CustomEvent(LAST_USED_SSO_EVENT,{detail:provider}));}catch{// ignore storage errors\n}};const useIsLastUsedSSO=provider=>{const[isLastUsed,setIsLastUsed]=useState(()=>readLastUsedProvider()===provider);useEffect(()=>{if(typeof window===\"undefined\")return;const refresh=value=>{const nextValue=value??readLastUsedProvider();setIsLastUsed(nextValue===provider);};const handleCustom=event=>refresh(event.detail);const handleFocus=()=>refresh();const handleStorage=()=>refresh();refresh();window.addEventListener(LAST_USED_SSO_EVENT,handleCustom);window.addEventListener(\"focus\",handleFocus);window.addEventListener(\"storage\",handleStorage);return()=>{window.removeEventListener(LAST_USED_SSO_EVENT,handleCustom);window.removeEventListener(\"focus\",handleFocus);window.removeEventListener(\"storage\",handleStorage);};},[provider]);return isLastUsed;};function consumeReturnIntentPath(){if(typeof window===\"undefined\")return null;const api=window.__araReturnIntent;const payload=api?.consume?.();return payload?.path??null;}function buildAbsoluteUrl(candidate,fallback){if(typeof window===\"undefined\"){return candidate||fallback||\"\";}const safeFallback=fallback||window.location.href;if(!candidate||candidate.trim().length===0){return safeFallback;}try{return new URL(candidate,window.location.origin).toString();}catch{return safeFallback;}}export default function GoogleSSOButton({buttonText=\"Sign in with Google\",backendUrl=\"/api/auth/google\",intent=\"login\",onSuccess,onError,style}){const[error,setError]=useState(null);const[isLinked,setIsLinked]=useState(false);const[currentUser,setCurrentUser]=useState(null);const providerSlug=\"google\";const isLastUsed=useIsLastUsedSSO(providerSlug);// Subscribe to Outseta user state instantly via shared module\nuseEffect(()=>{const outsetaModule=window.__outsetaFramerModule;if(outsetaModule){const user=outsetaModule.getUser();setCurrentUser(user);const unsubscribe=outsetaModule.subscribe(newUser=>{setCurrentUser(newUser);});return unsubscribe;}},[]);// Check if already linked when intent is \"link\"\nuseEffect(()=>{if(intent===\"link\"&&currentUser){if(currentUser.GoogleId){setIsLinked(true);}else{setIsLinked(false);}}},[intent,currentUser]);useEffect(()=>{const hash=window.location.hash;if(!hash)return;const params=new URLSearchParams(hash.replace(/^#/,\"\"));if(params.has(\"error\")){const provider=params.get(\"provider\");if(provider&&provider!==providerSlug){return;}const code=params.get(\"error\");const rawMessage=params.get(\"message\");const decodedMessage=rawMessage?decodeURIComponent(rawMessage):null;const message=decodedMessage||(code===\"account_exists\"?\"This email is already registered. Please sign in using a known method, then link this provider from your account settings.\":\"Authentication failed\");setError(message);onError?.(message);window.history.replaceState(null,\"\",window.location.pathname+window.location.search);return;}if(params.has(\"link\")){const provider=params.get(\"provider\");if(provider&&provider!==providerSlug){return;}// Clear link status hash silently\nwindow.history.replaceState(null,\"\",window.location.pathname+window.location.search);return;}if(params.has(\"google_token\")){const token=params.get(\"google_token\");if(token&&window.Outseta?.setAccessToken){(async()=>{try{await window.Outseta.setAccessToken(token);if(intent===\"login\"){markLastUsedSSO(providerSlug);}onSuccess?.();window.history.replaceState(null,\"\",window.location.pathname+window.location.search);const preferredPath=consumeReturnIntentPath();if(preferredPath!==null&&preferredPath!==undefined){const trimmedIntent=preferredPath.trim();window.location.href=trimmedIntent.length>0?trimmedIntent:\"/\";return;}window.location.href=\"/\";}catch(err){const errorMsg=err instanceof Error?err.message:\"Failed to set authentication token\";setError(errorMsg);onError?.(errorMsg);}})();}else if(token){const errorMsg=\"Outseta not loaded. Please refresh the page.\";setError(errorMsg);onError?.(errorMsg);}}},[intent,onSuccess,onError]);const handleGoogleLogin=async()=>{setError(null);try{const startUrl=new URL(backendUrl,window.location.origin);const targetReturnUrl=buildAbsoluteUrl();startUrl.searchParams.set(\"return_url\",targetReturnUrl);startUrl.searchParams.set(\"intent\",intent);if(intent===\"link\"){// Get token at click time from module\nconst outsetaModule=window.__outsetaFramerModule;let accessToken=outsetaModule?.getAccessToken?.();if(!accessToken&&outsetaModule?.getAccessTokenAsync){accessToken=await outsetaModule.getAccessTokenAsync(\"google-link-click\");}// Debug: check all possible token sources\nlet localStorageToken=null;try{const stored=localStorage.getItem(\"Outseta.nocode.accessToken\");if(stored){const parsed=JSON.parse(stored);localStorageToken=parsed.access_token||parsed;}}catch(e){}if(!currentUser||!currentUser?.Uid||!accessToken){const errorMsg=\"Please sign in before linking this provider.\";setError(errorMsg);onError?.(errorMsg);return;}startUrl.searchParams.set(\"link_person_uid\",currentUser.Uid);startUrl.searchParams.set(\"link_token\",accessToken);}window.location.href=startUrl.toString();}catch(err){const errorMsg=err instanceof Error?err.message:\"Authentication failed\";setError(errorMsg);onError?.(errorMsg);}};if(intent===\"link\"&&isLinked){return /*#__PURE__*/_jsx(\"div\",{style:{display:\"none\",visibility:\"hidden\",position:\"absolute\",width:0,height:0,overflow:\"hidden\",margin:0,padding:0,border:\"none\",clip:\"rect(0,0,0,0)\"}});}return /*#__PURE__*/_jsxs(\"div\",{style:{display:\"inline-flex\",flexDirection:\"column\",alignItems:\"center\",gap:\"8px\",width:\"100%\"},children:[/*#__PURE__*/_jsxs(\"div\",{style:{position:\"relative\",width:\"100%\"},children:[/*#__PURE__*/_jsxs(\"button\",{onClick:handleGoogleLogin,style:{fontFamily:\"Sentient\",padding:\"12px 24px\",background:\"linear-gradient(180deg, rgba(16, 24, 40, 0.4) 0%, rgba(16, 24, 40, 0.8) 100%)\",color:\"#fff\",border:\"none\",borderRadius:16,fontSize:16,fontWeight:400,cursor:\"pointer\",transition:\"all 0.2s\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\",gap:\"8px\",width:\"100%\",boxShadow:\"rgb(46, 62, 84) 0px -1px 2px 1px inset, rgba(61, 61, 61, 0.02) 0px 0.602187px 2.047437px 0px inset, rgba(61, 61, 61, 0.06) 0px 2.288533px 7.781013px 0px inset, rgba(61, 61, 61, 0.25) 0px 10px 34px 0px inset\",...style},onMouseEnter:e=>{e.currentTarget.style.boxShadow=\"rgb(89, 116, 153) 2px 2px 10px 6px inset, rgba(255, 255, 255, 0.02) 0px 0.602187px 1.565687px 0px inset, rgba(255, 255, 255, 0.06) 0px 2.288533px 5.950187px 0px inset, rgba(255, 255, 255, 0.25) 0px 10px 26px 0px inset\";},onMouseLeave:e=>{e.currentTarget.style.boxShadow=\"rgb(46, 62, 84) 0px -1px 2px 1px inset, rgba(61, 61, 61, 0.02) 0px 0.602187px 2.047437px 0px inset, rgba(61, 61, 61, 0.06) 0px 2.288533px 7.781013px 0px inset, rgba(61, 61, 61, 0.25) 0px 10px 34px 0px inset\";},children:[/*#__PURE__*/_jsxs(\"svg\",{width:\"18\",height:\"18\",viewBox:\"0 0 48 48\",fill:\"none\",children:[/*#__PURE__*/_jsx(\"path\",{d:\"M43.611 20.083H42V20H24v8h11.303c-1.649 4.657-6.08 8-11.303 8-6.627 0-12-5.373-12-12s5.373-12 12-12c3.059 0 5.842 1.154 7.961 3.039l5.657-5.657C34.046 6.053 29.268 4 24 4 12.955 4 4 12.955 4 24s8.955 20 20 20 20-8.955 20-20c0-1.341-.138-2.65-.389-3.917z\",fill:\"#FFC107\"}),/*#__PURE__*/_jsx(\"path\",{d:\"m6.306 14.691 6.571 4.819C14.655 15.108 18.961 12 24 12c3.059 0 5.842 1.154 7.961 3.039l5.657-5.657C34.046 6.053 29.268 4 24 4 16.318 4 9.656 8.337 6.306 14.691z\",fill:\"#FF3D00\"}),/*#__PURE__*/_jsx(\"path\",{d:\"M24 44c5.166 0 9.86-1.977 13.409-5.192l-6.19-5.238A11.91 11.91 0 0 1 24 36c-5.202 0-9.619-3.317-11.283-7.946l-6.522 5.025C9.505 39.556 16.227 44 24 44z\",fill:\"#4CAF50\"}),/*#__PURE__*/_jsx(\"path\",{d:\"M43.611 20.083H42V20H24v8h11.303a12.04 12.04 0 0 1-4.087 5.571l.003-.002 6.19 5.238C36.971 39.205 44 34 44 24c0-1.341-.138-2.65-.389-3.917z\",fill:\"#1976D2\"})]}),buttonText]}),intent===\"login\"&&isLastUsed&&/*#__PURE__*/_jsx(\"span\",{style:LAST_USED_BADGE_STYLE,children:\"Last used\"})]}),error&&/*#__PURE__*/_jsx(\"div\",{style:{fontFamily:\"Sentient\",color:\"rgba(245, 88, 88, 0.75)\",fontSize:12,textAlign:\"center\"},children:error})]});}addPropertyControls(GoogleSSOButton,{buttonText:{type:ControlType.String,title:\"Button Text\",defaultValue:\"Sign in with Google\"},backendUrl:{type:ControlType.String,title:\"Backend URL\",defaultValue:\"/api/auth/google\",description:\"Your backend endpoint for Google SSO\"},intent:{type:ControlType.Enum,title:\"Intent\",defaultValue:\"login\",options:[\"login\",\"link\"],optionTitles:[\"Login\",\"Link\"]}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"GoogleSSOButton\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./GoogleSSOButton.map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