<?php
$title = 'Wallet';
require_once('header-links.php');
// require_once('../lib/basic-function.php');
// require_once('../lib/user-functions.php');
// require_once('../lib/investment-plan-functions.php');
// require_once('../lib/package-functions.php');
// require_once('../lib/currency-functions.php');
$coin = $basicFunctn->selectAllDlt($basicFunctn->currencies_tb);
?>

<body>
    <!-- BEGIN LOADER -->
    <div id="load_screen">
        <div class="loader">
            <div class="loader-content">
                <div class="spinner-grow align-self-center"></div>
            </div>
        </div>
    </div>
    <!--  END LOADER -->
    <!-- ajax loader -->
    <div style="display: none;" id="the_load_screen">
        <div class="loader">
            <div class="loader-content">
                <div class="spinner-grow align-self-center"></div>
            </div>
        </div>
    </div>
    <!-- ajax loader -->
    <div class="app">
        <div class="layout">
            <?php require_once('sidebar.php'); ?>

            <!-- Page Container START -->
            <div class="page-container">
                <?php require_once('header.php'); ?>

                <!-- Content Wrapper START -->
                <div class="main-content">
                    <div class="container-fluid">
                        <div class="page-title">
                            <h4><?php print $title; ?></h4>
                        </div>
                        <?php if($admin_logged['level'] == 1){ ?>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="card">
                                    <div class="card-block">
                                        <div class="row">
                                            <div class="col-md-8  ml-auto mr-auto">
                                                <form class="form-horizontal mrg-top-40 new_wallet_form">
                                                    <div class="form-group row">
                                                        <label for="form-1-1" class="col-md-3 control-label">Coin Name</label>
                                                        <div class="col-md-8">
                                                            <input type="text" value="" class="form-control" name="create_currency" placeholder="">
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <label for="form-1-1" class="col-md-3 control-label">Symbol</label>
                                                        <div class="col-md-8">
                                                            <input type="text" value="" class="form-control" name="symbol" placeholder="">
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <label for="form-1-1" class="col-md-3 control-label">Admin Address</label>
                                                        <div class="col-md-8">
                                                            <input type="text" value="" class="form-control" name="address" placeholder="">
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <div class="col-md-11 col-xs-11">
                                                            <div class="text-right">
                                                                <button type="submit" id="referrer_percent" class="btn btn-primary new_wallet_btn">Save Wallet</button>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php } ?>
                        <div class="row">
                            <div class="col-md-12">
                                <div class="card">
                                    <div class="card-block">
                                        <div class="table-responsive">
                                            <table class="table table-bordered table-hover table-sm">
                                                <thead>
                                                    <tr>
                                                        <th>S/N</th>
                                                        <th>Coin Name</th>
                                                        <th>Symbol</th>
                                                        <th>Admin Address</th>
                                                        <th>Edit</th>
                                                        <th>Remove</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <?php
                                                    $i = 1;
                                                    foreach ($coin as $e) { ?>
                                                        <tr>
                                                            <td><?php print $i; ?></td>
                                                            <td><?php print $e['name']; ?></td>
                                                            <td class="status-done"><?php print $e['symbol']; ?></td>
                                                            <td><?php print $e['admin_wallet_address']; ?></td>
                                                            <td>
                                                                <a class="mrg-top-15 ico" href="edit-wallet?coin=<?php print $e['unique_id']; ?>">
                                                                    <i class="fa fa-edit fa-2x"></i>
                                                                </a>
                                                            </td>
                                                            <td>
                                                                <a href="" id="<?php print $e['unique_id']; ?>" class="mrg-top-15 cursor-pointer delete_coin_modal" title="Block Account">
                                                                    <i class="fa fa-trash fa-2x"></i>
                                                                </a>
                                                            </td>
                                                        </tr>
                                                    <?php $i++;
                                                    } ?>
                                                </tbody>
                                            </table>


                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal fade zoomInUp" id="delete_coin_modal">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <h4>Delete Coin?</h4>
                            </div>
                            <form class="delete_coin_form">
                                <div class="modal-body">
                                    <p class="text-danger">By clicking continue, this coin will be deleted permanently. <br> User won't be able to use this coin for transactions.</p>
                                </div>
                            </form>
                            <div class="modal-footer no-border">
                                <div class="text-right">
                                    <button class="btn btn-default btn-sm" data-dismiss="modal">Cancel</button>
                                    <button class="btn btn-primary btn-sm delete_coin_btn" data-dismiss="modal">Continue</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- Content Wrapper END -->
                <?php require_once('footer.php'); ?>
                <!-- Footer END -->

            </div>
            <!-- Page Container END -->

        </div>
    </div>

    <?php require_once('footer-links.php'); ?>
    <script>
        
        $('.delete_coin_modal').click(function(e) {
            e.preventDefault();
            append_id('delete_coin_id', '.delete_coin_form', '#delete_coin_modal', this)
            $('#delete_coin_modal').modal('toggle');
        });

        $('.new_wallet_btn').click(async function(e) {
            e.preventDefault();
            let new_wallet_form = $('.new_wallet_form').serializeArray();
            let form_data = set_form_data(new_wallet_form);
            // console.log(new_wallet_form);return;
            // console.log(edit_txn_form[0].value);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            throwSweetalert(returned, 'wallet', 1);
        });
        $('.delete_coin_btn').click(async function(e) {
            e.preventDefault();
            let delete_coin_form = $('.delete_coin_form').serializeArray();
            let form_data = set_form_data(delete_coin_form);
            // console.log(delete_coin_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
            throwSweetalert(returned, 'wallet', 1);
        });
    </script>