<?php
		require_once 'singles.php';

$emptyArray=array();

	$q="select * from invest where email = '$mail' order by id desc";
	$r= mysqli_query($conn,$q);
	while($qr= mysqli_fetch_assoc($r)){

		$plan_no = $qr['plan']; 

    require_once 'functions.php';		
		plans_x($plan_no);
		
		$plan_name = get_plan_name();
		
		
		$id_invest = $qr['id'];
		$period = $qr['period_remaining'];
		$n_period= get_plan_return_no();		
		$new_period = ($period - $n_period).' Times';
		$amount = $qr['amount'];
		$roi = get_plan_rate3();

		$capital = get_plan_capital_back();
    
     $rating  = $amount * ($roi/100);

$capital = '<div class="site-badge success">'.$capital.'</div>';
		
		$profit = '<strong> 0 x '. $rating.'  = 0 USD</strong>';
		$created_at = $qr['created_at'];
		$time = $qr['time'];
		$created_time = strtotime($created_at);
		$start_time = date('M d, Y H:i ',strtotime($created_at));
		
		$thiddate = date('M d, Y H:i ',$time);
		
		$icon = '<span class="avatar-img">'.$qr['icon'].'</span>';
	$schema = '<strong> '.$plan_name.'<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" icon-name="arrow-big-right" class="lucide lucide-arrow-big-right"><path d="m21 12-7-7v4H3v6h11v4z"></path></svg> $'.$amount.' </strong><div class="date">'.$thiddate.'</div> ';

	
	$timers = '<div> <strong><span id="days'.$id_invest.'">0</span>D : <span id="hours'.$id_invest.'">15</span>H : <span id="minutes'.$id_invest.'">48</span>M : <span id="seconds'.$id_invest.'">54</span>S</strong> <span class="site-badge primary-bg ms-3" id="percentage'.$id_invest.'">34.10%</span></div>	
	<div class="progress investment-timeline"> <div class="progress-bar progress-bar-striped progress-bar-animated" id="time-progress'.$id_invest.'" role="progressbar" aria-valuenow="75" aria-valuemin="0" aria-valuemax="100" style="width: 34.39%;"></div></div>
		 <script>

        (function ($) {
            "use strict";
            // Countdown
            const second = 1000,
                minute = second * 60,
                hour = minute * 60,
                day = hour * 24;
                let timezone = "UTC";




            let countDown = new Date(\''.$thiddate.'\').getTime()
            var start = new Date(\''.$start_time.' \').getTime()
            setInterval(function () {

                let utc_datetime_str = new Date().toLocaleString("en-US", { timeZone: timezone });
                let now = new Date(utc_datetime_str).getTime();

                let distance = countDown - now;


                var progress = (((now - start) / (countDown - start)) * 100).toFixed(2);


                $("#time-progress'.$id_invest.'").css("width", progress + \'%\');

                $("#percentage'.$id_invest.'").text(progress >= 100 ? 100 + \'%\' : progress + \'%\');

                document.getElementById(\'days'.$id_invest.'\').innerText = Math.floor(distance < 0 ? 0 : distance / (day)),
                    document.getElementById(\'hours'.$id_invest.'\').innerText = Math.floor(distance < 0 ? 0 : (distance % (day)) / (hour)),
                    document.getElementById(\'minutes'.$id_invest.'\').innerText = Math.floor(distance < 0 ? 0 : (distance % (hour)) / (minute)),
                    document.getElementById(\'seconds'.$id_invest.'\').innerText = Math.floor(distance < 0 ? 0 : (distance % (minute)) / second);

            }, second)

        })(jQuery)

    </script>';

	
		
$nw = array('icon'=>"$icon", 'schema'=>"$schema", 'amount'=>"$amount USD", 'roi'=>"$roi%", 'period'=>"$period", 'next_profit_time'=>"$timers", 'capital_back'=>"$capital",'profit'=>"$profit");

	
		array_push($emptyArray, $nw);
		
		
		
	}
	$p = array('data'=>$emptyArray);
	 $plans_obj2 =  (json_encode($p));
	 
	 print($plans_obj2);

           

?>