<!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 internationalCrimeArrest = [[${internationalCrimeArrest}]];
        const commonCode = [[${session.commonCode}]];
        const organConfigList = [[${organConfigList}]];
    </script>
    <script type="text/javascript" th:src="@{/js/faStatistics/internationalCrimeArrest.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="@{/faStatistics/internationalCrimeArrest}" id="icaSearchForm">
                        <input type="hidden" name="pageIndex" id="pageIndex" th:value="${searchParams.pageIndex}">
                        <input type="hidden" name="dateSelector" value="wrtDt">
                        <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">
                                        <input type="text" class="form-control form-control-sm" placeholder="사건번호" name="caseNum" th:value="${searchParams.caseNum}">
                                    </div>
                                    <div class="col-auto" sec:authorize="hasRole('ROLE_SUB_ADMIN')">
                                        <select class="form-select form-select-sm" name="organ">
                                            <option value="">지방청 선택</option>
                                            <th:block th:each="organConfig:${organConfigList}">
                                                <th:block th:if="${organConfig.parentOrgan eq 'OG001' && organConfig.organType ne 'OGC001'}">
                                                    <option th:value="${organConfig.organCd}" th:text="${organConfig.organNm}" th:selected="${organConfig.organCd eq searchParams.organ}"></option>
                                                </th:block>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-auto" id="departmentDiv">
                                        <select class="form-select form-select-sm" name="department">
                                            <option value="">경찰서 선택</option>
                                            <th:block th:each="organConfig:${organConfigList}">
                                                <th:block th:if="${organConfig.parentOrgan ne null && organConfig.organType ne 'OGC002'}">
                                                    <option th:value="${organConfig.organCd}" th:text="${organConfig.organNm}" th:selected="${organConfig.organCd eq searchParams.department}"></option>
                                                </th:block>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="crimeType" id="searchCrimeType">
                                            <option value="">범죄테마 선택</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('CTH')}">
                                                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${commonCode.itemCd eq searchParams.crimeType}"></option>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="violationType" id="searchViolationType">
                                            <option value="">위반유형 선택</option>
                                            <th:block th:each="num : ${#numbers.sequence(1,#lists.size(session.commonCode.get('CTH')))}">
                                                <th:block th:each="commonCode:${session.commonCode.get('CTH'+num)}">
                                                    <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${internationalCrimeArrest.violationType 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="crimeName" th:value="${searchParams.crimeName}">
                                    </div>
                                    <div class="col-auto">
                                        <input type="text" class="form-control form-control-sm" placeholder="발생원표" name="occurTable" th:value="${searchParams.occurTable}">
                                    </div>
                                    <div class="col-auto">
                                        <input type="text" class="form-control form-control-sm" placeholder="검거원표" name="arrestTable" th:value="${searchParams.arrestTable}">
                                    </div>
                                    <div class="col-auto">
                                        <input type="text" class="form-control form-control-sm" placeholder="피의자원표" name="suspectTable" th:value="${searchParams.suspectTable}">
                                    </div>
                                    <div class="col-auto">
                                        <div class="col-auto input-daterange" id="searchCrimeAwarenessDtDiv">
                                            <input type="text" class="form-control form-control-sm" placeholder="범죄인지" name="crimeAwarenessDt" id="crimeAwarenessDt" th:value="${#temporals.format(searchParams.crimeAwarenessDt, 'yyyy-MM-dd')}">
                                        </div>
                                    </div>
                                    <div class="col-auto">
                                        <div class="col-auto input-daterange" id="searchCaseSentDtDiv">
                                            <input type="text" class="form-control form-control-sm" placeholder="사건송치" name="caseSentDt" id="caseSentDt" th:value="${#temporals.format(searchParams.caseSentDt, 'yyyy-MM-dd')}">
                                        </div>
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="processResult" id="processResult">
                                            <option value="">신병처리 선택</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('PCR')}">
                                                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"
                                                        th:selected="${commonCode.itemCd eq searchParams.processResult}"></option>
                                            </th:block>
                                        </select>
                                    </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="tab-pane fade show active" id="ica" role="tabpanel"
                         aria-labelledby="arrest-tab">
                        <table class="table table-hover table-bordered ws-nowrap" id="ivsgtTable">
                            <thead class="align-middle text-center">
                                <tr>
                                    <th rowspan="2">지방청</th>
                                    <th rowspan="2">경찰서</th>
                                    <th rowspan="2">
                                        <div>범죄테마</div>
                                        <div>(대분류)</div>
                                    </th>
                                    <th rowspan="2">
                                        <div>위반유형</div>
                                        <div>(중분류)</div>
                                    </th>
                                    <th rowspan="2">
                                        <div>죄명</div>
                                        <div>(소분류)</div>
                                    </th>
                                    <th rowspan="2">발생원표</th>
                                    <th rowspan="2">검거원표</th>
                                    <th rowspan="2">피의자원표</th>
                                    <th colspan="3">피의자 인적사항</th>
                                    <th rowspan="2">범죄인지</th>
                                    <th rowspan="2">사건송치</th>
                                    <th rowspan="2">신병처리</th>
                                </tr>
                                <tr>
                                    <th>성별</th>
                                    <th>나이</th>
                                    <th>국적</th>
                                </tr>
                            </thead>
                            <tbody class="table-group-divider">
                                <th:block th:each="internationalCrimeArrest:${internationalCrimeArrestList}">
                                    <tr class="tr" th:data-key="${internationalCrimeArrest.icaKey}">
                                        <th:block th:if="${internationalCrimeArrest.organ eq null || internationalCrimeArrest.organ eq ''}">
                                            <td></td>
                                        </th:block>
                                        <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                                            <td th:if="${internationalCrimeArrest.organ eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                        </th:block>
                                        <th:block th:if="${internationalCrimeArrest.department eq null || internationalCrimeArrest.department eq ''}">
                                            <td></td>
                                        </th:block>
                                        <th:block th:each="commonCode:${session.commonCode.get('OG')}">
                                            <td th:if="${internationalCrimeArrest.department eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                        </th:block>
                                        <th:block th:if="${internationalCrimeArrest.crimeType eq null || internationalCrimeArrest.crimeType eq ''}">
                                            <td></td>
                                        </th:block>
                                        <th:block th:each="commonCode:${session.commonCode.get('CTH')}">
                                            <td th:if="${internationalCrimeArrest.crimeType eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                        </th:block>
                                        <th:block th:each="num : ${#numbers.sequence(1,#lists.size(session.commonCode.get('CTH')))}">
                                            <th:block th:each="commonCode:${session.commonCode.get('CTH'+num)}">
                                                <td th:if="${internationalCrimeArrest.violationType eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                            </th:block>
                                        </th:block>
                                        <th:block th:if="${internationalCrimeArrest.violationType eq null || internationalCrimeArrest.violationType eq ''}">
                                            <td></td>
                                        </th:block>
                                        <td th:text="${internationalCrimeArrest.crimeName}"></td>
                                        <td th:text="${internationalCrimeArrest.occurTable}"></td>
                                        <td th:text="${internationalCrimeArrest.arrestTable}"></td>
                                        <td th:text="${internationalCrimeArrest.suspectTable}"></td>
                                        <th:block th:if="${#lists.size(internationalCrimeArrest.suspectPersonInfoList) < 1}">
                                            <td></td>
                                            <td></td>
                                            <td></td>
                                        </th:block>
                                        <td colspan="3" th:if="${#lists.size(internationalCrimeArrest.suspectPersonInfoList) >= 1}">
                                            <table>
                                                <tr class="tr" th:each="suspectPersonInfo:${internationalCrimeArrest.suspectPersonInfoList}">
                                                    <th:block th:each="commonCode:${session.commonCode.get('SEX')}">
                                                        <td th:if="${suspectPersonInfo.sex eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                                    </th:block>
                                                    <th:block th:each="commonCode:${session.commonCode.get('AGE')}">
                                                        <td th:if="${suspectPersonInfo.age eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                                    </th:block>
                                                    <th:block th:each="commonCode:${session.commonCode.get('NNY')}">
                                                        <td th:if="${suspectPersonInfo.country eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                                    </th:block>
                                                    <th:block th:if="${suspectPersonInfo.country ne null && !#strings.contains(suspectPersonInfo.country, 'NNY')}">
                                                        <td th:text="${suspectPersonInfo.country}"></td>
                                                    </th:block>
                                                </tr>
                                            </table>
                                        </td>
                                        <td th:text="${#temporals.format(internationalCrimeArrest.crimeAwarenessDt, 'yyyy-MM-dd')}"></td>
                                        <td th:text="${#temporals.format(internationalCrimeArrest.caseSentDt, 'yyyy-MM-dd')}"></td>
                                        <th:block th:if="${internationalCrimeArrest.processResult eq null}">
                                            <td></td>
                                        </th:block>
                                        <th:block th:each="commonCode:${session.commonCode.get('PCR')}">
                                            <td th:if="${internationalCrimeArrest.processResult eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                        </th:block>
                                        <th:block th:if="${internationalCrimeArrest.processResult ne null && !#strings.contains(internationalCrimeArrest.processResult, 'PCR')}">
                                            <td th:text="${internationalCrimeArrest.processResult}"></td>
                                        </th:block>
                                    </tr>
                                </th:block>
                            </tbody>
                        </table>
                        <button class="btn btn-sm btn-primary col-auto" id="ivsgtAddBtn">관리자마감</button>
                        <button class="btn btn-sm btn-primary col-auto" id="icaExcelDownBtn">엑셀 다운로드</button>
                        <button class="btn btn-sm btn-primary col-auto" id="icaAddBtn">등록</button>
                    </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="icaEditModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="icaEditModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-xl modal-dialog-scrollable">
                <div class="modal-content" id="icaEditModalContent">

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

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