<%@ page language="java" contentType="text/html; charset=utf-8" %>
<%@ page import="java.io.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ 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>
        .restricted-badge {
            display: inline-block;
            padding: 2px 8px;
            background-color: #ff4444;
            color: white;
            font-weight: bold;
            border-radius: 12px;
            font-size: 0.8em;
        }
    </style>
    <script language="javascript">
        var url = '<c:url value="/onl/admin/tokenissuance/tokenIssuanceStatusMan.json" />';
        var url_view = '<c:url value="/onl/admin/tokenissuance/tokenIssuanceStatusMan.view" />';

        $(document).ready(function () {
            var gridPostData = getSearchForJqgrid("cmd", "LIST");
            $('#grid').jqGrid({
                datatype: "json",
                mtype: 'POST',
                url: url,
                postData: gridPostData,
                colNames: ['기관명', 'APP명', '제한건수', '요청건수', '성공건수', '실패건수', '제한여부', 'CLIENTID'],
                colModel: [
                    {name: 'orgName', align: 'left', sortable: false, width: 150},
                    {name: 'clientName', align: 'left', sortable: false},
                    {name: 'dailyTokenLimit', align: 'right', sortable: false, width: 80},
                    {name: 'requestCount', align: 'right', sortable: false, width: 80},
                    {name: 'successCount', align: 'right', sortable: false, width: 80},
                    {name: 'failedCount', align: 'right', sortable: false, width: 80},
                    {name: 'restricted', align: 'center', sortable: false, width: 60, formatter: restrictedFormatter},
                    {name: 'clientId', hidden: true}
                ],
                jsonReader: {
                    repeatitems: false
                },
                pager: $('#pager'),
                page: '${param.page}',
                rowNum: '${rmsDefaultRowNum}',
                autoheight: true,
                height: $("#container").height(),
                autowidth: true,
                viewrecords: true,
                rowList: eval('[${rmsDefaultRowList}]'),
                ondblClickRow: function(rowId, iRow, iCol, e) {
                    var rowData = $(this).getRowData(rowId);
                    var url2 = url_view;
                    url2 += '?cmd=DETAIL';
                    url2 += '&page=' + $(this).getGridParam("page");
                    url2 += '&returnUrl=' + getReturnUrl();
                    url2 += '&menuId=' + '${param.menuId}';
                    //검색값
                    url2 += '&' + getSearchUrl();
                    //key값
                    url2 += '&clientId=' + rowData['clientId'];
                    goNav(url2);
                }
            });

            resizeJqGridWidth('grid', 'content_middle', '1000');

            $("#btn_search").click(function () {
                var postData = getSearchForJqgrid("cmd", "LIST");
                $("#grid").setGridParam({postData: postData, page: "1"}).trigger("reloadGrid");
            });

            $("input[name^=search]").keydown(function (key) {
                if (key.keyCode == 13) {
                    $("#btn_search").click();
                }
            });

            buttonControl();
        });

        function restrictedFormatter(cellvalue, options, rowObject) {
            if (cellvalue === true) {
                return '<span class="restricted-badge">제한됨</span>';
            }
            return '';
        }
    </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" id="content_middle">
        <div class="search_wrap">
            <button type="button" class="cssbtn" id="btn_search" level="R"><i
                    class="material-icons">search</i> <%= localeMessage.getString("button.search") %>
            </button>
        </div>
        <div class="title" id="title">${rmsMenuName}</div>

        <table class="search_condition" cellspacing=0;>
            <tbody>
            <tr>
                <th style="width:180px;"><%= localeMessage.getString("clntMan.clntNm") %>
                </th>
                <td><input type="text" name="searchClientName" value="${param.searchClientName}"></td>
                <th style="width:180px;"><%= localeMessage.getString("clntMan.clntId") %>
                </th>
                <td><input type="text" name="searchClientId" value="${param.searchClientId}"></td>
            </tr>
            </tbody>
        </table>

        <table id="grid"></table>
        <div id="pager"></div>

    </div>
</div>
</body>
</html>