<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8" import="com.fasterxml.jackson.databind.ObjectMapper, sgc.portal.SgcPortalAttributes, sgc.portal.com.sym.user.model.UserDetails"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
	<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<title>SGC Portal</title>
<%--    <meta name="msapplication-TileImage" content="/resources/images/icon/ms-icon-144x144.png">--%>
<%--    <meta name="theme-color" content="#333">--%>
<%--    <link rel="apple-touch-icon" sizes="57x57" href="/resources/images/icon/apple-icon-57x57.png">--%>
<%--    <link rel="apple-touch-icon" sizes="60x60" href="/resources/images/icon/apple-icon-60x60.png">--%>
<%--    <link rel="apple-touch-icon" sizes="72x72" href="/resources/images/icon/apple-icon-72x72.png">--%>
<%--    <link rel="apple-touch-icon" sizes="76x76" href="/resources/images/icon/apple-icon-76x76.png">--%>
<%--    <link rel="apple-touch-icon" sizes="114x114" href="/resources/images/icon/apple-icon-114x114.png">--%>
<%--    <link rel="apple-touch-icon" sizes="120x120" href="/resources/images/icon/apple-icon-120x120.png">--%>
<%--    <link rel="apple-touch-icon" sizes="144x144" href="/resources/images/icon/apple-icon-144x144.png">--%>
<%--    <link rel="apple-touch-icon" sizes="152x152" href="/resources/images/icon/apple-icon-152x152.png">--%>
<%--    <link rel="apple-touch-icon" sizes="180x180" href="/resources/images/icon/apple-icon-180x180.png">--%>
<%--    <link rel="icon" type="image/png" sizes="192x192"  href="/resources/images/icon/android-icon-192x192.png">--%>
<%--    <link rel="icon" type="image/png" sizes="32x32" href="/resources/images/icon/favicon-32x32.png">--%>
<%--    <link rel="icon" type="image/png" sizes="96x96" href="/resources/images/icon/favicon-96x96.png">--%>
<%--    <link rel="icon" type="image/png" sizes="16x16" href="/resources/images/icon/favicon-16x16.png">--%>
<%--    <link rel="manifest" href="/manifest.json">--%>
<%--    <meta name="msapplication-TileColor" content="#1a499b">--%>
<%--    <meta name="msapplication-TileImage" content="/resources/images/icon/ms-icon-144x144.png">--%>
    <meta name="theme-color" content="#333">
    <script type="text/javascript" src="javascript.wq?q=/bootloader"></script>
    <script type="text/javascript" src="/pwa/app.js"></script>
    <script type="text/javascript" src="/pwa/engageable.js"></script>
    <script type="text/javascript">
        var _w2xPath_ = "<%=(String)request.getAttribute("w2xPath")%>";

        if (  "<%= request.getSession().getAttribute(SgcPortalAttributes.AUTHENTICATION) == null || request.getSession().getAttribute(SgcPortalAttributes.AUTHENTICATION).equals("") ? "":"O" %>" == "" && _w2xPath_.indexOf("/ux/main/login.xml") < 0 && _w2xPath_.indexOf("/ux/main/login-as.xml") < 0) {
            commLib.moveToLoginPage();  // 세션 만료 처리
        } else {
            if (  "<%= request.getSession().getAttribute(SgcPortalAttributes.AUTHENTICATION) == null || request.getSession().getAttribute(SgcPortalAttributes.AUTHENTICATION).equals("") ? "":"O" %>" != "" && _w2xPath_.indexOf("/login.xml") > 0) {
                location.replace( "/websquare/" );
            }else{
              window.onload = init;       // 유효한 세션
            }
        }

        function init() {
            try {
	            <%
	            if( request.getSession().getAttribute(SgcPortalAttributes.AUTHENTICATION) != null ) {
	                UserDetails userDetails = (UserDetails)request.getSession().getAttribute(SgcPortalAttributes.AUTHENTICATION);
	                ObjectMapper mapper = new ObjectMapper();
	                String jsonInString = mapper.writeValueAsString(userDetails);

	            %>
	              var sesData = <%=jsonInString%>;
	              WebSquare.session.setAttribute( "data" , sesData );
	              WebSquare.session.setAttribute( "user" , sesData );
	            <%
	            }
	            %>
	            WebSquare.startPopupApplication(_w2xPath_);
            } catch (e) {
                console.log(">>>>>>>>>>>", e);
                alert(e);
            }
        }

        window.addEventListener("beforeunload", function (event) {
            var tab = WebSquare.util.getComponentById("tabc_layout");
            if (tab != undefined) {
	            var openedTabCnt = tab.getTabCount();
		        for (var i = openedTabCnt-1; i >= 1; i--) {
		        	tab.setSelectedTabIndex( i );
					tab.deleteTab(i);
				}
			}
		});
    </script>
</head>
<body />
</html>