<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<div class="container">
    <div class="subHeader">
        <h1 class="logo">안동시 교통정보센터</h1>
        <div class="pageLocation">
            <%@ include file="/WEB-INF/jsp/egovframework/include/adminSubMenu.jsp" %>
        </div>
    </div>
    <div class="subContent">
        <!-- 어드민 탭메뉴 -->
        <%@ include file="/WEB-INF/jsp/egovframework/include/adminMenu.jsp" %>
        <!--// 어드민 탭메뉴 -->
        <div class="pageTitle">
            <h2>팝업창 관리</h2>
            <p>안동시 첨단교통센터 <span>관리자</span> 정보입니다.</p>
        </div>
        <div class="adminWrap">
            <div class="boardWrap">
                <div class="board-form">
                    <dl>
                        <dt><span>제목</span></dt>
                        <dd>${popup.title}</dd>
                    </dl>
                    <dl>
                        <dt><span>링크(URL)</span></dt>
                        <dd>${popup.url}</dd>
                    </dl>
                    <dl>
                        <dt><span>기간</span></dt>
                        <dd>
                            ${popup.post_from}
                            <span>~</span>
                            ${popup.post_to}
                        </dd>
                    </dl>
                    <dl>
                        <dt><span>팝업 이미지</span></dt>
                        <dd>
                            <div class="editor" style="width: 100%;"><img class="popup-img" style="max-width: 100%" src="/upload/${popup.img_id}.do"></div>
                        </dd>
                    </dl>
                    <dl>
                        <dt><span>파일첨부</span></dt>
                        <dd style="display: flex; align-items: center;">
                            ${popup.img_name}
                        </dd>
                    </dl>
                </div>
                <div class="btnArea">
                    <button type="button" class="button" onclick="goBack()">목록</button>
                    <button type="button" class="button" onclick="editPopup('${popup.popupId}')">수정</button>
                    <button type="button" class="button" onclick="deletePopup('${popup.popupId}', '${popup.title}')">삭제</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    function editPopup(popupId) {
        location.href = '/admin/editPopup/' + popupId + '.do';
    }

    /**
     * 팝업창 삭제
     * @param popId
     * @param popupTitle
     */
    function deletePopup(popId, popupTitle) {
        let delConfirm = confirm("제목 : " + popupTitle + "\n해당 게시물을 삭제 하시겠습니까?");
        if (delConfirm) {
            $.ajax({
                type : 'post',
                url : '/admin/deletePopup.do',
                data : {popupId : popId},
                success : function(data){
                    if (data && data > 0) {
                        alert('팝업 게시물이 삭제 되었습니다.');
                        location.href = '/admin/popupList.do';
                    }
                    else {
                        alert('팝업 게시물이 삭제되지 않았습니다.');
                    }
                },
                error : function(error) {
                    alert('팝업 게시물 삭제중 오류가 발생하였습니다. \n' + error);
                }
            });
        }
    }

</script>