<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%-- <%@ taglib prefix="cfn" uri="/WEB-INF/tlds/function.tld" %> --%> 
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ page import="cmm.util.CmmUtil" %>
<%@ page import="cmm.Constant" %>
<%
    String pdfPath = CmmUtil.getPropertyStr(Constant.PDF_VIEW_KEY);
%>
<ul class="list res-card" id="sch_ref_list">
    <c:forEach var="result" items="${reference.searchResultList}">
        <li>
            <c:if test="${!empty result.MAIN_IMG}"><!-- 썸네일이 있는 경우 -->
            <div class="thumb">
               <%--  <img src="${cfn:assetImgUrl(result.MAIN_IMG)}" alt="${result.TITLE}" /> --%>
                <img src="${result.MAIN_IMG}" alt="${result.TITLE}" />
                <c:if test="${!empty result.COPYRIGHT and result.COPYRIGHT ne ''}"><p class="source-origin">출처:${result.COPYRIGHT}</p></c:if>
            </div>
            </c:if>

            <div class="data-wrap">
                <div class="data-tit">
                    <span class="tit-txt"><c:out value="${result.TITLE}"/></span>
                </div>
                <ul class="list-info other">
                    <c:if test="${!empty result.FIRST_CATEGORY_NM}"><li><em><%--주제분야 : --%></em>${result.FIRST_CATEGORY_NM} <c:if test="${!empty result.SECOND_CATEGORY_NM}">&gt; ${result.SECOND_CATEGORY_NM}</c:if></li></c:if>
                    <c:if test="${!empty result.FIRST_CLASS_NM}"><li><em><%--자료유형 : --%></em>${result.FIRST_CLASS_NM} <c:if test="${!empty result.SECOND_CLASS_NM}">&gt; ${result.SECOND_CLASS_NM}</c:if></li></c:if>
                    <c:if test="${!empty result.PUBLISHER}"><li>${result.PUBLISHER}</li></c:if>
                    <c:if test="${(!empty result.GENYEAR) && (result.GENYEAR ne '0')}"><li>${result.GENYEAR}년도</li></c:if>
                </ul>
                <ul class="list-info other">
                    <c:if test="${!empty result.COUNCIL_NM_TOT}"><li><em>소장처 : </em>${result.COUNCIL_NM_TOT}</li></c:if>
                </ul>
                <p class="list-desc"><c:if test="${!empty result.SUMMARY}">${result.SUMMARY}</c:if></p>
                <div class="button-area left-align next-items">
                    <c:if test="${result.ORG_OPEN_AT eq 'Y'}">
                        <c:set var="docPath" value="${nfsNasPath}${nfsDocPath}"/>
                        <c:if test="${fn:contains(result.STRE_FILE_NAME, '/' )}">
                            <c:set var="docPath" value="${nfsNasPath}"/>
                        </c:if>
                        <c:choose>
                            <c:when test="${result.ASSET_TYPE eq '이미지'}"><a href="#" class="see-img original-viewer"  data-aId="${result.ASSETS_ID}"  data-mId="${result.MEDIA_ID}"  data-mType="I">사진보기</a></c:when>
                            <c:when test="${result.ASSET_TYPE eq '동영상'}"><a href="#" class="see-video original-viewer"  data-aId="${result.ASSETS_ID}"  data-mId="${result.MEDIA_ID}"  data-mType="V">영상보기</a></c:when>
                            <c:when test="${result.ASSET_TYPE eq '오디오'}"><a href="#" class="see-audio original-viewer"  data-aId="${result.ASSETS_ID}"  data-mId="${result.MEDIA_ID}"  data-mType="A">음향듣기</a></c:when>
                            <c:when test="${result.ASSET_TYPE eq '문서'}">
                                <%-- 원본 연결
                                <a href="#" class="see-doc btn-view-original"  data-mId="${result.MEDIA_ID}" onclick="util.docView( '${result.MEDIA_ID}'); return false;" >원문보기</a>
                                --%>
                                <%-- 분할파일 연결 (테스트query:임진란 임원선출) --%> 
                                <a href="#none" onclick="reference_viewOcr('${result.MEDIA_ID }', '${searchVO.query}', <%-- '${cfn:unidocsViewer(docPath ,result.STRE_FILE_NAME)}' --%>'czsczsc'); return false;" class="original-viewer" target="_blank">원문보기</a>
                            </c:when>   
                            <%-- <c:when test="${result.ASSET_TYPE eq '링크'}"><a href="${result.linkData}" target="_blank">원문보기</a></c:when> --%>
                            <c:when test="${result.ASSET_TYPE eq '링크'}"><a href="${result.LINK_DATA}" class="see-link original-viewer"  data-mId="${result.MEDIA_ID}" target="_blank">원문보기</a></c:when> 
                        </c:choose>
                    </c:if>
                    <c:if test="${result.ORG_OPEN_AT eq 'Y' and result.ASSET_TYPE eq '문서'}">
                        <c:if test="${!empty result.TABLE_OF_CONTENTS and result.TABLE_OF_CONTENTS ne ''}">
                            <button type="button" class="only-icon table-of-contents" data-mId="${result.MEDIA_ID}">목차</button>
                        </c:if>
                    </c:if>
                    <a href="#none" class="only-icon ris-viewer" onclick="util.risDownloadFile('${result.ASSETS_ID}','${result.MEDIA_ID}'); return false;">RIS</a>
                    <c:if test="${result.ORG_OPEN_AT eq 'Y'}">
                        <button type="button" class="btn-share only-icon sharing" data-cUrl="${result.LINK_URL}">공유하기</button>
                    </c:if>
                </div>
            </div>
        </li>
    </c:forEach> 
</ul>
<script>
    $(document).ready(function(){
        //구글  analytics event
        $('.ris-viewer').on('click', function(e) {
            var name = $(this).parents('.list-select-wrap').parents('.data-wrap').find('.tit-txt').text();
            name = "지방문화원자료 RIS | " + name;
            gtag('event', 'ris click', {
                'event_category': '지방문화원자료',
                'event_label': name,
            });
        });
    });
</script>
