<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="java.io.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ include file="/jsp/common/include/localemessage.jsp" %>
<%
    response.setHeader("Pragma", "No-cache");
    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Expires", "0");
%>
<html>
<head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <jsp:include page="/jsp/common/include/css.jsp"/>
    <jsp:include page="/jsp/common/include/script.jsp"/>
    <style>
        .succ-y { color:#1a73e8; font-weight:bold; }
        .succ-n { color:#d93025; font-weight:bold; }
        .pre-wrap { white-space:pre-wrap; word-break:break-all; min-height:60px; line-height:1.5; }
    </style>
    <script language="javascript">
        var url = '<c:url value="/onl/apim/webhook/webhookSendLogMan.json" />';
        var url_view = '<c:url value="/onl/apim/webhook/webhookSendLogMan.view" />';
        var key = '${param.id}';

        function escapeHtmlJs(s) { return $('<div>').text(s == null ? '' : s).html(); }

        function detail() {
            if (!key) return;
            $.ajax({
                type: "POST", url: url, dataType: "json",
                data: {cmd: 'DETAIL', id: key},
                success: function (data) {
                    $('#id').text(data.id != null ? data.id : '');
                    $('#orgName').text(data.orgName || '');
                    $('#eventType').text(data.eventTypeName || data.eventType || '')
                        .attr('title', data.eventType || '');
                    $('#targetUrl').text(data.targetUrl || '');
                    $('#proxyUrl').text(data.proxyUrl || '');
                    $('#statusCode').text(data.statusCode != null ? data.statusCode : '');
                    $('#retryCount').text(data.retryCount != null ? data.retryCount : '');
                    $('#sendBy').text(data.sendBy || '');
                    $('#sentAt').text(data.sentAt || '');
                    $('#signature').text(data.signature || '');
                    $('#errorMessage').text(data.errorMessage || '');
                    $('#payload').text(data.payload || '');
                    $('#responseBody').text(data.responseBody || '');

                    if (data.success === true) {
                        $('#success').html('<span class="succ-y">성공</span>');
                    } else if (data.success === false) {
                        $('#success').html('<span class="succ-n">실패</span>');
                    } else {
                        $('#success').text('');
                    }
                },
                error: function (e) { alert(e.responseText); }
            });
        }

        $(document).ready(function () {
            var returnUrl = getReturnUrlForReturn();

            buttonControl();
            detail();

            $('#btn_previous').click(function () { goNav(returnUrl); });
        });
    </script>
</head>
<body>
<div class="right_box">
    <div class="content_top">
        <ul class="path"><li><a href="#">${rmsMenuPath}</a></li></ul>
    </div>
    <div class="content_middle">
        <div class="search_wrap">
            <button type="button" class="cssbtn" id="btn_previous" level="R" status="DETAIL,NEW"><i class="material-icons">arrow_back</i> <%= localeMessage.getString("button.previous") %></button>
        </div>
        <div class="title" id="title">웹훅 발송 로그 상세</div>
        <table class="table_row" cellspacing="0">
            <colgroup>
                <col style="width:12%"/><col style="width:38%"/>
                <col style="width:12%"/><col style="width:38%"/>
            </colgroup>
            <tr>
                <th>ID</th>
                <td><span id="id"></span></td>
                <th>기관명</th>
                <td><span id="orgName"></span></td>
            </tr>
            <tr>
                <th>이벤트유형</th>
                <td><span id="eventType"></span></td>
                <th>Status Code</th>
                <td><span id="statusCode"></span></td>
            </tr>
            <tr>
                <th>Target URL</th>
                <td><span id="targetUrl"></span></td>
                <th>Proxy URL</th>
                <td><span id="proxyUrl"></span></td>
            </tr>
            <tr>
                <th>성공여부</th>
                <td><span id="success"></span></td>
                <th>재시도횟수</th>
                <td><span id="retryCount"></span></td>
            </tr>
            <tr>
                <th>발송서버</th>
                <td><span id="sendBy"></span></td>
                <th>발송일시</th>
                <td><span id="sentAt"></span></td>
            </tr>
            <tr>
                <th>Signature</th>
                <td colspan="3"><span id="signature"></span></td>
            </tr>
            <tr>
                <th>Payload</th>
                <td colspan="3"><div id="payload" class="pre-wrap"></div></td>
            </tr>
            <tr>
                <th>Response Body</th>
                <td colspan="3"><div id="responseBody" class="pre-wrap"></div></td>
            </tr>
            <tr>
                <th>에러 메세지</th>
                <td colspan="3"><div id="errorMessage" class="pre-wrap"></div></td>
            </tr>
        </table>
    </div>
</div>
</body>
</html>
