<%@ page language="java" pageEncoding="UTF-8" isELIgnored="false" session="false"%>
<%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
<%@ page import="java.util.HashMap, javax.servlet.http.HttpServletRequest, cokr.xit.foundation.data.Convert" %>
<%!	private static final HashMap<String, String> titles  = new HashMap<>();
	
	static {
		titles.put("404", "Page Not Found"); 
		titles.put("sessionExpired", "Session Expired"); 
		titles.put("invalidSession", "Invalid Session"); 
		titles.put("accessDenied", "Access Denied"); 
		titles.put("500", "Server Error");
	}
	
	private static void setTitle(HttpServletRequest hreq)  {
		String status = Convert.toString(hreq.getAttribute("status"));
		if (status == "")
			status = "500";
		String title = titles.get(status);
		if (title == null)
			title = titles.get("500");
		hreq.setAttribute("title", title);
	}
%>
<% setTitle(request); %>
<c:if test="${json}"><%
	response.setContentType("application/json; charset=UTF-8");
	String stacktrace = (String)request.getAttribute("stacktrace");
	request.setAttribute("stacktrace", Convert.rntq(stacktrace));
%>{
  "path": "${path}",
  "failed": true,
  "status": "${status}",
  "title": "${title}",
  "message": "${message}",
  "description": "${description}",
  "stacktrace": "${stacktrace}",
  "promptLogin": "${promptLogin}"
}</c:if>
<c:if test="${!json}"><%@ include file="/WEB-INF/jsp/include/taglib.jsp"%>
<jsp:include page="/WEB-INF/jsp/include/head.jsp" />
<style>
.misc-wrapper {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - (1.625rem * 2));
    text-align: center;
}
</style>
  <body>
    <!-- Content -->

    <!-- Error -->
    <div class="container-xxl container-p-y">
      <div class="misc-wrapper">
        <h2 class="mb-2 mx-2">${title} :(</h2>
        <p class="mb-4 mx-2">죄송합니다. 😖</p>
        <p class="mb-4 mx-2">${message}</p>
        <a onclick="wctx.home();" class="btn btn-primary" href="javascript:void(0);">처음으로 돌아가기</a>
        <a onclick="history.back();" class="btn btn-primary mt-2" href="javascript:void(0);" autofocus>이전으로 돌아가기</a>
        <div class="mt-3">
          <img
            src="<c:url value="/webjars/img/illustrations/page-misc-error-light.png"/>"
            alt="page-misc-error-light"
            width="500"
            class="img-fluid"
            data-app-dark-img="illustrations/page-misc-error-dark.png"
            data-app-light-img="illustrations/page-misc-error-light.png"
          />
        </div>
      </div>
    </div>
    <!-- /Error -->

    <!-- / Content -->

<jsp:include page="/WEB-INF/jsp/include/tail.jsp" />
<script>
<c:if test="${promptLogin}">
setTimeout(() => wctx.home(), 2000);
</c:if>
${functions}
</script>
  </body>
</html></c:if>
