<%@ 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="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

<div class="section_title">
	<!-- <p>현장 지원 시스템</p> -->
</div>

<div class="section_content">
	<form:form commandName="useRequestSearchVO" id="searchForm" name="searchForm" method="get" >
		<input type="hidden" name="id" />
		<table class="list-table">
			<thead>
				<tr><th colspan="4">지도 사용 요청 목록</th></tr>
				<tr>
					<th>번호</th>
					<th>작업명</th>
					<th>날짜</th>
					<th>상태</th>
				</tr>
			</thead>
			<tbody>
				<c:if test="${count >= 1}">
					<c:forEach var="item" items="${useRequestList}" varStatus="idx">
						<tr>
							<td>${idx.count}</td>
							<td class="title-td" style="width:70%;"><a href="/map/request/<c:out value='${item.idx}' />">${item.title}</a></td>
							<td class="td_date">${item.r_date}</td>
							<td>
								<c:choose>
									<c:when test="${item.status eq '99'}"><span class="card-warning"><c:out value='승인대기' /></span></c:when>
									<c:when test="${item.status eq '0'}"><span class="card-success"><c:out value='승인' /></span></c:when>
									<c:when test="${item.status eq '-1'}"><span class="card-default"><c:out value='반려' /></span></c:when>
								</c:choose>
							</td>
						</tr>
					</c:forEach>
				</c:if>
				<c:if test="${count == 0}">
					<tr><td colspan="4">요청한 목록이 없습니다.</td></tr>
				</c:if>
			</tbody>
		</table>
		<div class="div_write">
			<p>
				<input class="btn btn-secondary" type="button" value="작성" onclick="location.href='/map/reqWrite'" />
			</p>
		</div>

		<div class="text-page">
			<form:hidden path="pageIndex" />
			<nav aria-label="Page navigation">
				<ul class="pagination justify-content-center">
					<ui:pagination paginationInfo="${paginationInfo}" type="image" jsFunction="fn_link_page" />
				</ul>
			</nav>
		</div>
	</form:form>
</div>
<div class="section_btn">
	<!-- <p><input class="btn" type="button" value="관리" onclick="location.href='fieldDetail.html'" /></p> -->
</div>
<script type="text/javascript">
	var start = "${b_start}";
	var end = "${b_end}";
	var now = "${current_page}";

	$(function(){
		viewPaging();
		$(".r_date").each(function(){
			var r_date = $(this).text();
			var nowDate = new Date();
			var r_date = new Date(r_date);
			var getDay = 	getFormatDate(r_date);
			var nowDay = getFormatDate(nowDate);

			if(getDay === nowDay){
				$(this).html(getFormatTime(r_date));
			}else{
				$(this).html(getDay);
			}
		});
	});

	/* 날짜포맷 yyyy-MM-dd 변환 */
	 function getFormatDate(date){
		 var year = date.getFullYear();
		 var month = (1 + date.getMonth());
		 month = month >= 10 ? month : '0' + month;
		 var day = date.getDate();
		 day = day >= 10 ? day : '0' + day;
		 return year + '-' + month + '-' + day;
	 }

	 function getFormatTime(date){
		 var hours = date.getHours();
		 var minutes = date.getMinutes();
		 return hours + ':' + minutes;
	 }

	 function viewPaging(){
		for (step = start; step < end; step++) {
			if(step == now){
				$("#paging").append("<strong>"+step+"</strong>");
			}else{
				$("#paging").append("<a href='userPermissionList.do?&page="+ step +"'>"+step+"</a>");
			}
		}
	}

		function fn_link_page(pageNo) {
			document.searchForm.pageIndex.value = pageNo;
			document.searchForm.action = "<c:url value='/map/request' />";
			document.searchForm.submit();
		}

</script>
