<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/layout}">
<th:block layout:fragment="script">
    <script th:inline="javascript">
        const commonCode = [[${session.commonCode}]];
    </script>
    <script type="text/javascript" th:src="@{/js/ivsgt/ivsgt.js}"></script>
</th:block>
<div layout:fragment="content">
    <main class="pt-3">
        <h4>사건 보고</h4>
        <input type="hidden" name="_csrf_header" th:value="${_csrf.headerName}"/>
        <input type="hidden" th:name="${_csrf.parameterName}" th:value="${_csrf.token}"/>
        <div class="row mx-0">
            <div class="col-12 card">
                <div class="card-body">
                    <form method="get" th:action="@{/ivsgt/{ivsgtType}(ivsgtType = ${searchParams.ivsgtType})}">
                        <input type="hidden" name="pageIndex" id="pageIndex" th:value="${searchParams.pageIndex}">
                        <input type="hidden" name="dateSelector" value="wrtDt">
                        <input type="hidden" name="ivsgtType" th:value="${searchParams.ivsgtType}">
                        <div class="row justify-content-between pe-3 py-1">
                            <div class="col-auto">
                                <select class="form-select form-select-sm" name="rowCnt" id="rowCnt">
                                    <th:block th:each="num : ${#numbers.sequence(1,5)}">
                                        <option th:value="${num*10}" th:text="${num*10}" th:selected="${searchParams.rowCnt eq num*10}"></option>
                                    </th:block>
                                </select>
                            </div>
                            <div class="col-auto">
                                <div class="row justify-content-end">
                                    <div class="col-auto" sec:authorize="hasRole('ROLE_SUB_ADMIN')">
                                        <select class="form-select form-select-sm" name="wrtOrgan">
                                            <option value="">관서 선택</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                                                <th:block th:if="${#lists.contains(mgtOrganList, commonCode.itemCd)}">
                                                    <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd eq searchParams.wrtOrgan}"></option>
                                                </th:block>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-sm-2">
                                        <select class="form-select form-select-sm" name="arrestCd" id="searchArrestCd">
                                            <option value="">검거유형1 선택</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('AT')}">
                                                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"
                                                        th:selected="${searchParams.arrestCd != null and commonCode.itemCd eq searchParams.arrestCd}"></option>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-sm-2">
                                        <select class="form-select form-select-sm" name="arrestCd2" id="searchArrestCd2">
                                            <option value="">검거유형2 선택</option>
                                            <th:block th:each="num : ${#numbers.sequence(1,#lists.size(session.commonCode.get('AT')))}">
                                                <th:block th:if="${'AT'+num == searchParams.arrestCd}" th:each="commonCode:${session.commonCode.get('AT'+num)}">
                                                    <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.arrestCd2 eq commonCode.itemCd}"></option>
                                                </th:block>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <input type="text" class="form-control form-control-sm" placeholder="제목" name="contentTitle" th:value="${searchParams.contentTitle}">
                                    </div>
                                    <div class="col-auto">
                                        <input type="text" class="form-control form-control-sm" placeholder="작성자" name="wrtNm" th:value="${searchParams.wrtNm}">
                                    </div>
                                    <div class="col-4">
                                        <div class="input-group w-auto input-daterange" id="dateSelectorDiv">
                                            <input type="text" class="form-control form-control-sm" id="startDate" name="startDate" placeholder="시작일" autocomplete="off" readonly th:value="${searchParams.startDate}">
                                            <input type="text" class="form-control form-control-sm" id="endDate" name="endDate" placeholder="종료일" autocomplete="off" readonly th:value="${searchParams.endDate}">
                                        </div>
                                    </div>
                                    <input type="submit" class="btn btn-sm btn-primary col-auto" id="searchBtn" value="검색">
                                </div>
                            </div>
                        </div>
                    </form>
                    <div class="row justify-content-start">
                        <!-- 탭 메뉴 -->
                        <ul class="nav nav-tabs" role="tablist">
                            <li class="nav-item" role="presentation">
                                <button class="nav-link ivsgtTab" th:classappend="${searchParams.ivsgtType eq 'arrest'?' active':''}" id="arrest-tab" data-bs-toggle="tab"
                                        data-bs-target="#arrest" type="button" role="tab" aria-controls="arrest" data-ivsgt-type="arrest"
                                        aria-selected="true">검거보고서</button>
                            </li>
                            <li class="nav-item" role="presentation">
                                <button class="nav-link ivsgtTab" th:classappend="${searchParams.ivsgtType eq 'proceeding'?' active':''}" id="proceeding-tab" data-bs-toggle="tab"
                                        data-bs-target="#proceeding" type="button" role="tab" data-ivsgt-type="proceeding"
                                        aria-controls="proceeding">진행보고서</button>
                            </li>
                            <li class="nav-item" role="presentation">
                                <button class="nav-link ivsgtTab" th:classappend="${searchParams.ivsgtType eq 'result'?' active':''}" id="result-tab" data-bs-toggle="tab"
                                        data-bs-target="#result" type="button" role="tab" data-ivsgt-type="result"
                                        aria-controls="result">결과보고서</button>
                            </li>
                        </ul>

                        <!-- 내용 -->
                        <div class="tab-content">
                            <div class="tab-pane fade show active" id="arrest" role="tabpanel"
                                 aria-labelledby="arrest-tab">
                                <table class="table table-hover table-bordered ws-nowrap">
                                    <thead class="align-middle text-center">
                                    <tr>
                                        <th>문서번호</th>
                                        <th>관서</th>
                                        <th>검거유형1</th>
                                        <th>검거유형2</th>
                                        <th>제목</th>
                                        <th>작성자</th>
                                        <th>작성일</th>
                                    </tr>
                                    </thead>
                                    <tbody class="table-group-divider align-middle text-center">
                                        <tr class="tr" th:each="boardInvestigation:${boardInvestigationList}" th:data-key="${boardInvestigation.ivsgtKey}">
                                            <td th:text="${boardInvestigation.ivsgtKey}"></td>
                                            <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                                                <td th:if="${boardInvestigation.wrtOrgan eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                            </th:block>
                                            <td th:text="${boardInvestigation.arrestCdName}"></td>
                                            <td th:text="${boardInvestigation.arrestCd2Name}"></td>
                                            <td th:text="${boardInvestigation.contentStatus == 'Y' ? '[임시저장]' : ''} + ${boardInvestigation.contentTitle}"></td>
                                            <td th:text="${boardInvestigation.wrtNm}"></td>
                                            <td th:text="${#temporals.format(boardInvestigation.wrtDt, 'yyyy-MM-dd')}"></td>
                                        </tr>
                                    </tbody>
                                </table>
                                <button class="btn btn-sm btn-primary" id="ivsgtAddBtn">등록</button>
                            </div>
                            <div class="tab-pane fade" id="proceeding" role="tabpanel"
                                 aria-labelledby="proceeding-tab">진행보고서</div>
                            <div class="tab-pane fade" id="result" role="tabpanel"
                                 aria-labelledby="result-tab">결과보고서</div>
                        </div>
                    </div>
                    <!-- 페이징 -->
                    <div class="row justify-content-center">
                        <div class="col-auto">
                            <nav aria-label="Page navigation">
                                <ul class="pagination">
                                    <th:block th:if="${searchParams.pageIndex>3}">
                                        <li class="page-item" th:data-pageindex="${(searchParams.pageIndex)-3}">
                                            <a class="page-link" href="#" aria-label="Previous">
                                                <span aria-hidden="true">&laquo;</span>
                                            </a>
                                        </li>
                                    </th:block>
                                    <th:block th:each="num : ${#numbers.sequence(searchParams.startNum, searchParams.endNum)}">
                                        <li class="page-item" th:data-pageindex="${num}" th:classappend="${searchParams.pageIndex eq num?'active':''}">
                                            <a class="page-link" href="#" th:text="${num}"></a>
                                        </li>
                                    </th:block>
                                    <th:block th:if="${searchParams.maxNum>searchParams.endNum+2}">
                                        <li class="page-item" th:data-pageindex="${(searchParams.pageIndex)+3}">
                                            <a class="page-link" href="#" aria-label="Next">
                                                <span aria-hidden="true">&raquo;</span>
                                            </a>
                                        </li>
                                    </th:block>
                                </ul>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="ivsgtEditModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="ivsgtEditModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-xl modal-dialog-scrollable">
                <div class="modal-content" id="ivsgtEditModalContent">

                </div>
            </div>
        </div>
        <div class="modal fade" id="ivsgtViewModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="ivsgtViewModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-xl modal-dialog-scrollable">
                <div class="modal-content" id="ivsgtViewBody">

                </div>
            </div>
        </div>
    </main>
</div>
</html>