<!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/sailor.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/sailor}" id="sailorSearchForm">
                        <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">
                                        <select class="form-select form-select-sm" name="crackdownPolice">
                                            <option value="">단속경찰서</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('CPO')}">
                                                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"
                                                        th:selected="${commonCode.itemCd eq searchParams.crackdownPolice}"></option>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="crackdownBoat">
                                            <option value="">단속함정</option>
                                            <th:block th:each="num : ${#numbers.sequence(1,#lists.size(session.commonCode.get('CPO')))}">
                                                <th:block th:if="${'CPO'+num == searchParams.crackdownPolice}" th:each="commonCode:${session.commonCode.get('CPO'+num)}">
                                                    <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}" th:selected="${searchParams.crackdownBoat 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="sailorNameKr" th:value="${searchParams.sailorNameKr}">
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="residence">
                                            <option value="">거주지</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('RSC')}">
                                                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"
                                                        th:selected="${commonCode.itemCd eq searchParams.residence}"></option>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="education">
                                            <option value="">학력</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('SED')}">
                                                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"
                                                        th:selected="${commonCode.itemCd eq searchParams.education}"></option>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="position">
                                            <option value="">선박 내 직책</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('POS')}">
                                                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"
                                                        th:selected="${commonCode.itemCd eq searchParams.position}"></option>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="career">
                                            <option value="">승선경력</option>
                                            <th:block th:each="commonCode:${session.commonCode.get('BE')}">
                                                <option th:value="${commonCode.itemCd}" th:text="${commonCode.itemValue}"
                                                        th:selected="${commonCode.itemCd eq searchParams.career}"></option>
                                            </th:block>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="similarCriminalHistory">
                                            <option value="">동종 범죄경력</option>
                                            <option value="1" th:selected="${searchParams.similarCriminalHistory == 1}">1건</option>
                                            <option value="2" th:selected="${searchParams.similarCriminalHistory == 2}">2건</option>
                                            <option value="3" th:selected="${searchParams.similarCriminalHistory == 3}">3건</option>
                                            <option value="4" th:selected="${searchParams.similarCriminalHistory == 4}">4이상</option>
                                            <option value="0" th:selected="${searchParams.similarCriminalHistory == 0}">없음</option>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="heterogeneousCriminalHistory">
                                            <option value="">이종 범죄경력</option>
                                            <option value="1" th:selected="${searchParams.heterogeneousCriminalHistory == 1}">1건</option>
                                            <option value="2" th:selected="${searchParams.heterogeneousCriminalHistory == 2}">2건</option>
                                            <option value="3" th:selected="${searchParams.heterogeneousCriminalHistory == 3}">3건</option>
                                            <option value="4" th:selected="${searchParams.heterogeneousCriminalHistory == 4}">4이상</option>
                                            <option value="0" th:selected="${searchParams.heterogeneousCriminalHistory == 0}">없음</option>
                                        </select>
                                    </div>
                                    <div class="col-auto">
                                        <select class="form-select form-select-sm" name="arrestHistory">
                                            <option value="">검거이력</option>
                                            <option value="1" th:selected="${searchParams.arrestHistory == 1}">1건</option>
                                            <option value="2" th:selected="${searchParams.arrestHistory == 2}">2건</option>
                                            <option value="3" th:selected="${searchParams.arrestHistory == 3}">3건</option>
                                            <option value="4" th:selected="${searchParams.arrestHistory == 4}">4이상</option>
                                            <option value="0" th:selected="${searchParams.arrestHistory == 0}">없음</option>
                                        </select>
                                    </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="sailorTable">
                            <thead class="align-middle text-center">
                            <tr>
                                <th rowspan="2">연번</th>
                                <th rowspan="2">선박명</th>
                                <th rowspan="2">나포일시</th>
                                <th rowspan="2">단속경찰서</th>
                                <th rowspan="2">단속함정</th>
                                <th rowspan="2">위반장소</th>
                                <th rowspan="2">위반내용</th>
                                <th colspan="2">선원명</th>
                                <th rowspan="2">생년월일</th>
                                <th colspan="17">거주지(성기준)</th>
                                <th colspan="9">학력</th>
                                <th colspan="5">선박 내 직책</th>
                                <th colspan="6">승선경력</th>
                                <th colspan="5">동종 범죄경력</th>
                                <th colspan="5">이종 범죄경력</th>
                                <th colspan="5">검거이력<br>(나포이력, 선원 포함)</th>
                                <th rowspan="2">범죄경력<br>세부내용</th>
                                <th rowspan="2">임금<br>(월급여)</th>
                                <th rowspan="2">비고</th>
                                <th rowspan="2">최종수정일</th>
                            </tr>
                            <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>
                                <th>섬서성</th>
                                <th>절강성</th>
                                <th>강동성</th>
                                <th>기타</th>
                                <th>확인불가</th>
                                <th>초등<br>중퇴</th>
                                <th>초등<br>졸업</th>
                                <th>중등<br>중퇴</th>
                                <th>중등<br>졸업</th>
                                <th>고등<br>중퇴</th>
                                <th>고등<br>졸업</th>
                                <th>대학<br>중퇴</th>
                                <th>대졸<br>이상</th>
                                <th>확인<br>불가</th>
                                <th>선장</th>
                                <th>항해장</th>
                                <th>기관장</th>
                                <th>기타<br>간부선원</th>
                                <th>일반선원<br>또는<br>확인불가</th>
                                <th>1년미만</th>
                                <th>1년이상<br>~<br>3년미만</th>
                                <th>3년이상<br>~<br>5년미만</th>
                                <th>5년이상<br>~<br>10년미만</th>
                                <th>10년이상</th>
                                <th>확인불가</th>
                                <th>1건</th>
                                <th>2건</th>
                                <th>3건</th>
                                <th>4건<br>이상</th>
                                <th>없음</th>
                                <th>1건</th>
                                <th>2건</th>
                                <th>3건</th>
                                <th>4건<br>이상</th>
                                <th>없음</th>
                                <th>1건</th>
                                <th>2건</th>
                                <th>3건</th>
                                <th>4건<br>이상</th>
                                <th>없음</th>
                            </tr>
                            </thead>
                            <tbody class="table-group-divider align-middle text-center">
                                <th:block th:each="sailor:${sailorList}">
                                    <tr class="tr" th:data-key="${sailor.sailorKey}">
                                        <td th:text="${sailor.sailorKey}"></td>
                                        <td th:text="${sailor.fishingBoat.boatNameKr}"></td>
                                        <td th:text="${#temporals.format(sailor.crackdownStatus.napoDt, 'yyyy-MM-dd HH:mm')}"></td>
                                        <th:block th:each="commonCode:${session.commonCode.get('CPO')}">
                                            <td th:if="${sailor.crackdownStatus.crackdownPolice eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                        </th:block>
                                        <th:block th:if="${!#strings.contains(sailor.crackdownStatus.crackdownPolice, 'CPO')}">
                                            <td th:text="${sailor.crackdownStatus.crackdownPolice}"></td>
                                        </th:block>
                                        <th:block th:each="num : ${#numbers.sequence(1,#lists.size(session.commonCode.get('CPO')))}">
                                            <th:block th:if="${'CPO'+num == sailor.crackdownStatus.crackdownPolice}" th:each="commonCode:${session.commonCode.get('CPO'+num)}">
                                                <td th:if="${sailor.crackdownStatus.crackdownBoat eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></td>
                                            </th:block>
                                        </th:block>
                                        <th:block th:if="${!#strings.contains(sailor.crackdownStatus.crackdownBoat, 'CPO')}">
                                            <td></td>
                                        </th:block>
                                        <td>
                                            <span th:text="${sailor.crackdownStatus.napoSeaPointLon}"> ~ </span>
                                            <span th:text="${sailor.crackdownStatus.napoSeaPointLat}"></span>
                                            <div th:text="${sailor.crackdownStatus.napoSeaPointDetail}"></div>
                                        </td>
                                        <td>
                                            <th:block th:if="${#lists.size(sailor.violationList) >= 1}">
                                                <th:block th:each="violation:${sailor.violationList}">
                                                    <th:block th:each="commonCode:${session.commonCode.get('VT')}">
                                                        <div th:if="${violation.violation eq commonCode.itemCd}" th:text="${commonCode.itemValue}"></div>
                                                    </th:block>
                                                </th:block>
                                            </th:block>
                                        </td>
                                        <td th:text="${sailor.sailorNameKr}"></td>
                                        <td th:text="${sailor.sailorNameCn}"></td>
                                        <td th:text="${sailor.birthdate}"></td>
                                        <td th:text="${sailor.residence == 'RSC001' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC002' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC003' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC004' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC005' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC006' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC007' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC008' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC009' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC010' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC011' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC012' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC013' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC014' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC015' ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence ne '' && sailor.residence ne null && !#strings.contains(sailor.residence, 'RSC') ? 1 : 0}"></td>
                                        <td th:text="${sailor.residence == 'RSC016' ? 1 : 0}"></td>
                                        <td th:text="${sailor.education == 'SED001' ? 1 : 0}"></td>
                                        <td th:text="${sailor.education == 'SED002' ? 1 : 0}"></td>
                                        <td th:text="${sailor.education == 'SED003' ? 1 : 0}"></td>
                                        <td th:text="${sailor.education == 'SED004' ? 1 : 0}"></td>
                                        <td th:text="${sailor.education == 'SED005' ? 1 : 0}"></td>
                                        <td th:text="${sailor.education == 'SED006' ? 1 : 0}"></td>
                                        <td th:text="${sailor.education == 'SED007' ? 1 : 0}"></td>
                                        <td th:text="${sailor.education == 'SED008' ? 1 : 0}"></td>
                                        <td th:text="${sailor.education == 'SED009' ? 1 : 0}"></td>
                                        <td th:text="${sailor.position eq 'POS001' ? 1 : 0}"></td>
                                        <td th:text="${sailor.position eq 'POS002' ? 1 : 0}"></td>
                                        <td th:text="${sailor.position eq 'POS003' ? 1 : 0}"></td>
                                        <td th:text="${sailor.position eq 'POS005' ? 1 : 0}"></td>
                                        <td th:text="${sailor.position eq 'POS006' ? 1 : 0}"></td>
                                        <td th:text="${sailor.career == 'BE001' ? 1 : 0}"></td>
                                        <td th:text="${sailor.career == 'BE002' ? 1 : 0}"></td>
                                        <td th:text="${sailor.career == 'BE003' ? 1 : 0}"></td>
                                        <td th:text="${sailor.career == 'BE004' ? 1 : 0}"></td>
                                        <td th:text="${sailor.career == 'BE005' ? 1 : 0}"></td>
                                        <td th:text="${sailor.career == 'BE006' ? 1 : 0}"></td>
                                        <td th:text="${sailor.similarCriminalHistory == 1 ? 1 : 0}"></td>
                                        <td th:text="${sailor.similarCriminalHistory == 2 ? 1 : 0}"></td>
                                        <td th:text="${sailor.similarCriminalHistory == 3 ? 1 : 0}"></td>
                                        <td th:text="${sailor.similarCriminalHistory > 3 ? 1 : 0}"></td>
                                        <td th:text="${sailor.similarCriminalHistory == 0 ? 1 : 0}"></td>
                                        <td th:text="${sailor.heterogeneousCriminalHistory == 1 ? 1 : 0}"></td>
                                        <td th:text="${sailor.heterogeneousCriminalHistory == 2 ? 1 : 0}"></td>
                                        <td th:text="${sailor.heterogeneousCriminalHistory == 3 ? 1 : 0}"></td>
                                        <td th:text="${sailor.heterogeneousCriminalHistory > 3 ? 1 : 0}"></td>
                                        <td th:text="${sailor.heterogeneousCriminalHistory == 0 ? 1 : 0}"></td>
                                        <td th:text="${sailor.arrestHistory == 1 ? 1 : 0}"></td>
                                        <td th:text="${sailor.arrestHistory == 2 ? 1 : 0}"></td>
                                        <td th:text="${sailor.arrestHistory == 3 ? 1 : 0}"></td>
                                        <td th:text="${sailor.arrestHistory > 3 ? 1 : 0}"></td>
                                        <td th:text="${sailor.arrestHistory == 0 ? 1 : 0}"></td>
                                        <td th:text="${sailor.criminalHistoryDetail}"></td>
                                        <td th:text="${sailor.monthlyWages}"></td>
                                        <td th:text="${sailor.note}"></td>
                                        <td th:text="${#temporals.format(sailor.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="sailorDownExcel">엑셀 다운로드</button>
                        <button class="btn btn-sm btn-primary col-auto" id="sailorAddBtn">등록</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="modal fade" id="sailorAddModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="sailorAddModalLabel" aria-hidden="true">
            <div class="modal-dialog modal-xl modal-dialog-scrollable">
                <div class="modal-content" id="sailorAddModalContent">

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

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

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