<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>

<script type="text/javascript">
  $(document).on('click', '.logoutLink', function () {
    $("#logoutForm").submit();
  })
</script>
<c:set var="tilesURI" value="${requestScope['javax.servlet.forward.request_uri']}"/>
<c:set var="tilesURIParam" value="${requestScope['javax.servlet.forward.query_string']}"/>

<form id="logoutForm" action="/j_spring_security_logout" method="POST">
  <input name="${_csrf.parameterName}" type="hidden" value="${_csrf.token}"/>
</form>

<header class="header row justify-content-between">
  <div class="header_title col-auto">
    <sec:authorize access="isAnonymous()">
      <a href="/login">모바일센터 관리시스템</a>
    </sec:authorize>
    <sec:authorize access="hasRole('ROLE_USER')">
      <a href="/map/request">모바일센터 관리시스템</a>
    </sec:authorize>
    <sec:authorize access="hasRole('ROLE_ADMIN')">
      <a href="/admin/dashBoard">모바일센터 관리시스템</a>
    </sec:authorize>
  </div>
  <sec:authorize access="hasAnyRole('ROLE_ADMIN','ROLE_USER')">
    <div class="header_info col-auto">
      <a class="logoutLink d-none d-sm-block" href="#">
        <i class="bi bi-box-arrow-right"></i> 로그아웃
      </a>
      <div class="dropdown text-end d-block d-sm-none">
        <a href="#" class="d-block link-dark text-white text-decoration-none dropdown-toggle" id="dropdownUser1" data-bs-toggle="dropdown" aria-expanded="false">
          <i class="bi bi-list"></i>
        </a>
        <ul class="dropdown-menu text-small" aria-labelledby="dropdownUser1" style="">
          <sec:authorize access="hasRole('ROLE_USER')">
            <li><a class="dropdown-item" href="/map/request">지도사용 요청</a></li>
            <li><a class="dropdown-item" href="/map/userInfo">회원정보 수정</a></li>
          </sec:authorize>
          <sec:authorize access="hasRole('ROLE_ADMIN')">
            <li><a class="dropdown-item" href="/admin/dashBoard">대시보드</a></li>
            <li><a class="dropdown-item" href="/admin/request">지도사용 요청</a></li>
            <li><a class="dropdown-item" href="/admin/history">지도사용 이력</a></li>
            <li><a class="dropdown-item" href="/admin/fieldData?status0=1&status1=1&status2=1&status3=1&status4=1">현장수집 데이터</a></li>
            <li><a class="dropdown-item" href="/admin/userInfo?auth=99">회원 관리</a></li>
          </sec:authorize>
          <li><hr class="dropdown-divider"></li>
          <li><a class="dropdown-item logoutLink" href="#">로그아웃</a></li>
        </ul>
      </div>
    </div>
  </sec:authorize>
</header>
