<?php
$title = 'Affiliate';
// require_once('../admin/lib/table-traits.php');
// require_once('../admin/lib/basic-function.php');
// require_once('../admin/lib/user-functions.php');
require_once('header-links.php');

$current_pg = 6;
$user_details = $basicFunctn->selectWhereDlt($user->user_details, 'user_unique_id', $user_logged['unique_id'])[0];
$the_user = $basicFunctn->getDataDlt( $user_logged['unique_id'],$basicFunctn->user_tb);
$all_withdrawal = $basicFunctn->selectWhereDlt($user->user_details, 'referrer', $the_user['unique_id']);
$settings = $basicFunctn->site_settings();

// print_r($all_withdrawal);
// 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="hd-header-wrapper">
                <div class="row">
                    <div class="col-md-12 text-center">
                        <h4 class=""><?php print $basicFunctn->the_site_name; ?> Affiliate</h4>
                        <p class="">We pay you for spreading the word! </p>

                        <div class="row">
                            <div class="col-xl-9 col-lg-9 col-md-9 col-sm-11 col-11 mx-auto">
                                <div class="input-group mb-3">
                                    <div class="input-group-prepend">
                                        <span class="input-group-text" id="basic-addon1"><svg 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-search">
                                                <circle cx="11" cy="11" r="8"></circle>
                                                <line x1="21" y1="21" x2="16.65" y2="16.65"></line>
                                            </svg></span>
                                    </div>
                                    <input type="text" class="form-control text-white-50" value="<?php print $basicFunctn->site_root; ?>/en/register?ref=<?php print $user_logged['unique_id'] ?>" aria-label="Username" disabled aria-describedby="basic-addon1">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layout-px-spacing hd-tab-section">
                <div class="row">
                    <div class="col-md-12 ">

                        <div class="accordion" id="hd-statistics">
                            <div class="card">
                                <div class="card-header" id="hd-statistics-2">
                                    <div class="mb-0">
                                        <div class=" collapsed" data-toggle="collapse" role="navigation" data-target="#collapse-hd-statistics-2" aria-expanded="true" aria-controls="collapse-hd-statistics-2"><svg 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-help-circle">
                                                <circle cx="12" cy="12" r="10"></circle>
                                                <path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"></path>
                                                <line x1="12" y1="17" x2="12" y2="17"></line>
                                            </svg>
                                            Get started
                                        </div>
                                    </div>
                                </div>
                                <div id="collapse-hd-statistics-2" class="collapse show" aria-labelledby="hd-statistics-2" data-parent="#hd-statistics">
                                    <div class="card-body">
                                        <p>Above is your referral link.</p>
                                        <p>We currently pay up to <?php print $settings['referrer_percentage']; ?>% commissions on initial deposits of your referral, as well as additional deposits depending on the investment plan you are subscribed to; For every referral.</p>
                                        <p><a href="<?php print $basicFunctn->site_root; ?>/en/register?ref=<?php print $user_logged['unique_id'] ?>">Register Someone Now?</a></p>
                                    </div>
                                </div>
                            </div>

                        </div>
                        <div class="widget-content widget-content-area">
                            <p><h5>My Referrals</h5></p>
                            <div class="table-responsive">
                                <table class="table table-hover mb-4">
                                    <thead>
                                        <tr>
                                            <th>S/N</th>
                                            <th>Full Name</th>
                                            <th>Email</th>
                                            <th>Country</th>
                                            <th>Date Registered</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                    <?php if(count($all_withdrawal)>0){ 
                                        $i = 1;
                                        foreach ($all_withdrawal as $e) { 
                                            $referrer_details = $basicFunctn->getDataDlt($e['user_unique_id'],$basicFunctn->user_tb);
                                            $full_name = explode('++',$referrer_details['full_name']);
                                            $first_name = $full_name[0]; 
                                            $last_name = $full_name[1]; 
                                            ?>
                                            <tr>
                                                <td><?php print $i; ?></td>
                                                <td class="text-capitalize"><?php print $first_name.' '.$last_name; ?></td>
                                                <td><?php print $referrer_details['email']; ?></td>
                                                <td><?php print $e['country']; ?></td>
                                                <td><?php print $e['created_at']; ?></td>
                                            </tr>
                                    <?php $i++; }
                                         } else{ ?>
                                         <tr> 
                                             <td class="text-center" colspan="5"> No Records Found </td> 
                                         </tr>
                                    <?php } ?>
                                    </tbody>
                                </table>
                            </div>
                        </div>


                    </div>
                </div>
            </div>
            <?php require_once('footer.php'); ?>
        </div>
        <!--  END CONTENT AREA  -->
    </div>
    <?php require_once('footer-links.php'); ?>
    <script>
        $('.edit_user_btn').click(async function(e) {
            e.preventDefault();
            let edit_user_form = $('.edit_user_form').serializeArray();
            let form_data = set_form_data(edit_user_form);
            // console.log(edit_user_form);return;
            let returned = await ajaxRequest('ajax.php', form_data);
            // console.log(returned);return;
            throwSweetalert(returned, 'profile', 1);
        });
    </script>