<%@ Page Title="PDPA Contends" Language="C#" MasterPageFile="~/SunMaster.Master" AutoEventWireup="true" CodeBehind="PDPAContends.aspx.cs" Inherits="SUNWEB.PDPAContends" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous" />
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous" />
    <style type="text/css">
        .divEditor:empty:not(:focus):before {
            content: attr(data-text);
            color: #999999;
        }

        .sample-toolbar {
            border: solid 1px #ddd;
            background: #f4f4f4;
            padding: 5px;
        }

            .sample-toolbar > span {
                cursor: pointer;
            }

                .sample-toolbar > span:hover {
                    text-decoration: underline;
                }
    </style>

</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <asp:UpdatePanel runat="server" ID="updatepanel1" UpdateMode="Conditional">
        <%-- <asp:UpdatePanel runat="server" ID="updatepanel2">--%>
        <ContentTemplate>
            <%--<table style="width: 100%; padding-bottom: 10px;">
                <tr>
                    <td style="font-size: large; width: 50%; font-family: 'Open Sans', sans-serif; font-weight: bolder;"></td>
                    <td align="right" style="padding-bottom: 0px;">
                        <label for="validationCustom05">
                            Branch
                         <asp:Label ID="lblBranchAliasName" runat="server"></asp:Label>
                        </label>
                        <asp:DropDownList ID="cmbBranches" CssClass="form-select w-25" runat="server"
                            AutoPostBack="true" OnSelectedIndexChanged="cmbBranches_SelectedIndexChanged">
                        </asp:DropDownList>                                              
                        
                    </td>
                     <asp:Label ID="lblcurrentdb" runat="server" style="color:transparent"></asp:Label>
                </tr>
            </table>--%>


              <div class="container-fluid mb-3">
              <div class="row align-items-center">
  
                <!-- Left Column (optional) -->
                <div class="col-md-6">
                  <!-- Optional title or content here -->
                </div>

                <!-- Right Column: Label + Dropdown -->
                <div class="col-md-6 text-end">
                  <div class="d-inline-flex align-items-center gap-2">

                    <!-- Branch label -->
                    <label for="cmbBranches" class="mb-0">Branch</label>

                    <!-- DropDownList -->
                    <asp:DropDownList ID="cmbBranches"
                                      CssClass="form-select"
                                      runat="server"
                                      AutoPostBack="true"
                                      OnSelectedIndexChanged="cmbBranches_SelectedIndexChanged">
                    </asp:DropDownList>

                    <!-- Optional alias label next to dropdown -->
                    <asp:Label ID="lblBranchAliasName" runat="server" CssClass="mb-0" />

                    <!-- Transparent label for DB info -->
                    <asp:Label ID="lblcurrentdb" runat="server" Style="color: transparent;" />
                  </div>
                </div>

              </div>
            </div>






            <div class="row mt-4">
                <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
                    <div class="card">
                        <div class="card-body" style="height: 80vh">
                            <h5 class="card-header" style="background-color: #4c4c4c; color: White;">
                                <span style="font-size: 14px; color: #F8F9FA">PDPA</span>&nbsp;&nbsp;            
                            </h5>
                            <%-- <div class="sample-toolbar mt-2">
                                <a href="javascript:void(0)" onclick="format('bold')"><span class="fa fa-bold fa-fw"></span></a>
                                <a href="javascript:void(0)" onclick="format('italic')"><span class="fa fa-italic fa-fw"></span></a>
                            </div>--%>
                            <div id="container" class="border mb-2 h-75 overflow-auto">
                                <div id="pdpaEditor" contenteditable="true" data-text="Enter here..." class="divEditor p-2 fs-6 fst-normal" style="outline: none; min-height: 50vh;"></div>
                            </div>

                            <button id="btnSave" type="button" class="btn btn-primary">Save</button>
                            <button id="btnClear" type="button" class="btn btn-primary">Clear</button>

                        </div>
                    </div>
                </div>
            </div>

        </ContentTemplate>

    </asp:UpdatePanel>

    <script type="text/javascript">      
        function getdb(){                                
            let pdpa = document.getElementById('pdpaEditor')         
            var db = document.getElementById("<%=lblcurrentdb.ClientID %>").innerHTML;            
            getPDPA(db);                        
        }
       
        function readWebConfig() {
            var conStr = '<%=ConfigurationManager.ConnectionStrings["API_BaseURL"].ConnectionString %>'                
            return conStr
        }   

    $(document).ready(function () {
        $(document).on('click', '#btnSave', function () {       
            let pdpa = document.getElementById('pdpaEditor')  
            Swal.fire({                
                text: "Are you sure you want save changes?",
                icon: "warning",
                showCancelButton: true,
                confirmButtonColor: "#3085d6",
                cancelButtonColor: "#d33",
                confirmButtonText: "Yes"
            }).then((result) => {
                if (result.isConfirmed) {
                    var db = document.getElementById("<%=lblcurrentdb.ClientID %>").innerHTML;
                   
                    putPDPAConsent(db,pdpa.innerHTML)
                    Swal.fire({
                        position: "center",
                        icon: "success",
                        text: "PDPA Consent successfully change",
                        showConfirmButton: false,
                        timer: 1500
                    }).then((result) => {

                    });
                } else {
                    pdpa.innerHTML = getPDPA(db);
                }
                return;
            });
        });

        $(document).on('click', '#btnClear', function () {
            Swal.fire({
                //title: "Are you sure you want to stock in with zero cost?",
                text: "Are you sure you want clear PDPA consent?",
                icon: "warning",
                showCancelButton: true,
                confirmButtonColor: "#3085d6",
                cancelButtonColor: "#d33",
                confirmButtonText: "Yes"
            }).then((result) => {
                if (result.isConfirmed) {
                    pdpa.innerHTML = "";              
                } else {
                    //pdpa.innerHTML = getPDPA();
                }
                return;
            });     
        });
    });               
    </script>


    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script type="text/javascript" src="sunScript/crmscript.js"></script>

<script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css?v=1.1" rel="stylesheet" />
<!-- Bootstrap 5 -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" />
<!-- Optional Bootstrap Icons -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css" rel="stylesheet" />


</asp:Content>
