<!DOCTYPE html>
<html lang="ko" xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorate="~{layout/layout}">
<th:block layout:fragment="script">
  <script type="text/javascript" th:src="@{/js/igActivities/fpiMgt/affair/statistics.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 text-center">
        <div class="card-body">
        <div class="col-auto">
        <button id="downExcel">엑셀다운</button>
        </div>
          <div class="tab-content border border-top-0 p-2">
            <form id="searchFm" method="get" th:action="@{/affair/statistics}">
              <div class="row pe-3 py-1">
                <div class="col-auto">
                  <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>
                    <div class="col-auto">                   
                      <ul class="select_list" th:each="commonCode:${session.commonCode.get('OG')}">
                      <th:block th:if="${#lists.contains(mgtOrganList, commonCode.itemCd)}">		
						<li>
							<input id="category11" name="organList" type="checkbox" th:value="${commonCode.itemCd}" th:if="${#lists.isEmpty(searchParams.organList)}">
							<input id="category11" name="organList" type="checkbox" th:value="${commonCode.itemCd}" th:checked="${#lists.contains(searchParams.organList, commonCode.itemCd)}" th:unless="${#lists.isEmpty(searchParams.organList)}">
							<label th:text="${commonCode.itemValue}"></label>
						</li>
					   </th:block>
					   </ul>
				     </th:block>
                    </div>
                  <div class="row justify-content-end pb-1">
                    <div class="col-auto" style="overflow: auto">
                      <ul class="select_list" th:each="commonCode:${session.commonCode.get('DC01')}">			
							<li>
								<input th:id="|category1${commonCode.itemCd}|" name="category1" type="checkbox" th:value="${commonCode.itemCd}" th:if="${#lists.isEmpty(searchParams.category1)}">
								<input th:id="|category1${commonCode.itemCd}|" name="category1" type="checkbox" th:value="${commonCode.itemCd}" th:checked="${#lists.contains(searchParams.category1, commonCode.itemCd)}" th:unless="${#lists.isEmpty(searchParams.category1)}">
								<label th:for="|category1${commonCode.itemCd}|" th:text="${commonCode.itemValue}"></label>
							</li>
						</ul>
                    </div>
                    <div class="col-auto">
                     <ul class="select_list" th:each="commonCode:${session.commonCode.get('DC02')}">			
						<li>
							<input id="category11" name="category2" type="checkbox" th:value="${commonCode.itemCd}" th:if="${#lists.isEmpty(searchParams.category2)}">
							<input id="category11" name="category2" type="checkbox" th:value="${commonCode.itemCd}" th:checked="${#lists.contains(searchParams.category2, commonCode.itemCd)}" th:unless="${#lists.isEmpty(searchParams.category2)}">
							<label th:text="${commonCode.itemValue}"></label>
						</li>
					</ul>
                    </div>
                    <div class="col-auto">
                      <ul class="select_list" th:each="commonCode:${session.commonCode.get('DC03')}">			
							<li>
								<input id="category11" name="category3" type="checkbox" th:value="${commonCode.itemCd}" th:if="${#lists.isEmpty(searchParams.category3)}">
								<input id="category11" name="category3" type="checkbox" th:value="${commonCode.itemCd}" th:checked="${#lists.contains(searchParams.category3, commonCode.itemCd)}" th:unless="${#lists.isEmpty(searchParams.category3)}">
								<label th:text="${commonCode.itemValue}"></label>
							</li>
						</ul>
                    </div>
                    <div class="col-auto">
                      <ul class="select_list" th:each="commonCode:${session.commonCode.get('DC04')}">			
							<li>
								<input id="category11" name="category4" type="checkbox" th:value="${commonCode.itemCd}" th:if="${#lists.isEmpty(searchParams.category4)}">
								<input id="category11" name="category4" type="checkbox" th:value="${commonCode.itemCd}" th:checked="${#lists.contains(searchParams.category4, commonCode.itemCd)}" th:unless="${#lists.isEmpty(searchParams.category4)}">
								<label th:text="${commonCode.itemValue}"></label>
							</li>
						</ul>
                    </div>
                  </div>
                <div class="col-1 d-grid gap-2">
                  <input type="submit" class="btn btn-lg btn-primary col-auto" id="searchBtn" value="검색">
                </div>
              </div>
            </form>
            <div class="row justify-content-start">
              <div class="col-12">
                <div class="card">
                  <div class="card-body">
                    <div class="row">
                      <table class="table table-hover" id="tableData">
                        <thead>
                        <tr>
		                   <th rowspan="2">구분</th>
		                   <th rowspan="2">누계</th>
		                   <th:block th:unless="${#lists.isEmpty(type1)}">		                   
		                   <th th:colspan="${type1.size()}">분류1</th>
		                   </th:block>
		                   <th:block th:unless="${#lists.isEmpty(type2)}">
		                   <th th:colspan="${type2.size()}">분류2</th>
		                   </th:block>
		                   <th:block th:unless="${#lists.isEmpty(type3)}">
		                   <th th:colspan="${type3.size()}">분류3</th>
		                   </th:block>
		                   <th:block th:unless="${#lists.isEmpty(type4)}">
		                   <th th:colspan="${type4.size()}">분류4</th>
		                   </th:block>
		                 </tr>
		                 <tr>
		                 <th:block th:unless="${#lists.isEmpty(type1)}">
		                   <th:block th:each="type1:${type1}">
		                     <th th:text="${type1.itemValue}"></th>
		                   </th:block>
		                  </th:block>
		                  <th:block th:unless="${#lists.isEmpty(type2)}">
		                   <th:block th:each="type2:${type2}">
		                     <th th:text="${type2.itemValue}"></th>
		                   </th:block>
		                   </th:block>
		                   <th:block th:unless="${#lists.isEmpty(type3)}">
		                   <th:block th:each="type3:${type3}">
		                     <th th:text="${type3.itemValue}"></th>
		                   </th:block>
		                   </th:block>
		                   <th:block th:unless="${#lists.isEmpty(type4)}">
		                   <th:block th:each="type4:${type4}">
		                     <th th:text="${type4.itemValue}"></th>
		                   </th:block>
		                   </th:block>
		                 </tr>
                        </thead>
                        <tbody>
                        <th:block th:each="total:${totalList}">
	                    <tr>
	                     <td th:text="${total.itemValue}"></td>
	                     <td th:text="${total.cnt}"></td>
	                     <th:block th:each="commonCode:${type1}">
	                     	<th:block th:each="type1:${type1List}">                       
	                          <th:block th:if="${type1.affairType eq commonCode.affairType} and ${total.wrtOrgan eq type1.wrtOrgan}">
	                            <td th:text="${type1.cnt}"></td>
	                          </th:block>
	                        </th:block>
	                     </th:block>   
	                     <th:block th:each="commonCode:${type2}">
	                     	<th:block th:each="type2:${type2List}">                       
	                          <th:block th:if="${type2.affairType eq commonCode.affairType} and ${total.wrtOrgan eq type2.wrtOrgan}">
	                            <td th:text="${type2.cnt}"></td>
	                          </th:block>
	                        </th:block>
	                     </th:block>
	                     <th:block th:each="commonCode:${type3}">
	                     	<th:block th:each="type3:${type3List}">                       
	                          <th:block th:if="${type3.affairType eq commonCode.affairType} and ${total.wrtOrgan eq type3.wrtOrgan}">
	                            <td th:text="${type3.cnt}"></td>
	                          </th:block>
	                        </th:block>
	                     </th:block>
	                     <th:block th:each="commonCode:${type4}">
	                     	<th:block th:each="type4:${type4List}">                       
	                          <th:block th:if="${type4.affairType eq commonCode.affairType} and ${total.wrtOrgan eq type4.wrtOrgan}">
	                            <td th:text="${type4.cnt}"></td>
	                          </th:block>
	                        </th:block>
	                     </th:block> 	                                  
	                    </tr>
                  		</th:block>
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </main>
</div>
</html>