@php $pageContent = getContent(config('settings')->active_template, 'myproduct.content', true); @endphp
<?php $diLd = now()->copy()->endOfDay()->timestamp; ?>
<?php
	$last_time = \Carbon\Carbon::parse($user->next_claim);
	$now = \Carbon\Carbon::now();
	$difference = $last_time->diffInHours($now);
	if( $last_time > $now){
		$diLd = $last_time->timestamp;
	}
?>
<?php $sTime = date( 'r', $diLd );?>
<?php
	$pendingIncome = 'pending_income'; 
	if(config('settings')->cur_text != 'NGN'){
		$pendingIncome = 'usdt_pending_income'; 
	}
?>
@extends($activeTemplate.'layouts.dash')

@push('style')
<style>
.typeitem {float: left;width: 50%;height: auto;overflow: hidden;margin-left: 0px;}
.over {border-bottom: 1px solid #000;}.successful{color:#28c76f !important;font-weight:800;}
</style>
@endpush


@section('content')

@php $link = route('invite', ['code' => auth()->user()->ref_code]); @endphp

	<div class="top1"></div>
	<div style="">
		<div class="top" style="background: none;">
			<div data-href="{{ route('user.investment') }}" class="linkBTN" style="float:left; line-height:46px;width:50%; height:46px;cursor:pointer;" id="btnClose">
				<img src="/assets/images/arrow-back-up-white.png" style="margin-left:12px;width:32px;" />
			</div>
		</div>
		<div id="in1" data-href="{{route('user.investment.log')}}" class="linkBTN" style="position: absolute; text-align:center;color:#fff; left: 0px; top: 60px; height: 50px; width: 160px; background-image: linear-gradient(180deg,#000,#6d6d6d 3%,#000); border-top-right-radius: 30px; border-bottom-right-radius: 30px; box-shadow: 0 0.8vw 2.667vw 1px rgb(0 0 0 / 36%); ">
			<div style="margin-top:7px; font-size:17px; font-weight:bold;" id="number1"> {{ $logs->count() }}</div>
			<div style="position: absolute;right: 28px;top: 8px;"><img src="/assets/images/eye.png" style="width:18px;" /></div>
			<div style="font-size:12px;">My production order</div>
		</div>
		<div id="in2" style="position: absolute; text-align: center; color: #fff; left: 0px; top: 120px; height: 50px; width: 160px; background-image: linear-gradient(180deg,#000,#6d6d6d 3%,#000); border-top-right-radius: 30px; border-bottom-right-radius: 30px; box-shadow: 0 0.8vw 2.667vw 1px rgb(0 0 0 / 36%); ">
			<div style="margin-top: 7px; font-size: 17px; font-weight: bold; " id="number2">{{ config('settings')->cur_sym }}{{ showAmount($userBalance['income']) }}</div>
			<div style="font-size:12px;">Returns wallet</div>
		</div>
		<img src="{{ getImage( 'assets/images/frontend/myproduct/' .@$pageContent->data_values->backgroud, '1080x577') }}" style="width:100%;">
	</div>

	<div style=" width: 100%; margin: 0 auto; margin-top: 1px; text-align: center; background: #fff; color: #000; position: relative; height: auto; overflow: hidden;">
		<div class="typeitem linkBTN @if($status == 0 ) over @endif" data-href="{{route('user.investment.log', 'active')}}" value="0">
			<div style="font-weight:700;padding: 10px; height: 30px; line-height:30px; overflow: hidden;">Active 在</div>
		</div>
		<div class="typeitem linkBTN @if($status == 1 ) over @endif" data-href="{{route('user.investment.log', 'completed')}}" value="1">
			<div style="font-weight:700;padding: 10px; height: 30px; line-height: 30px; overflow: hidden; ">Completed 完畢</div>
		</div>
	</div>

	<div style="height:45px;padding-top:10px; border-bottom:1px solid #eee;background: #fff; ">
		<div style="float:left;width:20%;text-align:center;">
			<img src="/assets/images/logo1.png" style="height:30px;" />
		</div>
		<div style="float:left;width:50%;">
			<div style="font-weight:bold;">{{ config('settings')->cur_sym }}{{ showAmount($sumIncome) }}</div>
			<div style="color:#888; padding-top:4px; font-size:12px;">Total Purchase</div>
		</div>
		<div style="float:left;width:30%;text-align:center;">
			<div style="font-weight: bold; color: #000;">{{ config('settings')->cur_sym }}{{ showAmount($sumDailys) }}</div>
			<div style="color:#888; padding-top:4px; font-size:12px;">Total Earnings</div>
		</div>
	</div>


	@if( $logs->count() )
	<div style="border-radius: 5px; padding:5px;  margin-top:10px;  background:#fff; text-align:center;position:relative;" id="list">
		<div class="main" data-v-c35495fc="">
			<div class="page7-container">
				<?php if( $last_time < $now){ ?>
				<div class="page7-reward-value curReward" style="font-size:16px;margin:10px; 0">NOTE:: Click the get dividend to start accumulating your product profits. this process last for 24 hours. Therefore, needs to be repeated every 24 hours interval.</div>

				<div class="linkBTN" id="start-trade" data-href="{{ route('user.trade.now',time()) }}" style="width: 98%; background: #000; margin:0 auto; height:45px; line-height:45px; color:#fff; border-radius: 5px !important;">
					<iconify-icon width="30" height="30" icon="hugeicons:money-receive-square" style="color: #FFFFFF;"></iconify-icon>
					<span>GET DIVIDEND</span>
				</div>
				<?php }else { ?>

				<div style="height:45px;padding-top:10px; border-bottom:1px solid #eee;background: #fff; ">
					<div style="float:left;width:30%;">
						<div style="font-weight:bold;">{{ config('settings')->cur_sym }}{{ showAmount($user->$pendingIncome,2) }}</div>
						<div style="color:#888; padding-top:4px; font-size:13px;">Product Dividend</div>
					</div>
					<div style="float:left;width:50%;text-align:center;">
						<div style="font-weight: bold; color: #000;">COUNTER 時間</div>
						<div style="color:#888; padding-top:4px;font-weight:700; font-size:16px;" id="timeDiv">
							<span class="page7-clock-number pTHours">20:</span>
							<span class="page7-clock-number pTMinutes">23:</span>
							<span class="page7-clock-number pTSeconds">57</span>
						</div>
					</div>
					<div style="float:right;width:20%;text-align:center;">
						<img src="/assets/images/piggy-bank.png" style="height:40px;" />
					</div>
				</div>

				<div class="btn2" id="whatsapp-share" data-href="{{ $link }}" style="width: 98%; background: #000; margin:0 auto; height:45px; line-height:45px; color:#fff; border-radius: 5px !important;">
					<iconify-icon width="30" height="30" icon="hugeicons:money-receive-square" style="color: #FFFFFF;"></iconify-icon>
					<span>CLAIM DIVIDEND</span>
				</div>
				<?php } ?>
			</div>
		</div>
	</div>
	@endif
	
	<div style="border-radius: 5px; padding:5px;  margin-top:10px; margin-bottom:70px; background:#fff; text-align:center;position:relative;" id="list">
		@forelse($logs as $log)
			<div style="background:#fff;width: 99%; margin: 0 auto; height: 160px; overflow: hidden; margin-top: 10px; position: relative;border-radius: 5px !important;border-bottom:1px solid #eee;">
				<div style="padding:10px; padding-top:15px; color:#000; text-align:left; font-weight:bold; font-size:14px;">{{ $log->plan->name }}</div>
				<div style="padding:5px 10px;color:#000; text-align:left;font-size:12px;">
					<font class='small-font' >Validity : </font> <font style='color:rgb(33,63,175);'>{{($log->total_return/2)}} </font> days
				</div>
				<div style="padding: 5px 10px; color: #000; text-align: left; font-size: 12px;">
					@if($log->interest_type == 1 )
					Daily income : <font style='color:rgb(33,63,175);'>{{ showAmount( $log->interest_amount ) }}%</font>
					@else
					Daily income : <font style='color:rgb(33,63,175);'>{{ $log->plan->cur_sym }}{{ showAmount( ($log->interest_amount * 2 ) ) }}</font>
					@endif
				</div>
				<div style="padding: 5px 10px; color: #000; text-align: left; font-size: 12px;">
					@if($log->interest_type == 1 )
					Daily income : <font style='color:rgb(33,63,175);'>{{ showAmount($log->interest_amount * $log->total_return) }}%</font>
					@else
					Total income : <font style='color:rgb(33,63,175);'>{{ $log->plan->cur_sym }}{{ showAmount($log->interest_amount * $log->total_return) }}</font>
					@endif
				</div>
				<div style="padding: 5px 10px; color: #000; text-align: left; font-size: 12px;">Buy Time : {{ $log->created_at->format('dS F Y, H:i') }}</div>
				@if( $log->status == 0 )
				<div style="background:#000; border: 0px; position: absolute; font-size: 12px; right: 10px; bottom: 10px; width: 80px; height: 25px; line-height: 27px; border: 1px solid #000; color: #fff; border-radius: 25px;">Running 跑步</div>
				@else
				<div style="background:#000; border: 0px; position: absolute; font-size: 12px; right: 10px; bottom: 10px; width: 80px; height: 25px; line-height: 27px; border: 1px solid #000; color: #fff; border-radius: 25px;">Closed 關閉</div>
				@endif

				<div class=''  style="background: none; text-align:center; border: 0px; position: absolute; font-size: 16px; right: 2px; top: 5px; width: 90px; height: 25px; line-height: 27px;  color: #000; border-radius: 25px;">
					<font style='color:rgb(33,63,175);'>{{ $log->plan->cur_sym }}{{ showAmount($log->amount) }} </font>
				</div>
				<div class='' style="background: none; text-align:center; border: 0px; position: absolute; font-size: 16px; right: 2px; top: 35px; width: 90px; height: 25px; line-height: 27px;  color: #000; font-weight:bold; border-radius: 25px;">
					<img src="{{ asset('assets') }}/{{ $log->plan->img }}" style='height:80px;border-radius: 2px;'>
				</div>
				<div style="margin-top:15px">
					@if( $log->status == 0 )
					<div class="layui-progress layui-progress-big" style="border-radius: 5px;">
						<div class="layui-progress-bar layui-progress-text" style="border-radius: 5px; width: {{diffDatePercent($log->updated_at, $log->next_return_date,0)}}%;">{{number_format(diffDatePercent($log->updated_at, $log->next_return_date,0),2)}}%</div>
					</div>
					@else
					<div class="layui-progress layui-progress-big" style="border-radius: 5px;">
						<div class="layui-progress-bar layui-progress-text" style="border-radius: 5px; width:100%;">100%</div>
					</div>
					@endif
				</div>
			</div>
		@empty
		<div style="padding:2px; width:95%; margin:0 auto; margin-top:50px;">
			<div style="border-radius: 5px; color:#fff; text-align:center; margin-top:35px;position:relative;">
				<img src="/assets/images/no.png" style=" width:100%;" /><br>
			</div>
		</div>
		<div class="layui-flow-more">You have not production line yet</div>
		@endforelse
	</div>
@endsection

@push('script')
<script>
    $('#whatsapp-share').on('click', function() {
        var url = $(this).data('url');
		$.ajax({
			type: "POST",
			url: "{{ route('user.collect.income') }}",
			data: {
                _token: '{{ csrf_token() }}'
			},
			beforeSend: function() {
				loading.showLoading({type: 2,tip: "Checking..."});
			},
			success: function(data) {
				loading.hideLoading();
                modalMessage(data.message, 200, data.link);
			},
			error: function(xhr, status, error) {
                var data = JSON.parse(xhr.responseText);
                var responseMessage = data.message
                modalMessage(responseMessage);
				loading.hideLoading();
			},
			fail: function() {
				loading.hideLoading();
				modalMessage("Request Failed");
			}
		});
		
    });
	
		function gtTRg(etime) {
		  const total = Date.parse(etime) - Date.parse(new Date());
		  const seconds = Math.floor((total / 1000) % 60);
		  const minutes = Math.floor((total / 1000 / 60) % 60);
		  const hours = Math.floor((total / (1000 * 60 * 60)) % 24);
		  return {total,hours,minutes,seconds};
		}

		function itlCk(id, ends) {
		  const clock = document.getElementById(id);
		  const hoursSpan = clock.querySelector('.pTHours');
		  const minutesSpan = clock.querySelector('.pTMinutes');
		  const secondsSpan = clock.querySelector('.pTSeconds');

		  function utCk() {
			const t = gtTRg(ends);

			hoursSpan.innerHTML = (t.hours+':').slice(-3);
			minutesSpan.innerHTML = (t.minutes+':').slice(-3);
			secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);
			
			if (t.total <= 1) {
				clearInterval(timeinterval);
				return false;
			}
		  }

		  utCk();
		  const timeinterval = setInterval(utCk, 1000);
		}

		const deadline = new Date(Date.parse('{{$sTime}}'));
		<?php if( $logs->count() && $last_time > $now){ ?>
		itlCk('timeDiv', deadline);
		<?php } ?>
</script>
@endpush