<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Setting</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
    <link rel="stylesheet" href="/plugins/fontawesome-free/css/all.min.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    <link rel="stylesheet" href="/dist/css/adminlte.min.css">
    <link rel="stylesheet" href="/css/admin.css">
    <link href="//cdn.jsdelivr.net/npm/@sweetalert2/theme-dark@4/dark.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <style>
        .form-group {
            margin-top: 20px;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 5px #2ecc71;
        }
        
        .form-group button {
            margin-top: 30px;
        }
    </style>
</head>

<body class="hold-transition sidebar-mini">
    <div class="wrapper">
        <%- include('nav') %>
            <div class="content-wrapper">
                <section class="content-header">
                    <div class="container-fluid">
                        <div class="row mb-2">
                            <div class="col-sm-6">
                                <h1>Settings</h1>
                            </div>
                        </div>
                    </div>
                    <!-- /.container-fluid -->
                </section>

                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-12">
                            <div style="padding: 10px 20px;margin-bottom: 200px;">
                                <div class="form-group">
                                    <div class="text-center">
                                        <label for="quantity">Increase | Discount for members</label>
                                    </div>
                                    <input type="text" class="form-control" oninput="value=value.replace(/\D/g,'')" id="buff-id" placeholder="Enter Account ID">< br>
                                    <select class="form-select mb-4" id="buff-acc" aria-label="Default select example">
                                        <option selected value="">--------------- Select function ---------------</option>
                                        <option value="1">Increase (+)</option>
                                        <option value="2">Reduce (-)</option>
                                    </select>

                                    <input type="text" class="form-control" oninput="value=value.replace(/\D/g,'')" id="buff-money" placeholder="Enter amount">
                                    <button type="submit" class="btn btn-primary" id="buff-username" style="width: 100%;">Initialize</button>
                                </div>

                                <div class="form-group">
                                    <div class="text-center">
                                        <label for="quantity">Change deposit information</label>
                                    </div>
                                    <label for="quantity" style="color: #3498db;">Upi Payment</label>
                                    <!-- <input type="text" class="form-control" placeholder="" id="edit-banking-name_bank" value=""><br> -->
                                    <input type="text" class="form-control" placeholder="Name" id="edit-banking-name" value=""><br>
                                    <input type="text" class="form-control" placeholder="UPI ID Tpay" id="edit-banking-info" value=""><br>
                                    <input type="text" class="form-control" placeholder="UPI ID Bharat Pe" id="edit-banking-upi" value=""><br>
                                    <button type="submit" class="btn btn-primary edit-banking" style="width: 100%;margin-bottom: 20px;">Submit</button>
                                    <!------------------------------------------------ --->
                                    <!-- <label for="quantity" style="color: #3498db;">Upi Payment 2</label>
                                    <input type="text" class="form-control" placeholder="" id="edit-banking-name_bank" value=""><br> -->
                                    <!-- <input type="text" class="form-control" placeholder="Name" id="edit-banking2-name" value=""><br>
                                    <input type="text" class="form-control" placeholder="UPI ID Tpay" id="edit-banking2-info" value=""><br>
                                    <input type="text" class="form-control" placeholder="UPI ID Bharat Pe" id="edit-banking2-upi" value=""><br>
                                    <button type="submit" class="btn btn-primary edit-banking2" style="width: 100%;margin-bottom: 20px;">Submit</button>  -->
                                    <!------------------------------------------------ --->
                                    <label for="quantity" style="color: #a50064;">UPI 2</label>
                                    <input type="text" class="form-control" placeholder="Name" id="edit-momo-name_bank" value=""><br>
                                    <input type="text" class="form-control" placeholder="UPI ID Tpay" id="edit-momo-name" value=""><br>
                                    <input type="text" class="form-control" placeholder="UPI ID Bharat Pe" id="edit-momo-info" value=""><br>
                                    <button type="submit" class="btn btn-primary edit-momo" style="width: 100%;">Initialize</button>
                                </div>

                                <div class="form-group">
                                    <div class="text-center">
                                        <label for="telegram">Telegram</label>
                                    </div>
                                    <label for="telegram" style="color: #3498db;">Telegram</label>
                                    <input type="text" class="form-control" id="telegram" placeholder="Link Telegram" value=""><br>
                                    <label for="cskh" style="color: #3498db;">Online service</label>
                                    <input type="text" class="form-control" id="cskh" placeholder="Online service" value=""><br>
                                    <label for="myapp_web" style="color: #3498db;">App download link</label>
                                    <input type="text" class="form-control" id="myapp_web" placeholder="Link to download APP" value=""><br>
                                    <button type="submit" class="btn btn-primary telegram" style="width: 100%;">Initialize</button>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
    </div>
    <script src="/plugins/jquery/jquery.min.js"></script>
    <script src="/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
    <script src="/dist/js/adminlte.min.js"></script>
    <script src="/js/admin/admin.js"></script>
    <script src="//cdn.jsdelivr.net/npm/sweetalert2@11/dist/sweetalert2.min.js"></script>
    <script>
        $.ajax({
            type: "POST",
            url: "/admin/manager/settings/get",
            data: "data",
            dataType: "json",
            success: function (response) {
                let bank = response.datas[0];
                let momo = response.datas[1];
                let bank2 = response.datas[2];
                $('#edit-momo-name_bank').val(momo.name_bank);
                $('#edit-momo-name').val(momo.name_user);
                $('#edit-momo-info').val(momo.stk);
                $('#edit-banking-upi').val(momo.upi);

                $('#edit-banking-name_bank').val(bank.name_bank);
                $('#edit-banking-name').val(bank.name_user);
                $('#edit-banking-info').val(bank.stk);
                $('#edit-banking-upi').val(bank.upi);
                $('#edit-banking2-upi').val(momo2.upi);

                $('#edit-banking2-name_bank').val(bank2.name_bank);
                $('#edit-banking2-name').val(bank2.name_user);
                $('#edit-banking2-info').val(bank2.stk);
                $('#edit-banking2-upi').val(bank2.upi);

                $('#telegram').val(response.settings[0].telegram);
                $('#cskh').val(response.settings[0].cskh);
                $('#myapp_web').val(response.settings[0].app);
            }
        });
    </script>
    <script>
        function sendRequest(params1, params2, typer) {
            $.ajax({
                type: "POST",
                url: "/manage/admin/settings",
                data: {
                    params1: params1,
                    params2: params2,
                    typer: typer,
                },
                dataType: "json",
                success: function(response) {
                    if (response.message == 1) {
                        Swal.fire(
                            'Good job!',
                            'You clicked the button!',
                            'success'
                        )
                    } else if (response.message == 2) {
                        Swal.fire({
                            icon: 'error',
                            title: 'Phone number does not exist',
                        })
                    } else {
                        Swal.fire({
                            icon: 'error',
                            title: 'Unknown error !',
                        })
                    }
                }
            });
        }

        function sendRequestBank(name_bank = '', name = '', info = '', typer = '', upi ='') {
            $.ajax({
                type: "POST",
                url: "/admin/manager/settings/bank",
                data: {
                    name_bank: name_bank,
                    name: name,
                    info: info,
                    typer: typer,
                    upi:upi
                },
                dataType: "json",
                success: function(response) {
                    Swal.fire(
                        'Good job!',
                        'You clicked the button!',
                        'success'
                    )
                }
            });
        }
        $('.buff-money').click(function(e) {
            e.preventDefault();
            const phone = $('#buff-phone').val();
            const money = $('#buff-money').val();
            const checkMoney = $.isNumeric(money);
            if (phone && checkMoney) {
                sendRequest(phone, money, "buff");
            } else {
                Swal.fire({
                    icon: 'error',
                    title: 'Empty or malformed',
                })
            }
        });
        $('.edit-momo').click(function(e) {
            e.preventDefault();
            const name_bank = $('#edit-momo-name_bank').val();
            const name = $('#edit-momo-name').val();
            const info = $('#edit-momo-info').val();
            const upi =  $('#edit-banking-upi').val();
            sendRequestBank(name_bank, name, info, "momo",upi);
        });
        $('.edit-banking').click(function(e) {
            e.preventDefault();
            const name_bank = $('#edit-banking-name_bank').val();
            const name = $('#edit-banking-name').val();
            const info = $('#edit-banking-info').val();
            const upi =  $('#edit-banking-upi').val();
            sendRequestBank(name_bank, name, info, "bank",upi);
        });
        $('.edit-momo2').click(function(e) {
            e.preventDefault();
            const name_bank = $('#edit-momo-name_bank').val();
            const name = $('#edit-momo-name').val();
            const info = $('#edit-momo-info').val();
            const upi =  $('#edit-banking2-upi').val();
            sendRequestBank(name_bank, name, info, "momo",upi);
        });
        $('.edit-banking2').click(function(e) {
            e.preventDefault();
            const name_bank = $('#edit-banking2-name_bank').val();
            const name = $('#edit-banking2-name').val();
            const info = $('#edit-banking2-info').val();
            const upi =  $('#edit-banking2-upi').val();
            sendRequestBank(name_bank, name, info, "bank2",upi);
        });
        $('.telegram').click(function(e) {
            e.preventDefault();
            const telegram = $('#telegram').val();
            const cskh = $('#cskh').val();
            const myapp_web = $('#myapp_web').val();
            $.ajax({
                type: "POST",
                url: "/admin/manager/settings/cskh",
                data: {
                    telegram: telegram,
                    cskh: cskh,
                    myapp_web: myapp_web,
                },
                dataType: "json",
                success: function (response) {
                    if (response.status == true) {
                        Swal.fire(
                            'Good job!',
                            'You clicked the button!',
                            'success'
                        )
                    } else {
                        Swal.fire({icon: 'error',
                             title: 'Empty or malformed',
                         })
                     }
                 }
             });
         });

         $('#buff-username').click(function (e) {
             e.preventDefault();
             let id_user = $('#buff-id').val().trim();
             let buff_acc = $('#buff-acc').val().trim();
             let money_value = $('#buff-money').val().trim();
             if (id_user && buff_acc && money_value) {
                 $.ajax({
                     type: "POST",
                     url: "/admin/manager/settings/buff",
                     data: {
                         id_user: id_user,
                         buff_acc: buff_acc,
                         money_value: money_value,
                     },
                     dataType: "json",
                     success: function (response) {
                         if (response.status == true) {
                             Swal.fire(
                                 'Good job!',
                                 '初始化成功',
                                 'success'
                             )
                         } else {
                             Swal.fire({
                                 icon: 'error',
                                 title: '用户 ID 不存在',
                             })
                         }
                     }
                 });
             } else {
                 Swal.fire({
                     icon: 'error',
                     title: '请输入完整信息',
                 })
             }
         });
     </script>
</body>

</html>
