<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<jsp:include page="${data._INCLUDE}/header.jsp"></jsp:include>
<script>
    $(function() {
        $("input[name=\"startDate\"]").daterangepicker({
            singleDatePicker : true,
            showDropdowns : true,
            startDate : "<c:out value='${startDate}'/>",
            locale : {
                //format : "M/DD hh:mm A"
                format : "YYYY-MM-DD"
            }
        });
        $("input[name=\"endDate\"]").daterangepicker({
            singleDatePicker : true,
            showDropdowns : true,
            startDate : "<c:out value='${endDate}'/>",
            locale : {
                //format : "M/DD hh:mm A"
                format : "YYYY-MM-DD"
            }
        });
    });
</script>
</head>
<body>
    <div class="wrapper">
        <jsp:include page="${data._INCLUDE}/sidebar.jsp"></jsp:include>
        
        <div class="main">
            <jsp:include page="${data._INCLUDE}/top.jsp"></jsp:include>

            <main class="content">
                <div class="container-fluid p-0">
                    <!-- 환지관리 START -->
                    <div class="row">
                        <div class="col-12 col-lg-6">
                            <h1 class="h3 mb-3">
                                환자관리
                            </h1>
                        </div>
                        <div class="col-12 col-lg-6  text-right">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="javscript:;">Home</a></li>
                                    <li class="breadcrumb-item active">환자관리</li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12">
                            <div class="card">
                                <form action="?" method="get">
                                    <div class="card-body">
                                        <table class="table mobile-table">
                                            <colgroup>
                                                <col style="width:10%">
                                                <col style="width:40%">
                                                <col style="width:10%">
                                                <col style="width:40%">
                                            </colgroup>
                                            <tr>
                                                <th>지역</th>
                                                <td>
                                                    <select class="custom-select form-control" name="locationCode">
                                                        <option value="">전체</option>
                                                        <c:forEach var="i" items="${locationList}">
                                                            <option value="${i.locationCode}" <c:if test="${i.locationCode eq locationCode}"> selected="selected"</c:if>><c:out value="${i.locationName}"/></option>
                                                            
                                                        </c:forEach>
    <!--                                                     <option value="info">서울특별시</option> -->
    <!--                                                     <option value="warning">경기도</option> -->
                                                    </select>
                                                </td>
                                                <th>생활치료센터명</th>
                                                <td>
                                                    <input type="text" class="form-control" name="centerName" placeholder="생활치료센터명" value="<c:out value="${centerName}" />">
                                                </td>
                                            </tr>
                                            <tr>
                                                <th>등록일</th>
                                                <td colspan="3">
                                                    <div class="row">
                                                        <div class="col-lg-4 col-sm-5">
                                                            <div class="form-group calendar-bar mb-xl-0">
                                                                <input class="form-control" type="text" name="startDate">
                                                                <i class="align-middle mr-2 fas fa-fw fa-calendar-alt"></i>
                                                            </div>
                                                        </div>
                                                        <div class="col-lg-2 col-sm-2 text-center">
                                                            ~
                                                        </div>
                                                        <div class="col-lg-4 col-sm-5">
                                                            <div class="form-group calendar-bar mb-xl-0">
                                                                <input class="form-control" type="text" name="endDate">
                                                                <i class="align-middle mr-2 fas fa-fw fa-calendar-alt"></i>
                                                            </div>
                                                        </div>
                                                        <div class="col-sm-12 col-lg-2">
                                                            <button class="btn btn-primary">검색</button>
                                                        </div>
                                                    </div>
                                                </td>
                                            </tr>
                                        </table>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-12">
                            <div class="card">
                                <div class="card-body">
                                    <div class="row mb-3">
                                        <div class="col-6">전체 : 
                                            <fmt:formatNumber value="${total}" pattern="#,###" />
                                        </div>
                                        <div class="col-6 text-right">
                                            <button class="btn btn-primary" onclick="location.href='./new';">생활치료센터 신규 등록</button>
                                        </div>
                                    </div>
                                    <div class="table-responsive">
                                        <table class="table table-striped text-center">
                                            <colgroup>
                                                <col style=" width: 11.1%; ">
                                                <col style=" width: 20%; ">
                                                <col style=" width: 11.1%; ">
                                                <col style=" width: 11.1%; ">
                                                <col style=" width: 11.1%; ">
                                                <col style=" width: 7%; ">
                                                <col style=" width: 7%; ">
                                                <col style=" width: 7%; ">
                                                <col style=" width: 11.1%; ">
                                            </colgroup>
                                            <thead>
                                                <tr>
                                                    <th>번호</th>
                                                    <th>치료센터명</th>
                                                    <th>지역</th>
                                                    <th>담당자(ID)</th>
                                                    <th>전화번호</th>
                                                    <th>입소자 수(명)</th>
                                                    <th>소용인원(명)</th>
                                                    <th>의료진 수</th>
                                                    <th>등록일시</th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <c:choose>
                                                    <c:when test="${total > 0}">
                                                        <c:forEach var="l" items="${item}" varStatus="lStatus">
                                                            <c:set var="viewLink" value="./info?centerCode=${l.centerCode}" />
                                                            <c:set var="pageNum" value="${ ( total - lStatus.index ) - ( (page - 1) * pageSize ) }" />
                                                            
                                                            <tr>
                                                                <td><fmt:formatNumber value="${pageNum}" pattern="#,###" /></td>
                                                                <td>
                                                                    <a href="${viewLink}"><c:out value="${l.centerName}" /></a>
                                                                </td>
                                                                <td><c:out value="${l.locationName}" /></td>
                                                                <td><c:out value="${l.staffName}(${l.staffId})" /></td>
                                                                <td><c:out value="${l.staffPhoneNumber}"></c:out></td>
                                                                <td><c:out value="${l.totalPatient}" /></td>
                                                                <td><c:out value="${l.totalCapacity}" /></td>
                                                                <td><c:out value="${l.totalStaff}" /></td>
                                                                <td><c:out value="${l.createDate}" /></td>
                                                            </tr>
                                                        </c:forEach>
                                                    </c:when>
                                                    <c:otherwise>
                                                        <tr>
                                                            <td colspan="9">등록된 생활치료센터가 없습니다.</td>
                                                        </tr>
                                                    </c:otherwise>
                                                </c:choose>
                                            </tbody>
                                        </table>
                                    </div>
                                    <div class="row mt-5">
                                        <div class="col-12 col-lg-6 mb-2">
                                        </div>
                                        <div class="col-12 col-lg-6 mb-2">
                                            <jsp:include page="${data._INCLUDE}/paging.jsp" flush="true">
                                                <jsp:param name="firstPageNo" value="${paging.firstPageNo}" />
                                                <jsp:param name="prevPageNo"  value="${paging.prevPageNo}" />
                                                <jsp:param name="startPageNo" value="${paging.startPageNo}" />
                                                <jsp:param name="pageNo"      value="${paging.pageNo}" />
                                                <jsp:param name="endPageNo"   value="${paging.endPageNo}" />
                                                <jsp:param name="nextPageNo"  value="${paging.nextPageNo}" />
                                                <jsp:param name="finalPageNo" value="${paging.finalPageNo}" />
                                                <jsp:param name="preFix"      value="${paging.preFix}" />
                                                <jsp:param name="url"         value="${paging.url}" />
                                                <jsp:param name="total"       value="${paging.totalCount}" />
                                            </jsp:include>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- 환자관리 END -->
                </div>
            </main>

            <jsp:include page="${data._INCLUDE}/footer.jsp"></jsp:include>
        </div>
    </div>
</body>
</html>