<?php
require("../includes/db_connect.php");
require_once("includes/admin_session_token.php");

$accountId = $_SESSION['adm_accountId'];

$sql = "SELECT * FROM app_settings WHERE action IN(?,?,?,?,?,?,?,?)";
$sth = $conn->prepare($sql, [PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY]);

if ($sth->execute([
    'btc_address', 'eth_address',
    'usdt_address', 'min_withdrawal',
    'max_withdrawal', 'trc_address', 'erc_address', 'ltc_address'
])) {

    while ($data = $sth->fetch(PDO::FETCH_ASSOC)) {
        $action =  $data['action'];
        $value =  $data['value'];
        if ($action == "btc_address") {
            $btc_address = $value;
        } else if ($action == "eth_address") {
            $eth_address = $value;
        } else if ($action == "usdt_address") {
            $usdt_address = $value;
        } else if ($action == "min_withdrawal") {
            $min_withdrawal = $value;
        } else if ($action == "max_withdrawal") {
            $max_withdrawal = $value;
        } else if ($action == "trc_address") {
            $trc_address = $value;
        } else if ($action == "erc_address") {
            $erc_address = $value;
        } else if ($action == "ltc_address") {
            $ltc_address = $value;
        }
    }
} else {
    die("An error occurred!");
}

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

<head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>App Settings</title>
    <?php require_once("includes/header.php"); ?>

    <div class="content ht-100v pd-0">
        <div class="content-header">
        </div><!-- content-header -->

        <div class="content-body">
            <div class="container pd-x-0">
                <div class="d-sm-flex align-items-center justify-content-between mg-b-20 mg-lg-b-25 mg-xl-b-30">
                    <div>
                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb breadcrumb-style1 mg-b-10">
                                <li class="breadcrumb-item"><a href="#">App Settings</a></li>
                            </ol>
                        </nav>
                        <h4 class="mg-b-0 tx-spacing--1">App Settings</h4>
                    </div>

                </div>

                <div class="row row-xs">
                    <div class="col-sm-12">
                        <div class="card">
                            <div class="card-body">
                                <div style="display: none;" id="feedbackPrompt"></div>
                                <div class="row">
                                    <div class="form-floating mb-3 col-md-6">
                                        <label for="btc-address">BTC Address</label>
                                        <input type="text" class="form-control form-input-bg" id="btc-address"
                                            placeholder="" value="<?php echo ($btc_address); ?>" required />
                                    </div>
                                    <div class="form-floating mb-3 col-md-6">
                                        <label for="eth-address">ETH Address</label>
                                        <input type="text" class="form-control form-input-bg" id="eth-address"
                                            placeholder="" value="<?php echo ($eth_address); ?>" required />
                                    </div>
                                    <div class="form-floating mb-3 col-md-6">
                                        <label for="usdt-address">Solana Address</label>
                                        <input type="text" class="form-control form-input-bg" id="usdt-address"
                                            placeholder="" value="<?php echo ($usdt_address); ?>" required />
                                    </div>
                                    <div class="form-floating mb-3 col-md-6">
                                        <label for="erc-address">ERC20 Wallet Address</label>
                                        <input type="text" class="form-control form-input-bg" id="erc-address"
                                            placeholder="" value="<?php echo ($erc_address); ?>" required />
                                    </div>
                                    <div class="form-floating mb-3 col-md-6">
                                        <label for="trc-address">TRC20 Wallet Address</label>
                                        <input type="text" class="form-control form-input-bg" id="trc-address"
                                            placeholder="" value="<?php echo ($trc_address); ?>" required />
                                    </div>
                                    <div class="form-floating mb-3 col-md-6">
                                        <label for="ltc-address">LTC Wallet Address</label>
                                        <input type="text" class="form-control form-input-bg" id="ltc-address"
                                            placeholder="" value="<?php echo ($ltc_address); ?>" required />
                                    </div>
                                    <div class="form-floating mb-3 col-md-6">
                                        <label for="min-withdrawal">Min Withdrawal</label>
                                        <input type="text" class="form-control form-input-bg" id="min-withdrawal"
                                            placeholder="" value="<?php echo ($min_withdrawal); ?>" required />
                                    </div>
                                    <div class="form-floating mb-3 col-md-6">
                                        <label for="max-withdrawal">Max Withdrawal</label>
                                        <input type="text" class="form-control form-input-bg" id="max-withdrawal"
                                            placeholder="" value="<?php echo ($max_withdrawal); ?>" required />
                                    </div>
                                    <div class="form-floating mb-3 col-md-6">
                                    </div>
                                    <div class="d-flex align-items-stretch pt-2 col-md-6">
                                        <button id="save-btn" style="width: 100%;" type="submit"
                                            class="btn btn-primary btn-lg px-4">
                                            Save Settings
                                            <span style="display: none;"
                                                class="button_spinner spinner-border spinner-border-sm" role="status"
                                                aria-hidden="false"></span>
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div><!-- container -->
        </div>
    </div>

    <?php require_once("includes/footer.php"); ?>
    <script type="text/javascript">
    $(document).ready(function() {
        var classes = $("#mn-settings").prop('class');
        $("#mn-settings").prop('class', classes + ' active pcoded-trigger');

        var classes = $("#mn-app-settings").prop('class');
        $("#mn-app-settings").prop('class', classes + ' active pcoded-trigger');

    });
    </script>
    <script src="../js/admin/app-settings.js"></script>

    </body>

</html>