import{r as registerInstance,e as createEvent,h as h$1,g as getElement}from"./index-38ad4957.js";import{k as useState,f as useEffect,n as h}from"./dom-context-hooks.module-50442785.js";import{g as getEnvironmentSDK,i as isDemo}from"./index.module-b23fdad8.js";function useGoogleSignIn(e){var t=useState(false),n=t[0],o=t[1];var i=useState(null),r=i[0],u=i[1];var c=useState(400),l=c[0],a=c[1];var s=null;var g=function(){if(r){a(r.clientWidth)}};useEffect((function(){if(!r)return;var e=new ResizeObserver((function(){if(s){clearTimeout(s)}s=setTimeout((function(){g()}),50)}));e.observe(r);g();return function(){return e.disconnect()}}),[r]);useEffect((function(){var t=function(){window.onGoogleLibraryLoad=null;var t=getEnvironmentSDK();if(t.type!=="SquatchPortal")return;var n=function(t){e.initComplete.emit(t)};google.accounts.id.initialize({client_id:t.env.googleOAuthId,callback:n});o(true)};if(window.google)t();window.onGoogleLibraryLoad=t}),[]);useEffect((function(){if(!r||!n)return;google.accounts.id.renderButton(r,{theme:"outline",size:"large",text:e.text,height:40,width:l})}),[r,n,l]);return{setGoogleButtonDiv:u}}var GoogleSignIn=function(){function e(e){registerInstance(this,e);this.initComplete=createEvent(this,"initComplete",7);this.googleButtonDiv=null;h(this)}e.prototype.disconnectedCallback=function(){};e.prototype.connectedCallback=function(){var e="https://accounts.google.com/gsi/client";if(!document.head.querySelector('script[src="'+e+'"]')){var t=document.createElement("script");t.src="https://accounts.google.com/gsi/client";t.async=true;document.head.appendChild(t)}};e.prototype.render=function(){var e=(isDemo()?useDemoGoogleSignIn(this):useGoogleSignIn(this)).setGoogleButtonDiv;return h$1("div",{ref:e,style:{width:"100%"}})};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});return e}();function useDemoGoogleSignIn(e){var t=useState(false),n=t[0],o=t[1];var i=useState(null),r=i[0],u=i[1];useEffect((function(){var e=function(){window.onGoogleLibraryLoad=null;o(true)};if(window.google)e();window.onGoogleLibraryLoad=e}),[]);useEffect((function(){if(!r||!n)return;var t=function(){e.initComplete.emit({credential:null})};google.accounts.id.initialize({client_id:"PLACEHOLDER",cb:function(){}});google.accounts.id.renderButton(r,{theme:"outline",size:"large",text:e.text,click_listener:t})}),[r,n]);return{setGoogleButtonDiv:u}}export{GoogleSignIn as sqm_google_sign_in};