<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="localdatetime" uri="https://www.notiforce.co.kr/functions/i2c-localdatetime" %>
<script type="text/javascript" src="<c:url value="/validator.do"/>"></script>
<script type="text/javascript" src="/views/jsp/v2/admin/stat/excelutils.js"></script>
<div id="admin_cont">
  <div class="inner">
    <div class="title">
      <h3>메세지 사용현황</h3>
    </div>
    <div class="info-text">
      <p>
        더욱 자세한 정보는 <a href="mailto:notiforce_support@i2max.co.kr" style="color: blue;">notiforce_support@i2max.co.kr</a>
        로 문의주시기 바랍니다.
      </p>
      <p class="text-red mt5">
        ※ 수신자번호검색은 번호를 정확히 입력해주셔야 합니다.<br/>
        ※ 수신거부 및 잘못된요청 건은 아래 결과데이터에 포함되지 않습니다.
      </p>
    </div>

    <form:form commandName="msgStatisticsVO" method="get">
      <form:input path="pageIndex" type="hidden"/>
      <form:input path="agentType" type="hidden"/>
      <form:input path="tSeq" type="hidden"/>

      <div class="mt20">
        <table class="list">
          <colgroup>
            <col style="width:200px">
            <col/>
          </colgroup>
          <tbody>
          <tr>
            <th><label for="search">사용연월</label></th>
            <td>
              <div class="agent-radio">
                <form:select path="yyyyMm" class="form" style="width: 125px; height: 28px" onchange="formSearch();">
                  <c:forEach items="${monthList }" var="list">
                    <form:option value="${list }">${list }</form:option>
                  </c:forEach>
                </form:select>
              </div>
            </td>
          </tr>
          </tbody>
        </table>
      </div>

      <div class="mt20">
        <table class="list">
          <colgroup>
            <col style="width:200px">
            <col/>
          </colgroup>
          <tbody>
          <tr>
            <th><label for="search">Journey</label></th>
            <td colspan="3">JourneyName: <span class="f600">${detailVO.journeyName }</span></td>
            <td colspan="3">JourneyID: <span class="f600">${detailVO.journeyId }</span></td>
          </tr>
          <tr>
            <th><label for="search">Version</label></th>
            <td colspan="3">JourneyVersion: <span class="f600">${detailVO.journeyVersion }</span></td>
            <td colspan="3">VersionID: <span class="f600">${detailVO.versionId }</span></td>
          </tr>
          <tr>
            <th><label for="search">Activity</label></th>
            <td colspan="3">ActivityName: <span class="f600">${detailVO.activityName }</span></td>
            <td colspan="3">ActivityId: <span class="f600">${detailVO.activityId }</span></td>
          </tr>
          <tr>
            <th><label for="search"><c:out value='${fn:substring(detailVO.yyyyMm,4,6) }' escapeXml="false"/>월 통계</label>
            </th>
            <td>전체: <span class="text-green f600">${detailVO.allCnt }</span> 건</td>
            <td>성공: <span class="text-blue f600">${detailVO.successCnt }</span> 건</td>
            <td>재전송: <span class="text-blue f600">${detailVO.failbackCnt }</span> 건</td>
            <td>실패: <span class="text-red f600">${detailVO.failCnt }</span> 건</td>
            <td>수신거부: <span class="text-red f600">${detailVO.arsCnt }</span> 건</td>
            <td>잘못된요청: <span class="text-red f600">${detailVO.rjctCnt }</span> 건</td>
          </tr>
          <tr>
            <th><label for="search">발신정보</label></th>
            <c:if test="${detailVO.agentType eq 'emma' }">
              <td>발신번호: <span class="f600"><c:out value='${detailVO.dsptchNum }' escapeXml="false"/></span></td>
            </c:if>

            <c:if test="${detailVO.agentType eq 'ita' || detailVO.agentType eq 'frnPlus'}">
              <td>발신프로필: <span class="f600"><c:out value="${detailVO.kakaoProfile }" escapeXml="false"/></span></td>
            </c:if>

            <c:if test="${not empty detailVO.arsNum }">
              <td>
                수신거부번호: <span class="f600"><c:out value='${detailVO.arsNum }' escapeXml="false"/></span>
              </td>
              <td colspan="4">
                발신타입: <span class="f600"><c:out value='${detailVO.msgClType eq "1" ? "광고성" : "정보성" }'
                                                escapeXml="false"/></span>
              </td>
            </c:if>

            <c:if test="${empty detailVO.arsNum }">
              <td colspan="5">
                발신타입: <span class="f600"><c:out value='${detailVO.msgClType eq "1" ? "광고성" : "정보성" }'
                                                escapeXml="false"/></span>
              </td>
            </c:if>
          </tr>
          <tr>
            <th><label for="search">메세지정보</label></th>
            <c:if test="${detailVO.agentType eq 'emma' }">
              <td>메세지타입: <span class="f600">
                                 <c:choose>
                                   <c:when test="${detailVO.serviceType eq '0'}">
                                     SMS
                                   </c:when>
                                   <c:when test="${detailVO.serviceType eq '2'}">
                                     MMS
                                   </c:when>
                                   <c:when test="${detailVO.serviceType eq '3'}">
                                     LMS
                                   </c:when>
                                 </c:choose></span>
              </td>
            </c:if>

            <c:if test="${detailVO.agentType eq 'ita' || detailVO.agentType eq 'frnPlus'}">
              <td>메세지타입: <span class="f600">
	                                 <c:choose>
                                     <c:when test="${detailVO.msgType eq '1008'}">
                                       알림톡(T)
                                     </c:when>
                                     <c:when test="${detailVO.msgType eq '1012'}">
                                       알림톡(I)
                                     </c:when>
                                     <c:when test="${detailVO.msgType eq '1009'}">
                                       친구톡(T)
                                     </c:when>
                                     <c:when test="${detailVO.msgType eq '1013'}">
                                       친구톡(I)
                                     </c:when>
                                     <c:when test="${detailVO.msgType eq '1014'}">
                                       친구톡(W)
                                     </c:when>
                                     <c:when test="${detailVO.msgType eq '10001'}">
                                       친구톡+(WIL)
                                     </c:when>
                                     <c:when test="${detailVO.msgType eq '10002'}">
                                       친구톡+(CRS)
                                     </c:when>
                                     <c:when test="${detailVO.msgType eq '10003'}">
                                       친구톡+(CRSCM)
                                     </c:when>
                                     <c:when test="${detailVO.msgType eq '10004'}">
                                       친구톡+(CM)
                                     </c:when>
                                     <c:when test="${detailVO.msgType eq '10005'}">
                                       친구톡+(PV)
                                     </c:when>
                                   </c:choose>
	                               	</span>
              </td>
            </c:if>

            <td>예약상태: <span class="f600">
                                	<c:choose>
                                    <c:when test="${detailVO.tmpBookYN eq 'Y'}">
                                      예약대기
                                    </c:when>
                                    <c:when test="${detailVO.tmpBookYN eq 'N'}">
                                      실시간
                                    </c:when>
                                    <c:when test="${detailVO.tmpBookYN eq 'C'}">
                                      예약취소
                                    </c:when>
                                    <c:when test="${detailVO.tmpBookYN eq 'S'}">
                                      발신성공
                                    </c:when>
                                  </c:choose></span>
            </td>
            <td colspan="4">
              <c:out value="${detailVO.tmpBookYN eq 'N' ? '' : '예약발신일시: ' }" escapeXml="false"/>
              <span class="f600">
                                		<c:out
                                      value='${detailVO.tmpBookYN eq "N" ? "" : localdatetime:formatLocalDateTime(detailVO.reservedDate,"yyyy-MM-dd HH:mm") }'
                                      escapeXml="false"/>
                                	</span>
            </td>
          </tr>

          <c:if test="${detailVO.agentType == 'emma' && detailVO.serviceType != '0' }">
            <tr>
              <th><label for="search">제목</label></th>
              <td colspan="6"><input type="text" readonly="readonly" class="form"
                                     value="<c:out value='${detailVO.subject }' escapeXml='false' />"/></td>
            </tr>
          </c:if>

          <%-- 친구톡+ 제외 --%>
          <c:if test="${!fn:startsWith(detailVO.msgType, '1000')}">
            <tr>
              <th><label for="search">내용</label></th>
              <td colspan="6">
              <textarea readonly="readonly" id="content" style="margin: 0px;"><c:out value="${detailVO.content }"
                                                                                     escapeXml="false"/></textarea>
              </td>
            </tr>
          </c:if>

          <c:if test="${detailVO.serviceType eq '2' or detailVO.msgType eq '1013' or detailVO.msgType eq '1014' }">
            <tr>
              <th><label for="search">이미지</label></th>
              <td colspan="6"><img src="${detailVO.imgPath }" width="200"/></td>
            </tr>
          </c:if>

          <c:if test="${detailVO.msgType eq '1008' or detailVO.msgType eq '1012' }">
            <tr>
              <th><label for="search">템플릿코드</label></th>
              <td colspan="6">
                  ${detailVO.tmplatCd } (&nbsp;<span class="text-blue" style="cursor: pointer;"
                                                     onclick="selectAtTmpl('${detailVO.tmplatCd }')">템플릿상세정보 이동</span>&nbsp;)
              </td>
            </tr>
          </c:if>

          <%-- 와이드 아이템리스트 --%>
          <c:if test="${detailVO.msgType eq '10001' }">
            <%-- 헤더 --%>
            <tr>
              <th>제목</th>
              <td colspan="6">
                ${detailVO.header}
              </td>
            </tr>
            <%-- 아이템 리스트 --%>
            <c:forEach items="${frnPlusActivityInformation}" var='wideItemList' varStatus="status">
              <tr>
                <c:if test="${status.count eq 1}">
                  <th rowspan="5">대표 와이드 아이템리스트</th>
                </c:if>
                <c:if test="${status.count ne 1}">
                  <th rowspan="5">와이드 아이템리스트${status.count-1}</th>
                </c:if>
                <th rowspan="5" colspan="1" style="text-align: center;">
                  <img
                    src="${wideItemList.imageUrl}"
                    alt="와이드아이템리스트 이미지"
                    style="max-width: 200px; max-height: 150px;">
                </th>
                <th colspan="1">
                  내용
                </th>
                <td colspan="4">
                  <textarea
                    class="contentText"
                    readonly="readonly"
                    style="margin: 0px; height: auto;"
                  ><c:out
                    value="${wideItemList.title}"
                    escapeXml="false"
                  /></textarea>
                </td>
              </tr>
              <tr>
                <th colspan="1">
                  모바일 웹 링크
                </th>
                <td colspan="4">
                  ${wideItemList.linkMo}
                </td>
              </tr>
              <tr>
                <th colspan="1">
                  PC 링크
                </th>
                <td colspan="4">
                  ${wideItemList.linkPc}
                </td>
              </tr>
              <tr>
                <th colspan="1">
                  Android 링크
                </th>
                <td colspan="4">
                  ${wideItemList.schemeAndroid}
                </td>
              </tr>
              <tr>
                <th colspan="1">
                  iOS 링크
                </th>
                <td colspan="4">
                  ${wideItemList.schemeIos}
                </td>
              </tr>
            </c:forEach>
            <%-- 쿠폰 --%>
            <tr>
              <th rowspan="6">쿠폰</th>
              <th>
                타이틀
              </th>
              <td colspan="5">
                ${detailVO.couponTitle}
              </td>
            </tr>
            <tr>
              <th>상세 설명</th>
              <td colspan="5">
                ${detailVO.couponDescription}
              </td>
            </tr>
            <tr>
              <th>모바일 웹 링크</th>
              <td colspan="5">
                ${detailVO.couponLinkMo}
              </td>
            </tr>
            <tr>
              <th>PC 링크</th>
              <td colspan="5">
                ${detailVO.couponLinkPc}
              </td>
            </tr>
            <tr>
              <th>Android 링크</th>
              <td colspan="5">
                ${detailVO.couponSchemeAndroid}
              </td>
            </tr>
            <tr>
              <th>iOS 링크</th>
              <td colspan="5">
                ${detailVO.couponSchemeIos}
              </td>
            </tr>
            <%-- 버튼 --%>
            <c:forEach items="${frnPlusActivityInformationButton}" var="buttonList" varStatus="status">
              <tr>
                <th rowspan="6">
                  버튼${status.count}
                </th>
                <th>타입</th>
                <td colspan="5">
                  <c:if test="${'WL' eq buttonList.type}">웹링크</c:if>
                  <c:if test="${'AL' eq buttonList.type}">앱링크</c:if>
                </td>
              </tr>
              <tr>
                <th>이름</th>
                <td colspan="5">${buttonList.name}</td>
              </tr>
              <tr>
                <th>모바일 웹 링크</th>
                <td colspan="5">${buttonList.linkMo}</td>
              </tr>
              <tr>
                <th>PC 링크</th>
                <td colspan="5">${buttonList.linkPc}</td>
              </tr>
              <tr>
                <th>Android 링크</th>
                <td colspan="5">${buttonList.schemeAndroid}</td>
              </tr>
              <tr>
                <th>iOS 링크</th>
                <td colspan="5">${buttonList.schemeIos}</td>
              </tr>
            </c:forEach>
          </c:if>
          <%-- 케러셀 피드 --%>
          <c:if test="${detailVO.msgType eq '10002' }">
            <%-- 케러셀 리스트 --%>
            <c:forEach items="${frnPlusActivityInformation}" var='carouselList' varStatus="status">
              <%-- carouselList.buttonCount 값이 설정되어 있다고 가정 --%>
              <c:set var="carouselListbuttonCount" value="${carouselList.buttonCount}" />
              <%-- rowspan 값을 계산하여 사용 --%>
              <c:set var="rowspanValue" value="${9 + (6 * carouselListbuttonCount)}" />
              <tr>
                <th rowspan="${rowspanValue}">캐러셀 피드${status.count}</th>
                <th rowspan="3" colspan="1" style="text-align: center;">
                  <img src="${carouselList.imageUrl}" alt="캐러셀피드 이미지" style="width: auto; max-height: 100px;">
                </th>
                <th>제목</th>
                <td colspan="4">
                  ${carouselList.header}
                </td>
              </tr>
              <tr>
                <th>내용</th>
                <td colspan="4">
                  <textarea
                    class="contentText"
                    readonly="readonly"
                    style="margin: 0px; height: auto;"
                  ><c:out
                      value="${carouselList.content}"
                      escapeXml="false"
                    /></textarea>
                </td>
              </tr>
              <tr>
                <th>이미지 링크</th>
                <td colspan="4">
                  ${carouselList.imageLink}
                </td>
              </tr>
              <%-- 쿠폰 --%>
              <tr>
                <th rowspan="6" style="text-align: center">쿠폰</th>
                <th>타이틀</th>
                <td colspan="4">
                    ${carouselList.couponTitle}
                </td>
              </tr>
              <tr>
                <th>상세 설명</th>
                <td colspan="4">
                    ${carouselList.couponDescription}
                </td>
              </tr>
              <tr>
                <th>모바일 웹 링크</th>
                <td colspan="4">
                    ${carouselList.couponLinkMo}
                </td>
              </tr>
              <tr>
                <th>PC 링크</th>
                <td colspan="4">
                    ${carouselList.couponLinkPc}
                </td>
              </tr>
              <tr>
                <th>Android 링크</th>
                <td colspan="4">
                    ${carouselList.couponSchemeAndroid}
                </td>
              </tr>
              <tr>
                <th>iOS 링크</th>
                <td colspan="4">
                    ${carouselList.couponSchemeIos}
                </td>
              </tr>
              <%-- 버튼 --%>
              <c:forEach items="${frnPlusActivityInformationButton}" var="buttonList" varStatus="status">
                <c:if test="${carouselList.seq eq buttonList.seq}">
                  <tr>
                    <th rowspan="6" style="text-align: center">
                      버튼
                    </th>
                    <th>타입</th>
                    <td colspan="4">${buttonList.type}</td>
                  </tr>
                  <tr>
                    <th>이름</th>
                    <td colspan="4">${buttonList.name}</td>
                  </tr>
                  <tr>
                    <th>모바일 웹 링크</th>
                    <td colspan="4">${buttonList.linkMo}</td>
                  </tr>
                  <tr>
                    <th>PC 링크</th>
                    <td colspan="4">${buttonList.linkPc}</td>
                  </tr>
                  <tr>
                    <th>Android 링크</th>
                    <td colspan="4">${buttonList.schemeAndroid}</td>
                  </tr>
                  <tr>
                    <th>iOS 링크</th>
                    <td colspan="4">${buttonList.schemeIos}</td>
                  </tr>
                </c:if>
              </c:forEach>
            </c:forEach>
            <%-- 더보기 --%>
            <tr>
              <th rowspan="4">더보기</th>
              <th>모바일 웹 링크</th>
              <td colspan="5">
                ${detailVO.tailLinkMo}
              </td>
            </tr>
            <tr>
              <th>PC 링크</th>
              <td colspan="5">
                ${detailVO.tailLinkPc}
              </td>
            </tr>
            <tr>
              <th>Android 앱 링크</th>
              <td colspan="5">
                  ${detailVO.tailSchemeAndroid}
              </td>
            </tr>
            <tr>
              <th>iOS 앱 링크</th>
              <td colspan="5">
                  ${detailVO.tailSchemeIos}
              </td>
            </tr>
          </c:if>
          <%-- 케러셀 커머스 --%>
          <c:if test="${detailVO.msgType eq '10003' }">
            <tr>
              <th rowspan="6">인트로</th>
              <th rowspan="6" colspan="1" style="text-align: center;">
                <img src="${frnPlusActivityInformationIntro.image}" alt="캐러셀커머스인트로 이미지" style="width: auto; max-height: 100px;">
              </th>
              <th>제목</th>
              <td colspan="4">
                  ${frnPlusActivityInformationIntro.header}
              </td>
            </tr>
            <tr>
              <th>내용</th>
              <td colspan="4">
                  <textarea
                    class="contentText"
                    readonly="readonly"
                    style="margin: 0px; height: auto;"
                  ><c:out
                    value="${frnPlusActivityInformationIntro.content}"
                    escapeXml="false"
                  /></textarea>
              </td>
            </tr>
            <tr>
              <th>모바일 웹 링크</th>
              <td colspan="4">
                  ${frnPlusActivityInformationIntro.linkMo}
              </td>
            </tr>
            <tr>
              <th>PC 링크</th>
              <td colspan="4">
                  ${frnPlusActivityInformationIntro.linkPc}
              </td>
            </tr>
            <tr>
              <th>Android 링크</th>
              <td colspan="4">
                  ${frnPlusActivityInformationIntro.android}
              </td>
            </tr>
            <tr>
              <th>iOS 링크</th>
              <td colspan="4">
                  ${frnPlusActivityInformationIntro.ios}
              </td>
            </tr>
            <%-- 케러셀 리스트 --%>
            <c:forEach items="${frnPlusActivityInformation}" var='carouseCommercelList' varStatus="status">
              <%-- carouselList.buttonCount 값이 설정되어 있다고 가정 --%>
              <c:set var="carouselCommerceListbuttonCount" value="${carouseCommercelList.buttonCount}" />
              <%-- rowspan 값을 계산하여 사용(커머스 + 쿠폰 + 버튼) --%>
              <c:set var="rowspanValue" value="${7 + 6 + (6 * carouselCommerceListbuttonCount)}" />
              <tr>
                <th rowspan="${rowspanValue}">캐러셀 커머스${status.count}</th>
                <th rowspan="7" colspan="1" style="text-align: center;">
                  <img src="${carouseCommercelList.imageUrl}" alt="캐러셀커머스 이미지" style="width: auto; max-height: 100px;">
                </th>
                <th>상품명</th>
                <td colspan="4">
                    ${carouseCommercelList.title}
                </td>
              </tr>
              <tr>
                <th>부가 정보</th>
                <td colspan="4">
                  <textarea
                    class="contentText"
                    readonly="readonly"
                    style="margin: 0px; height: auto;"
                  ><c:out
                    value="${carouseCommercelList.additionalContent}"
                    escapeXml="false"
                  /></textarea>
                </td>
              </tr>
              <tr>
                <th>정상가격</th>
                <td colspan="4">
                    ${carouseCommercelList.regularPrice}
                </td>
              </tr>
              <tr>
                <th>할인가격</th>
                <td colspan="4">
                    ${carouseCommercelList.discountPrice}
                </td>
              </tr>
              <tr>
                <th>할인율</th>
                <td colspan="4">
                    ${carouseCommercelList.discountRate}
                </td>
              </tr>
              <tr>
                <th>정액할인가격</th>
                <td colspan="4">
                    ${carouseCommercelList.discountFixed}
                </td>
              </tr>
              <tr>
                <th>이미지 링크</th>
                <td colspan="4">
                    ${carouseCommercelList.imageLink}
                </td>
              </tr>
              <%-- 쿠폰 --%>
              <tr>
                <th rowspan="6" style="text-align: center">쿠폰</th>
                <th>타이틀</th>
                <td colspan="4">
                    ${carouseCommercelList.couponTitle}
                </td>
              </tr>
              <tr>
                <th>상세 설명</th>
                <td colspan="4">
                    ${carouseCommercelList.couponDescription}
                </td>
              </tr>
              <tr>
                <th>모바일 웹 링크</th>
                <td colspan="4">
                    ${carouseCommercelList.couponLinkMo}
                </td>
              </tr>
              <tr>
                <th>PC 링크</th>
                <td colspan="4">
                    ${carouseCommercelList.couponLinkPc}
                </td>
              </tr>
              <tr>
                <th>Android 링크</th>
                <td colspan="4">
                    ${carouseCommercelList.couponSchemeAndroid}
                </td>
              </tr>
              <tr>
                <th>iOS 링크</th>
                <td colspan="4">
                    ${carouseCommercelList.couponSchemeIos}
                </td>
              </tr>
              <%-- 버튼 --%>
              <c:forEach items="${frnPlusActivityInformationButton}" var="buttonList" varStatus="status">
                <c:if test="${carouseCommercelList.seq eq buttonList.seq}">
                  <tr>
                    <th rowspan="6" style="text-align: center">
                      버튼
                    </th>
                    <th>타입</th>
                    <td colspan="4">${buttonList.type}</td>
                  </tr>
                  <tr>
                    <th>이름</th>
                    <td colspan="4">${buttonList.name}</td>
                  </tr>
                  <tr>
                    <th>모바일 웹 링크</th>
                    <td colspan="4">${buttonList.linkMo}</td>
                  </tr>
                  <tr>
                    <th>PC 링크</th>
                    <td colspan="4">${buttonList.linkPc}</td>
                  </tr>
                  <tr>
                    <th>Android 링크</th>
                    <td colspan="4">${buttonList.schemeAndroid}</td>
                  </tr>
                  <tr>
                    <th>iOS 링크</th>
                    <td colspan="4">${buttonList.schemeIos}</td>
                  </tr>
                </c:if>
              </c:forEach>
            </c:forEach>
            <%-- 더보기 --%>
            <tr>
              <th rowspan="4">더보기</th>
              <th>모바일 웹 링크</th>
              <td colspan="5">
                  ${detailVO.tailLinkMo}
              </td>
            </tr>
            <tr>
              <th>PC 링크</th>
              <td colspan="5">
                  ${detailVO.tailLinkPc}
              </td>
            </tr>
            <tr>
              <th>Android 앱 링크</th>
              <td colspan="5">
                  ${detailVO.tailSchemeAndroid}
              </td>
            </tr>
            <tr>
              <th>iOS 앱 링크</th>
              <td colspan="5">
                  ${detailVO.tailSchemeIos}
              </td>
            </tr>
          </c:if>
            <%-- 커머스 --%>
          <c:if test="${detailVO.msgType eq '10004' }">
            <%-- 커머스 --%>
            <c:forEach items="${frnPlusActivityInformation}" var='commerceList' varStatus="status">
              <tr>
                <th rowspan="7">커머스</th>
                <th rowspan="7" colspan="1" style="text-align: center;">
                  <img src="${commerceList.imageUrl}" alt="커머스 이미지" style="width: auto; max-height: 100px;">
                </th>
                <th>상품명</th>
                <td colspan="4">
                    ${commerceList.title}
                </td>
              </tr>
              <tr>
                <th>부가 정보</th>
                <td colspan="4">
                  <textarea
                    class="contentText"
                    readonly="readonly"
                    style="margin: 0px; height: auto;"
                  ><c:out
                    value="${commerceList.additionalContent}"
                    escapeXml="false"
                  /></textarea>
                </td>
              </tr>
              <tr>
                <th>정상가격</th>
                <td colspan="4">
                    ${commerceList.regularPrice}
                </td>
              </tr>
              <tr>
                <th>할인가격</th>
                <td colspan="4">
                    ${commerceList.discountPrice}
                </td>
              </tr>
              <tr>
                <th>할인율</th>
                <td colspan="4">
                    ${commerceList.discountRate}
                </td>
              </tr>
              <tr>
                <th>정액할인가격</th>
                <td colspan="4">
                    ${commerceList.discountFixed}
                </td>
              </tr>
              <tr>
                <th>이미지 링크</th>
                <td colspan="4">
                    ${commerceList.imageLink}
                </td>
              </tr>
            </c:forEach>
            <%-- 쿠폰 --%>
            <tr>
              <th rowspan="6">쿠폰</th>
              <th>
                타이틀
              </th>
              <td colspan="5">
                  ${detailVO.couponTitle}
              </td>
            </tr>
            <tr>
              <th>상세 설명</th>
              <td colspan="5">
                  ${detailVO.couponDescription}
              </td>
            </tr>
            <tr>
              <th>모바일 웹 링크</th>
              <td colspan="5">
                  ${detailVO.couponLinkMo}
              </td>
            </tr>
            <tr>
              <th>PC 링크</th>
              <td colspan="5">
                  ${detailVO.couponLinkPc}
              </td>
            </tr>
            <tr>
              <th>Android 링크</th>
              <td colspan="5">
                  ${detailVO.couponSchemeAndroid}
              </td>
            </tr>
            <tr>
              <th>iOS 링크</th>
              <td colspan="5">
                  ${detailVO.couponSchemeIos}
              </td>
            </tr>
            <%-- 버튼 --%>
            <c:forEach items="${frnPlusActivityInformationButton}" var="buttonList" varStatus="status">
              <tr>
                <th rowspan="6">
                  버튼${status.count}
                </th>
                <th>타입</th>
                <td colspan="5">
                  <c:if test="${'WL' eq buttonList.type}">웹링크</c:if>
                  <c:if test="${'AL' eq buttonList.type}">앱링크</c:if>
                </td>
              </tr>
              <tr>
                <th>이름</th>
                <td colspan="5">${buttonList.name}</td>
              </tr>
              <tr>
                <th>모바일 웹 링크</th>
                <td colspan="5">${buttonList.linkMo}</td>
              </tr>
              <tr>
                <th>PC 링크</th>
                <td colspan="5">${buttonList.linkPc}</td>
              </tr>
              <tr>
                <th>Android 링크</th>
                <td colspan="5">${buttonList.schemeAndroid}</td>
              </tr>
              <tr>
                <th>iOS 링크</th>
                <td colspan="5">${buttonList.schemeIos}</td>
              </tr>
            </c:forEach>
          </c:if>
          <%-- 프리미엄동영상 --%>
          <c:if test="${detailVO.msgType eq '10005' }">
            <%-- 헤더 --%>
            <tr>
              <th>제목</th>
              <td colspan="6">
                  ${detailVO.header}
              </td>
            </tr>
            <%-- 동영상 --%>
            <c:forEach items="${frnPlusActivityInformation}" var='videoList' varStatus="status">
              <tr>
                <th rowspan="3">프리미엄동영상</th>
                <th>
                  내용
                </th>
                <td colspan="5">
                  <textarea
                    class="contentText"
                    readonly="readonly"
                    style="margin: 0; height: auto;"
                  ><c:out value="${videoList.content}" escapeXml="false"/></textarea>
                </td>
              </tr>
              <tr>
                <th>비디오 URL</th>
                <td colspan="5">
                    ${videoList.videoUrl}
                </td>
              </tr>
              <tr>
                <th>썸네일 이미지</th>
                <td colspan="5">
                  <c:if test="${videoList.imageUrl ne null && videoList.imageUrl ne ''}">
                    <img
                      src="${videoList.imageUrl}"
                      alt="와이드아이템리스트 이미지"
                      style="max-width: 200px; max-height: 150px;"
                    >
                  </c:if>
                </td>
              </tr>
            </c:forEach>
            <%-- 쿠폰 --%>
            <tr>
              <th rowspan="6">쿠폰</th>
              <th>
                타이틀
              </th>
              <td colspan="5">
                  ${detailVO.couponTitle}
              </td>
            </tr>
            <tr>
              <th>상세 설명</th>
              <td colspan="5">
                  ${detailVO.couponDescription}
              </td>
            </tr>
            <tr>
              <th>모바일 웹 링크</th>
              <td colspan="5">
                  ${detailVO.couponLinkMo}
              </td>
            </tr>
            <tr>
              <th>PC 링크</th>
              <td colspan="5">
                  ${detailVO.couponLinkPc}
              </td>
            </tr>
            <tr>
              <th>Android 링크</th>
              <td colspan="5">
                  ${detailVO.couponSchemeAndroid}
              </td>
            </tr>
            <tr>
              <th>iOS 링크</th>
              <td colspan="5">
                  ${detailVO.couponSchemeIos}
              </td>
            </tr>
            <%-- 버튼 --%>
            <c:forEach items="${frnPlusActivityInformationButton}" var="buttonList" varStatus="status">
              <tr>
                <th rowspan="6">
                  버튼${status.count}
                </th>
                <th>타입</th>
                <td colspan="5">
                  <c:if test="${'WL' eq buttonList.type}">웹링크</c:if>
                  <c:if test="${'AL' eq buttonList.type}">앱링크</c:if>
                </td>
              </tr>
              <tr>
                <th>이름</th>
                <td colspan="5">${buttonList.name}</td>
              </tr>
              <tr>
                <th>모바일 웹 링크</th>
                <td colspan="5">${buttonList.linkMo}</td>
              </tr>
              <tr>
                <th>PC 링크</th>
                <td colspan="5">${buttonList.linkPc}</td>
              </tr>
              <tr>
                <th>Android 링크</th>
                <td colspan="5">${buttonList.schemeAndroid}</td>
              </tr>
              <tr>
                <th>iOS 링크</th>
                <td colspan="5">${buttonList.schemeIos}</td>
              </tr>
            </c:forEach>
          </c:if>

          <%-- 친구톡+ 제외 --%>
          <c:if test="${fn:length(detailVO.buttonInfo) > 13
            && !fn:startsWith(detailVO.msgType, '1000')}">
            <tr>
              <th><label for="search">버튼정보</label></th>
              <td colspan="6"><c:out value="${detailVO.buttonInfo }" escapeXml="false"/></td>
            </tr>
          </c:if>
          <tr>
            <th><label for="search">엑셀파일생성</label></th>
            <td>
              <button type="button" class="button btn-blue" onclick="javascript:openExcelLayer();">파일확인</button>
            </td>
          </tr>
          </tbody>
        </table>
      </div>

      <div class="mt20">
        <table class="list">
          <colgroup>
            <col style="width:200px">
            <col/>
          </colgroup>
          <tbody>
          <tr>
            <th><label for="search">수신자번호검색</label></th>
            <td>
              <ul class="inner-td">
                <li><form:input path="searchKeyword" placeholder="'-' 없이 입력" type="text"/></li>
                <li>
                  <button type="button" class="button d s" onclick="formSearch();">검색</button>
                </li>
              </ul>
            </td>
          </tr>
          </tbody>
        </table>
      </div>
      <div class="board">
        <div class="board_added_module mt30 subtit">
          <span class="sum_info"
                style="display: inline-block;">결과데이터 : <strong>${msgStatisticsListCnt }</strong> 건 조회</span>
          <ul class="d-flex" style="float: right">
            <li class="mr10">목록 :</li>
            <li>
              <form:select path="pageUnit" class="form" onchange="formSearch();">
                <form:option value="10">10개</form:option>
                <form:option value="20">20개</form:option>
                <form:option value="30">30개</form:option>
              </form:select>
            </li>
          </ul>
        </div>
        <!-- <ul class="btn_wrap between mb10">
            <li><button class="button b b-inverse" style="display: none;">엑셀 다운로드</button></li>
            <li></li>
        </ul> -->

        <table class="list fix tb-border tb-center">
          <caption></caption>
          <colgroup>
            <col/>
            <col width="10%">
            <col width="10%">
            <col width="10%">
            <c:if test="${detailVO.agentType ne 'emma' }">
              <col width="10%">
              <col width="10%">
            </c:if>
          </colgroup>
          <thead>
          <tr>
            <th scope="col">발신ID</th>
            <th scope="col">수신자번호</th>
            <th scope="col">발신결과(코드)</th>
            <th scope="col">발신일시<br/>결과일시</th>
            <c:if test="${detailVO.agentType ne 'emma' }">
              <th scope="col">재발신결과(코드)</th>
              <th scope="col">재발신일시<br/>결과일시</th>
            </c:if>
          </tr>
          </thead>
          <tbody>
          <c:if test="${msgStatisticsListCnt == 0}">
            <tr>
              <c:choose>
                <c:when test="${detailVO.agentType eq 'emma'}">
                  <td colspan="4" style="text-align:center;">메세지 발신내역이 없습니다.</td>
                </c:when>
                <c:otherwise>
                  <td colspan="6" style="text-align:center;">메세지 발신내역이 없습니다.</td>
                </c:otherwise>
              </c:choose>
            </tr>
          </c:if>
          <c:if test="${msgStatisticsListCnt > 0}">
            <c:forEach items="${msgStatisticsList }" var="list" varStatus="status">
              <tr>
                <td>${list.notiId }</td>
                <td>${list.recipientNum }</td>

                <td><c:choose>
                  <c:when test="${list.reportCode eq '1000'}">
                    <span class="text-blue">발신성공(${list.reportCode })</span>
                  </c:when>
                  <c:otherwise>
                    <span class="text-red">발신실패(${list.reportCode })</span>
                  </c:otherwise>
                </c:choose>
                </td>
                <td><c:out value='${localdatetime:formatLocalDateTime(list.sendDate,"yyyy-MM-dd HH:mm") }'
                           escapeXml="false"/><br/>
                  <c:out value='${localdatetime:formatLocalDateTime(list.rsltDate,"yyyy-MM-dd HH:mm") }'
                         escapeXml="false"/>
                </td>
                <c:if test="${detailVO.agentType ne 'emma' }">
                  <td><c:if test="${fn:length(list.fbReportCode) > 0 }">
                    <c:choose>
                      <c:when test="${list.fbReportCode eq '1000' and fn:length(list.fbReportCode) > 0 }">
                        <span class="text-blue">발신성공(${list.fbReportCode })</span>
                      </c:when>
                      <c:otherwise>
                        <span class="text-red">발신실패(${list.fbReportCode })</span>
                      </c:otherwise>
                    </c:choose>
                  </c:if>
                  </td>
                  <td><c:if test="${fn:length(list.fbReportCode) > 0 }">
                    <c:out value='${localdatetime:formatLocalDateTime(list.fbSendDate,"yyyy-MM-dd HH:mm") }'
                           escapeXml="false"/><br/>
                    <c:out value='${localdatetime:formatLocalDateTime(list.fbRsltDate,"yyyy-MM-dd HH:mm") }'
                           escapeXml="false"/>
                  </c:if>
                  </td>
                </c:if>
              </tr>
            </c:forEach>
          </c:if>
          </tbody>
        </table>
        <!-- 페이징 -->
        <div class="btn_wrap tc">
          <ui:pagination paginationInfo="${paginationInfo}" type="image" jsFunction="formSearch"/>
        </div>
        <!-- //페이징 -->
      </div>
    </form:form>
    <!-- //table -->

  </div><!-- // admin inner -->
</div>

<!-- excel popup -->
<div class="add-new-pop template pop_layer_box" id="excelDownPop" style="display: none; width:250px;">
  <div class="title" style="padding-bottom: 25px; padding-top: 20px">
    <div></div>
    <h3 class="fs16" style="text-align: center;" id="ldtitle"></h3>
    <div><a href="javascript:;" class="close pop_layer_close" title="close" style="display: none;">X</a></div>
  </div>
  <p style="text-align: center; padding-bottom: 20px;">
    <span class="loader" style="display: none;"></span><br><br>
    <input type="text" class="form" id="excelName" placeholder="file_name"
           style="border: solid; width: 300px; margin-bottom: 5px; display: none;" maxlength="20"/>
  </p>
  <div class="btn_wrap">
    <button class="button b" id="downloadBtn" style="display: none;"></button>
  </div>
</div>

<script type="text/javascript">
  document.addEventListener("DOMContentLoaded", () => {
    /* 검색창 이벤트 변경 */
    msgStatisticsVO.searchKeyword.addEventListener('keydown', (e) => {
      if (event.keyCode === 13) {
        e.preventDefault();
        formSearch();
      }
      ;
    }, true);

    /* Content 자동 resize */
    let detailContent = document.getElementById('content');
    while (detailContent.clientHeight < detailContent.scrollHeight) {
      detailContent.rows = detailContent.rows + 1;
    }

    /* 친구톡+ Content 자동 resize */
    const contentList = document.querySelectorAll('.contentText');
    contentList.forEach((content) => {
      while (content.clientHeight < content.scrollHeight) {
        content.rows = content.rows + 1;
      }
    });
  });

  /* 알림톡 템플릿 상세정보 */
  function selectAtTmpl(tmplatCd) {
    const formWidget = document.createElement("form");
    formWidget.action = "/v2/admin/ita/at/tmpl/selectAtTmpl.do";
    formWidget.method = "post";
    formWidget.target = "_self";

    const tSeqWidget = document.createElement("input");
    tSeqWidget.type = "hidden";
    tSeqWidget.name = "tmplatCd";
    tSeqWidget.value = tmplatCd;
    formWidget.appendChild(tSeqWidget);

    document.body.appendChild(formWidget);
    formWidget.submit();
  }

  /* 검색 */
  function formSearch(pageIndex) {
    if (!pageIndex || pageIndex.value === 0) msgStatisticsVO.pageIndex.value = 1;
    else msgStatisticsVO.pageIndex.value = pageIndex;

    msgStatisticsVO.submit();
  }

  /* 엑셀 */
  function openExcelLayer() {
    // popup on
    openPopLayer({layer: $('#excelDownPop'), clickable: false});

    // check excel process
    fnExcelOnOpen();
  }

  const fnExcelOnOpen = () => {
    fetch('/restapi/v2/admin/stat/excelCheck.json', {
      method: 'get',
    }).then((response) => response.json()).then((data) => {
      switch (data.excelStatus) {
        case 'N':
          fnActivityExcelOnNothing('${detailVO.mainTable }', '${detailVO.subTable }',
              '${detailVO.journeyName } - ${detailVO.journeyVersion } - ${detailVO.activityName } // 상세정보');
          break;
        case 'P':
          fnExcelOnProcess();
          break;
        case 'S':
          fnExcelOnSuccess(data.excelInfo, data.excelName);
          break;
        case 'E':
          fnExcelOnError();
          break;
      }
    }).catch((err) => {
      alert('서버와 통신중 문제가 생겼습니다.');
    });
  }
  /* /엑셀 */
</script>
