<?php
$title = 'Make Deposit';
// require_once('../admin/lib/basic-function.php');
// require_once('../admin/lib/user-functions.php');
// require_once('../admin/lib/investment-plan-functions.php');
// require_once('../admin/lib/package-functions.php');
// require_once('../admin/lib/currency-functions.php');
require_once('header-links.php');

$current_pg = 8;
$investment_plan = $basicFunctn->selectAllDlt($basicFunctn->investment_plan_tb);
$all_currency = $basicFunctn->selectAllDlt($basicFunctn->currencies_tb);
$all_package = $basicFunctn->selectAllDlt($basicFunctn->package_tb);

// $all_investments = $basicFunctn->selectWhereDlt($user->transaction_tb, 'user_id', $user_logged['unique_id']);
$all_txns = $basicFunctn->selectWhereDlt($basicFunctn->wallet_tb, 'user_id', $user_logged['unique_id']);


// print_r($title);die();

?>

<body>

    <!--  BEGIN NAVBAR  -->
    <?php require_once('header.php'); ?>
    <!--  END NAVBAR  -->

    <!--  BEGIN MAIN CONTAINER  -->
    <div class="main-container" id="container">

        <div class="overlay"></div>
        <div class="search-overlay"></div>

        <!--  BEGIN SIDEBAR  -->
        <?php require_once('sidebar.php'); ?>
        <!--  END SIDEBAR  -->

        <!--  BEGIN CONTENT AREA  -->
        <div id="content" class="main-content">
            <div class="layout-px-spacing">

                <div class="row layout-spacing">

                    <div class="col-xl-4 col-lg-6 col-md-5 col-sm-12 layout-top-spacing">

                        <div style="padding: 2px 32px;" class="widget widget-card-four">
                            <div class="widget-content">
                                <div class="w-content ">
                                    <div class="p-auto">
                                        <div class="s-icon icon-purple">
                                            <i class="bx bx-wallet"></i>
                                        </div>
                                    </div>
                                    <div class="s-info">
                                        <h6 class="value">$ <?php print number_format($wallet->get_balance($user_logged['unique_id'])); ?></h6>
                                        <hp>Balance</hp>
                                    </div>
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="col-xl-8 col-lg-6 col-md-7 col-sm-12 layout-top-spacing">
                        <div class="widget-content widget-content-area">
                            <form id="contact" class="section contact deposit_form">
                                <div class="info">
                                    <!-- <h5 class="text-capitalize"> make a deposit</h5> -->
                                    <div class="row">

                                        <div class="col-md-11 mx-auto">
                                            <div class="row">
                                                <div class="col-md-12">
                                                    <div class="form-group">
                                                        <label for="country">Currency<span class="text-danger">*</span></label>
                                                        <select class="form-control" name="top_up_coin_id">
                                                            <option value="" selected>-- choose a preferred currency --</option>
                                                            <?php foreach ($all_currency as $e) { ?>
                                                                <option value="<?php print $e['unique_id']; ?>"><?php print $e['name']; ?></option>
                                                            <?php } ?>
                                                        </select>
                                                    </div>
                                                </div>
                                                <div class="col-md-12">
                                                    <div class="form-group">
                                                        <label for="">Amount($)<span class="text-danger">*</span> </label>
                                                        <input type="number" class="form-control mb-4" name="amt_in_usd" value="" placeholder="Please enter an amount">
                                                    </div>
                                                    <div class="form-group">

                                                        <em>
                                                            Note: To proceed with deposit, you agree to our terms of operation.
                                                        </em>
                                                    </div>
                                                </div>
                                                <div class="col-md-12 text-center mb-5">
                                                    <button id="add-work-platforms" class="btn btn-secondary text-capitalize make_deposit_btn">confirm & proceed</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <!-- Content -->


                    <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 layout-top-spacing">
                        <div class="widget-content widget-content-area">
                            <div class="table-responsive">
                                <table class="table table-hover mb-4">
                                    <thead>
                                        <tr>
                                            <th>#</th>
                                            <th> hash</th>
                                            <!-- <th>Type</th> -->
                                            <th>action</th>
                                            <th>Amount($)</th>
                                            <th class="text-center">Status</th>
                                            <!-- <th>Date Confirmed</th> -->
                                            <th> Created at</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                        if (count($all_txns) > 0) {
                                            $i = 1;
                                            foreach ($all_txns as $e) {
                                        ?>
                                                <tr>
                                                    <td><?php print $i; ?></td>
                                                    <td>


                                                        <?php if ($e['action_type'] == 'top_up') { ?>
                                                            <span class="text-success">
                                                                <?php print $e['unique_id']; ?>
                                                            </span>
                                                        <?php } elseif ($e['action_type'] == 'withdrawal') { ?>
                                                            <span class="text-danger">
                                                                <?php print $e['unique_id']; ?>
                                                            </span>
                                                        <?php } ?>



                                                    </td>
                                                    <!-- <td><?php // print $e['action_type']; 
                                                                ?></td> -->
                                                    <td><?php print $e['description']; ?></td>
                                                    <td><?php print $e['amt_in_usd']; ?></td>
                                                    <td class="text-center text-capitalize">
                                                        <?php if ($e['status'] == 'pending') { ?>
                                                            <span class="text-warning">
                                                                <?php print $e['status']; ?>
                                                            </span>
                                                        <?php } elseif ($e['status'] == 'confirmed') { ?>
                                                            <span class="text-success">
                                                                <?php print $e['status']; ?>
                                                            </span>
                                                        <?php } elseif ($e['status'] == 'completed') { ?>
                                                            <span class="text-danger">
                                                                <?php print $e['status']; ?>
                                                            </span>
                                                        <?php } ?>
                                                    </td>
                                                    <!-- <td><?php //print $e['date_confirmed']; 
                                                                ?></td> -->
                                                    <td><?php print $e['created_at']; ?></td>
                                                </tr>
                                            <?php $i++;
                                            }
                                        } else { ?>
                                            <tr>
                                                <td class="text-center" colspan="10"> No Records Found </td>
                                            </tr>
                                        <?php } ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>



                </div>
            </div>
            <!-- deposit modal -->
            <div id="deposit_pay_modal" class="modal animated zoomInUp register-modal" role="dialog">
                <div style="max-width: 400px;" class="modal-dialog" role="document">
                    <div class="modal-content">
                        <div class="modal-header" id="registerModalLabel">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                <svg aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x">
                                    <line x1="18" y1="6" x2="6" y2="18"></line>
                                    <line x1="6" y1="6" x2="18" y2="18"></line>
                                </svg>
                            </button>
                        </div>
                        <div class="container">
                            <div class="form-group">
                                <div class="col-md-12 text-center">
                                    <h5 class="modal-title text-warning">TrustFort Finance</h5>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-12 text-center text-danger">
                                    <span>Transfer funds to the address below <i style="font-size: 20px;" class="bx bx-loader-circle rotate"></i></span>
                                </div>
                            </div>
                        </div>
                        <div style="padding-top: 0px;" class="modal-body">
                            <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12">
                                <div class="user-profile layout-spacing">
                                    <div style="float: left;" class="widget-content widget-content-area">
                                        <div class="form-group">
                                            <div class="col-md-12 text-left">
                                                <span>Please send payment within 12hrs </span>
                                            </div>
                                        </div>
                                        <ul class="contacts-block list-unstyled">
                                            <li class="contacts-block__item" id="modal-pay-details">
                                                <div class="social text-success">
                                                    <div class="brand-name mb-3 text-left ">Payment Address</div>
                                                    <div class="brand-name mb-3 text-right">CVHHN89Y83J89JJ8</div>
                                                </div>
                                                <div class="social ">
                                                    <div class="brand-name mb-3 text-left ">Amount($)</div>
                                                    <div class="brand-name mb-3 text-right">12000</div>
                                                </div>
                                                <div class="social ">
                                                    <div class="brand-name mb-3 text-left">BTC Equivalent</div>
                                                    <div class="brand-name mb-3 text-right">0.0005981</div>
                                                </div>
                                            </li>
                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="modal-footer justify-content-center">
                            <div class="forgot login-footer">
                                <span><a href="https://blockchain.com">Continue</a>?</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- deposit modal -->
            <?php require_once('footer.php'); ?>
        </div>
        <!--  END CONTENT AREA  -->
    </div>
    <?php require_once('footer-links.php'); ?>
    <script>
        $('.make_deposit_btn').click(async function(e) {
            e.preventDefault();
            let deposit_form = $('.deposit_form').serializeArray();
            let form_data = set_form_data(deposit_form);
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);
            // return;
            if (returned.error == 1) {
                throwSweetalert(returned, 'deposit', 1);
                return;
            }
            window.location.href = returned.site_root + '/user/process-payment?txn=' + returned.txn_id;

            // let payment_modal = `<div class="social text-success">
            //                         <div class="brand-name mb-3 text-left ">Payment Address</div>
            //                         <div class="brand-name mb-3 text-right">${returned.address}</div>
            //                     </div>
            //                     <div class="social ">
            //                         <div class="brand-name mb-3 text-left ">Amount($)</div>
            //                         <div class="brand-name mb-3 text-right">${returned.usd_amt}</div>
            //                     </div>
            //                     <div class="social ">
            //                         <div class="brand-name mb-3 text-left">${returned.coin_name} Equivalent</div>
            //                         <div class="brand-name mb-3 text-right">${returned.coin_amt}</div>
            //                     </div>`;
            //     $('.contacts-block__item > *').remove();
            //     $(payment_modal).appendTo('#modal-pay-details');
            //     $('#deposit_pay_modal').modal('toggle');
        });

        // });
    </script>