<!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/faStatistics/processResult.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/processResult}" id="processResultSearchForm">
                        <div class="row justify-content-between pe-3 py-1">
                            <div class="col-auto">
                                <div class="col-auto">
                                    <select class="form-select form-select-sm" name="year">
                                        <option value="">연도</option>
                                        <th:block th:each="year : ${#numbers.sequence(2020, 2030)}">
                                            <option th:value="${year + '-01-01'}" th:text="${year}" th:selected="${searchParams.year eq year}"></option>
                                        </th:block>
                                    </select>
                                </div>
                            </div>
                            <div class="col-10">
                                <div class="row justify-content-end">
                                    <div class="col-auto">
                                        <input type="text" class="form-control form-control-sm" placeholder="사건번호" name="sailorNameKr" th:value="${searchParams.caseNum}">
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="crackdownPolice" id="crackdownPolice">
                                            <option value="">사건담당경찰서</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('CPO')}">
                                                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"
                                                        th:selected="${searchParams.crackdownPolice eq commonCode.itemCd}"></option>
                                            </th:block>
                                            <option value="etc" th:selected="${searchParams.crackdownPolice ne '' && searchParams.crackdownPolice ne null && !#strings.contains(searchParams.crackdownPolice, 'CPO')}">직접입력</option>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <input class="form-control form-control-sm" name="boatNameKr" id="boatNameKr" placeholder="피의자(선박명)" th:value="${searchParams.boatNameKr}">
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm violation" name="violation">
                                            <option value="">위반내용</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('VT')}">
                                                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"
                                                        th:selected="${commonCode.itemCd eq searchParams.violation}"></option>></option>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <input class="form-control form-control-sm" name="sentencingCourt" id="sentencingCourt" placeholder="선고법원" th:value="${searchParams.sentencingCourt}">
                                    </div>
                                    <div class="col-auto">
                                        <input class="form-control form-control-sm" name="sentencingDetail" id="sentencingDetail" placeholder="선고내용" th:value="${searchParams.sentencingDetail}">
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="executionDetail" id="executionDetail">
                                            <option value="">선택</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('PR')}">
                                                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"
                                                        th:selected="${commonCode.itemCd eq searchParams.executionDetail}"></option>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <input class="form-control form-control-sm" name="returnDt" id="returnDate" placeholder="환부일" th:value="${#temporals.format(searchParams.returnDt, 'yyyy-MM-dd')}">
                                    </div>
                                    <div class="col-auto">
                                        <input class="form-control form-control-sm" name="consignmentStartDt" id="consignmentStartDate" placeholder="위탁시작일" th:value="${#temporals.format(searchParams.consignmentStartDt, 'yyyy-MM-dd')}">
                                    </div>
                                    <div class="col-auto">
                                        <input class="form-control form-control-sm" name="consignmentEndDt" id="consignmentEndDate" placeholder="위탁종료일" th:value="${#temporals.format(searchParams.consignmentEndDt, 'yyyy-MM-dd')}">
                                    </div>
                                    <div class="col-auto">
                                        <input class="form-control form-control-sm" name="confiscationDt" id="confiscationDate" placeholder="몰수확정일" th:value="${#temporals.format(searchParams.confiscationDt, 'yyyy-MM-dd')}">
                                    </div>
                                    <div class="col-auto">
                                        <input class="form-control form-control-sm" name="boatDisposalDt" id="boatDisposalDate" placeholder="폐선일" th:value="${#temporals.format(searchParams.boatDisposalDt, 'yyyy-MM-dd')}">
                                    </div>
                                </div>
                            </div>
                            <div class="col-auto">
                                <input type="submit" class="btn btn-sm btn-primary col-auto" id="searchBtn" value="검색">
                            </div>
                        </div>
                    </form>
                    <div class="row justify-content-start" style="overflow: hidden; overflow-x: scroll">
                        <table class="table table-hover table-bordered ws-nowrap" style="max-width: none; width: auto;" id="prTable">
                            <thead class="align-middle text-center">
                            <tr>
                                <th>연번</th>
                                <th>사건번호</th>
                                <th>사건담당경찰서</th>
                                <th>피의자(선박명)</th>
                                <th>위반장소 및 내용</th>
                                <th>선고내용</th>
                                <th>선고법원</th>
                                <th>집행내용</th>
                                <th>환부일</th>
                                <th>위탁시작일</th>
                                <th>위탁종료일</th>
                                <th>몰수확정일</th>
                                <th>폐선일(인계한 날짜)</th>
                                <th>최종수정일</th>
                            </tr>
                            </thead>
                            <tbody class="table-group-divider align-middle text-center">
                                <th:block th:each="processResult:${processResultList}">
                                    <tr class="tr" th:data-key="${processResult.prKey}">
                                        <td th:text="${processResult.prKey}"></td>
                                        <td th:text="${processResult.crackdownStatus.caseNum}"></td>
                                        <th:block th:each="commonCode:${session.commonCode.get('CPO')}">
                                            <td th:if="${processResult.crackdownStatus.crackdownPolice eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                        </th:block>
                                        <th:block th:if="${!#strings.contains(processResult.crackdownStatus.crackdownPolice, 'CPO')}">
                                            <td th:text="${processResult.crackdownStatus.crackdownPolice}"></td>
                                        </th:block>
                                        <td th:text="${processResult.boatNameKr}"></td>
                                        <td>
                                            <span th:text="${processResult.crackdownStatus.napoSeaPointLon}"></span>
                                            <span th:if="${processResult.crackdownStatus.napoSeaPointLon ne null && processResult.crackdownStatus.napoSeaPointLon ne ''}" th:text="${' ~ '}"></span>
                                            <span th:text="${processResult.crackdownStatus.napoSeaPointLat}"></span>
                                            <div th:text="${processResult.crackdownStatus.napoSeaPointDetail}"></div>
                                            <th:block th:if="${#lists.size(processResult.violationList) >= 1}">
                                                <div>
                                                <th:block th:each="violation, i:${processResult.violationList}">
                                                    <th:block th:each="commonCode:${session.commonCode.get('VT')}">
                                                        <span th:if="${violation.violation eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></span>
                                                    </th:block>
                                                    <span th:if="${violation.violation ne null && !#strings.contains(violation.violation, 'VT')}" th:text="${violation.violation}"></span>
                                                    <th:block th:if="${#lists.size(processResult.violationList) >= 1 && i.index < #lists.size(processResult.violationList)-1}">
                                                        <span>, </span>
                                                    </th:block>
                                                </th:block>
                                                </div>
                                            </th:block>
                                        </td>
                                        <td th:text="${processResult.sentencingCourt}"></td>
                                        <td th:text="${processResult.sentencingDetail}"></td>
                                        <th:block th:each="commonCode:${session.commonCode.get('PR')}">
                                            <th:block th:if="${processResult.executionDetail ne null && #strings.contains(processResult.executionDetail, 'PR')}">
                                                <td th:if="${processResult.executionDetail eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                            </th:block>
                                        </th:block>
                                        <td th:if="${processResult.executionDetail ne null && !#strings.contains(processResult.executionDetail, 'PR')}" th:text="${processResult.executionDetail}"></td>
                                        <th:block th:if="${processResult.executionDetail eq null}">
                                            <td></td>
                                        </th:block>
                                        <td th:text="${processResult.returnDt}"></td>
                                        <td th:text="${processResult.consignmentStartDt}"></td>
                                        <td th:text="${processResult.consignmentEndDt}"></td>
                                        <td th:text="${processResult.confiscationDt}"></td>
                                        <td th:text="${processResult.boatDisposalDt}"></td>
                                        <td th:text="${#temporals.format(processResult.updDt, 'yyyy-MM-dd HH:mm')}"></td>
                                    </tr>
                                </th:block>
                            </tbody>
                        </table>
                    </div>
                    <div class="row justify-content">
                        <button class="btn btn-sm btn-primary col-auto" id="processResultDownExcel">엑셀 다운로드</button>
                        <button class="btn btn-sm btn-primary col-auto" id="processResultAddBtn">등록</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="processResultAddModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="processResultAddModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-xl modal-dialog-scrollable">
                <div class="modal-content" id="processResultAddModalContent">

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

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

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