<%@ 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" %>

<script src="<c:url value="/js/admin/userinfo.js"/>"></script>


<div class="section_title">
    <!-- <p>현장 지원 시스템</p> -->
</div>
<div class="section_content">
    <h1 class="h4 m-3">회원관리</h1>
    <form:form commandName="userSearchVO" name="searchForm" action="/admin/userInfo" method="get">

        <div class="row justify-content-between bg-white mx-3 py-2">
            <div class="col-auto">
                <ul class="nav nav-pills ms-2" role="tablist">
                    <li role="presentation" class="nav-item">
                      <a class="nav-link ${userSearchVO.auth eq '99'?'active':''}" href="/admin/userInfo?auth=99">승인대기(${standByCount})</a>
                    </li>
                    <li role="presentation" class="nav-item">
                      <a class="nav-link ${empty userSearchVO.auth?'active':''}" href="/admin/userInfo">회원 관리</a>
                    </li>
                </ul>
                <input type="hidden" name="auth" value="${userSearchVO.auth}"/>
            </div>

            <div class="col-auto row">
                <div class="col-auto">
                    <select class="form-select" name="searchCondition">
                        <option value="all" ${userSearchVO.searchCondition eq 'all'?'selected':''}>통합검색</option>
                        <option value="name" ${userSearchVO.searchCondition eq 'name'?'selected':''}>이름</option>
                        <option value="company" ${userSearchVO.searchCondition eq 'company'?'selected':''}>소속</option>
                        <option value="email" ${userSearchVO.searchCondition eq 'email'?'selected':''}>이메일</option>
                        <option value="phonenum" ${userSearchVO.searchCondition eq 'phonenum'?'selected':''}>전화번호</option>
                    </select>
                </div>

                <div class="col-auto">
                    <input type="text" class="form-control" name="searchKeyword" value="${userSearchVO.searchKeyword}"/>
                </div>
                <div class="col-auto">
                    <input class="btn btn-outline-secondary" type="submit" value="검색"/>
                </div>
            </div>
        </div>


        <div class="row m-3 p-2 bg-white">
            <table class="table table-hover text-center">
                <thead>
                <tr>
                    <th>아이디</th>
                    <th>이름</th>
                    <th>소속</th>
                    <th>전화번호</th>
                    <th>이메일</th>
                    <th>가입일</th>
                    <th>${userSearchVO.auth eq '99'?'상태':'권한'}</th>
                </tr>
                </thead>
                <tbody>
                <c:if test="${count >= 1}">
                    <c:forEach var="user" items="${userList}" varStatus="idx">
                        <tr>
                            <td class="clickAbleObj userInfoModalBtn useridTd"><c:out value='${user.userid}'/></td>
                            <td class="clickAbleObj userInfoModalBtn"><c:out value='${user.name}'/></td>
                            <td class="clickAbleObj userInfoModalBtn"><c:out value='${user.company}'/></td>
                            <td class="clickAbleObj userInfoModalBtn"><c:out value='${user.phonenum}'/></td>
                            <td class="clickAbleObj userInfoModalBtn"><c:out value='${user.email}'/></td>
                            <td class="clickAbleObj userInfoModalBtn td_date"><c:out value='${user.regdate}'/></td>
                            <td>
                                <c:choose>
                                    <c:when test="${user.auth eq '1'}">관리자</c:when>
                                    <c:when test="${user.auth eq '2'}">사용자</c:when>
                                    <c:when test="${user.auth eq '99'}">
                                        <input type="button" class="btn btn-outline-success" value="승인"
                                               onclick="confirmBtn('${user.userid}','2'); return false;"/>
                                        <input type="button" class="btn btn-outline-danger" value="삭제"
                                               onclick="confirmBtn('${user.userid}','-1'); return false;"/>
                                    </c:when>
                                </c:choose>
                            </td>
                        </tr>
                    </c:forEach>
                </c:if>
                <c:if test="${count == 0}">
                    <tr>
                        <td colspan="7">요청한 목록이 없습니다.</td>
                    </tr>
                </c:if>
                </tbody>
            </table>
        </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>

    <form:form commandName="userVO" id="updateFrm" method="post" action="/admin/userSign">
        <input type="hidden" id="userid" name="userid"/>
        <input type="hidden" id="auth" name="auth"/>
    </form:form>
</div>

<div class="modal fade" id="userInfoModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1"
     aria-labelledby="userInfoModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="userInfoModalLabel">회원 정보 수정</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" id="userInfoModalBody">

            </div>
        </div>
    </div>
</div>