<%@ Page Language="C#" AutoEventWireup="true" CodeFile="View.aspx.cs" Inherits="Mail_PermitSend_View" meta:resourcekey="Page" %>

<!DOCTYPE html>
<html>
<head runat="server">
    <title></title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../libs/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../../libs/fontawesome/css/all.min.css" >
    <script type="text/javascript" src="../../libs/jquery-3.2.1.min.js"></script>
    <script type="text/javascript" src="../../libs/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
    <style type="text/css">
        .cBoxSubject {
            display: flex;
            font-size: 1.25rem;
        }
        .cBoxSubject .last {
            font-size: 1rem;
            margin-left: auto;
            padding-left: 4px;
        }
    </style>
    <script type="text/javascript">
        var darkView = { enabled: false };

        $(document).ready(function () {
            Dialog.setMessage('<asp:Literal runat="server" Text="<%$ Resources:Dialog, Title%>" />', '<asp:Literal runat="server" Text="<%$ Resources:Dialog, OK%>" />', '<asp:Literal runat="server" Text="<%$ Resources:Dialog, Cancel%>" />');
            Dialog.setUseBrowserConfirm(<%=AppSetting.UseBrowserConfirm%>);

            // 다크 모드 여부 확인
            if (window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches) {
                var v = localStorage.getItem("mail_darkview");
                if (v !== null) {
                    darkView = JSON.parse(v);
                } else {
                    darkView = { enabled: true };
                }
                SetDarkView(darkView.enabled);
            } else {
                document.getElementById("toggleDarkView").style.display = "none";
            }
            ShowMailBodyPanel();
        });

        function ShowMailBodyPanel() {
            if (!darkView.enabled)
                ShowToShadowDom("mailBodyPanel", "mailTemplate", true, true);
            else
                ShowToShadowDom4DarkMode("mailBodyPanel", "mailTemplate", true, true);
        }

        function Confirm_old() {
            Dialog.confirm({
                content: '<asp:Literal runat="server" Text="<%$ Resources:, Msg01%>" />',     // 메일 발송을 승인하겠습니까?
                ok: function () {
                    $.ajax({
                        type: "POST",
                        url: "CallAjax.aspx/Confirm",
                        data: JSON.stringify({ clid: '<%= _clId.ToString() %>' }),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            if (response.d == 0)
                                GotoList();
                            else
                                ShowErrorMessage(response.d);
                        },
                        failure: function (response) {
                            ShowErrorMessage(-1);
                        }
                    });
                }
            });
        }

        function Reject_old() {
            Dialog.confirm({
                content: '<asp:Literal runat="server" Text="<%$ Resources:, Msg02%>" />',     // 메일 발송을 거부하겠습니까?
                ok: function () {
                    $.ajax({
                        type: "POST",
                        url: "CallAjax.aspx/Reject",
                        data: JSON.stringify({ clid: '<%= _clId.ToString() %>' }),
                        contentType: "application/json; charset=utf-8",
                        dataType: "json",
                        success: function (response) {
                            if (response.d == 0)
                                GotoList();
                            else
                                ShowErrorMessage(response.d);
                        },
                        failure: function (response) {
                            ShowErrorMessage(-1);
                        }
                    });
                }
            });
        }

        function Confirm() {
            location.href = "DecideSend.aspx?cmd=approve&clid=<%=_clId%>&<%=_listPageParams%>";
        }

        function Reject() {
            location.href = "DecideSend.aspx?cmd=reject&clid=<%=_clId%>&<%=_listPageParams%>";
        }

        function ShowErrorMessage(code) {
            switch (code) {
                case 1: Dialog.alert('<asp:Literal runat="server" Text="<%$ Resources:, Msg03%>" />'); break;    // 이미 처리된 메일입니다.
                case 2: Dialog.alert('<asp:Literal runat="server" Text="<%$ Resources:, Msg04%>" />'); break;    // 유지보수 라이선스 만료 시 메일 승인 기능을 사용할 수 없습니다.
                default: Dialog.alert('<asp:Literal runat="server" Text="<%$ Resources:, Msg05%>" />'); break;   // 메일 발송 승인/거부 처리에 실패했습니다.
            }
        }

        function GotoList() {
            location.href = "ConfirmerList.aspx?<%=_listPageParams%>";
        }

        function OpenViewEmlWindow(msgfile) {
            var url = "../ViewEml.aspx?msgfile=" + msgfile;
            window.open(url, "");
        }

        function ShowMessage(msg) {
            Dialog.alert(msg);
        }

        function ToggleDarkView() {
            darkView.enabled = !darkView.enabled;
            SetDarkView(darkView.enabled);
            ShowMailBodyPanel();
            localStorage.setItem("mail_darkview", JSON.stringify(darkView));
            return false;
        }

        function SetDarkView(toggle) {
            if (toggle) {
                $("#mailBodyPanel").css({
                    "background-color": "rgba(0, 0, 0, 0)",
                    "color": $("body").css("color"),
                });
            } else {
                $("#mailBodyPanel").css({
                    "background-color": "#fff",
                    "color": "#333"
                });
            }
        }
    </script>

    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <CompositeScript>
                <Scripts>
                    <asp:ScriptReference Path="~/libs/tabs/common.js" />
                    <asp:ScriptReference Path="~/libs/tabs/dialog.js" />
                </Scripts>
            </CompositeScript>
        </asp:ScriptManager>

        <div class="container-fluid">
            <div class="row" id="toolBar" data-spy="affix">
                <div class="col-xs-12" style="padding-top:2px;padding-bottom:2px;">                    
                    <button type="button" id="confirmToolButton" runat="server" class="btn btn-primary" onclick="Confirm()"><span class="fa-regular fa-circle-check"></span> <%=_approveButtonText%></button>
                    <button type="button" id="rejectToolButton" runat="server" class="btn btn-primary" onclick="Reject()"><span class="fa-regular fa-circle-xmark"></span> <%=_declineButtonText%></button>
                    <span>&nbsp;</span>
                    <button type="button" id="closeToolButton" class="btn btn-primary" onclick="GotoList();"><span class="fa-solid fa-bars"></span></button>
                </div>
            </div>
        </div>
       
        <div class="container-fluid" style="padding-top:40px">
            <div class="row">
                <div class="col-xs-12 cBoxSubject">
                    <span><asp:Literal ID="SubjectLabel" runat="server" Mode="Encode" /></span>
                    <span id="toggleDarkView" class="last"><a href="#" onclick="return ToggleDarkView()"><i class="fa-solid fa-circle-half-stroke"></i></a></span>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <small class="text-muted"><asp:Label ID="RecvDateLabel" runat="server" Text=""></asp:Label></small>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <small class="text-muted"><asp:Localize ID="Localize5" runat="server" meta:resourcekey="Localize5">보낸 사람</asp:Localize></small> <asp:Label ID="FromAddrLabel" runat="server" CssClass="label label-default" />
                </div>
            </div>
            <div class="row">
                <div class="col-xs-12">
                    <small class="text-muted"><asp:Localize ID="Localize7" runat="server" meta:resourcekey="Localize7">받는 사람</asp:Localize></small> <asp:Literal ID="ToAddrTag" runat="server" />
                </div>
            </div>
            <div class="row <%=_ccCssClass%>">
                <div class="col-xs-12">
                    <small class="text-muted"><asp:Localize ID="Localize8" runat="server" meta:resourcekey="Localize8">참조</asp:Localize></small> <asp:Literal ID="CcAddrTag" runat="server" />
                </div>
            </div>
            <div class="row <%=_bccCssClass%>">
                <div class="col-xs-12">
                    <small class="text-muted"><asp:Localize ID="Localize9" runat="server" meta:resourcekey="Localize9">기타 수신자</asp:Localize></small> <asp:Literal ID="BccAddrTag" runat="server" />
                </div>
            </div>
            <div id="attachPanel" class="<%=_attachCssClass%>">
                <hr />
                <div class="mc-likeLink" data-toggle="collapse" data-target="#attachList">
                    <div class="row" style="padding-bottom:0.5em">
                        <div class="col-xs-12">
                            <i class="fa-solid fa-paperclip"></i> <asp:Label ID="AttachSummaryLabel" runat="server"></asp:Label>
                        </div>
                    </div>
                </div>
                <div id="attachList" class="list-group collapse">
                    <asp:Literal ID="AttachListTag" runat="server" />
                </div>
            </div>
            <hr />
            <div id="mailBodyPanel" style="min-height: 200px;padding: 5px 10px;overflow:auto"></div>
        </div>
        <template id="mailTemplate">
            <asp:PlaceHolder ID="MsgBodyHolder" runat="server" EnableViewState="false"></asp:PlaceHolder>
        </template>
    </form>
</body>
</html>
