<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>L2MAKER - Firebase Authentication</title>
	<style>
	.bg-main {
		background-color: <%=(request.getParameter("bg-color") == null ? "#fff" : request.getParameter("bg-color"))%>;
	}
	</style>
	<!--[if IE]><base href="<% 
	String baseURL = request.getRequestURL().toString().replace("/l2s/firebase/auth/index.jsp", "/");
	out.print(baseURL); %>"></base><![endif]-->
	<!--[if !IE]>--><base href="../../.." /><!--<![endif]-->
    <script src="https://www.gstatic.com/firebasejs/9.1.3/firebase-app-compat.js"></script>
    <script src="https://www.gstatic.com/firebasejs/9.1.3/firebase-auth-compat.js"></script>
	<script type="text/javascript" src="l2s/commons/core.js"></script>
	<%=br.com.l2software.api.firebase.auth.ClientHelper.getConfig(request)%>
    <script src="https://www.gstatic.com/firebasejs/ui/6.0.1/firebase-ui-auth__pt_br.js"></script>
    <link type="text/css" rel="stylesheet" href="https://www.gstatic.com/firebasejs/ui/6.0.1/firebase-ui-auth.css" />
    <script type="text/javascript">  
      var uiConfig = {
        callbacks: {
          signInSuccessWithAuthResult: function(authResult, redirectUrl) {
            var user = authResult.user;
            var credential = authResult.credential;
            var isNewUser = authResult.additionalUserInfo.isNewUser;
            var providerId = authResult.additionalUserInfo.providerId;
            var operationType = authResult.operationType;
			var accessToken = user._delegate.accessToken;
			var payload = JSON.stringify(authResult);//
			var flowName = '<%=request.getParameter("onResponse")%>';
			var params = [ providerId, operationType, accessToken, payload ];
			callFlow(flowName, params);
            return false;
          },
          signInFailure: function(error) {
            return handleUIError(error);
          },
          uiShown: function() {
            document.getElementById('loader').style.display = 'none';
          }
        },
        credentialHelper: firebaseui.auth.CredentialHelper.NONE,
        queryParameterForWidgetMode: 'mode',
        queryParameterForSignInSuccessUrl: 'signInSuccessUrl',
        signInFlow: 'popup',
        signInSuccessUrl: false,
        signInOptions: [<%=br.com.l2software.api.firebase.auth.ClientHelper.getProviders(request)%>],
        immediateFederatedRedirect: false,
        tosUrl: false,
        privacyPolicyUrl: false
      };

      var ui = new firebaseui.auth.AuthUI(firebase.auth());
      ui.start('#firebaseui-auth-container', uiConfig);
    </script>
  </head>
  <body class="bg-main">
    <div id="firebaseui-auth-container"></div>
    <div id="loader">Carregando...</div>
  </body>
</html>