@extends($activeTemplate.'layouts.dash')

@push('style')
@endpush

@section('content')
	<div class="top1"></div>

	<div style="  text-align: center; margin-bottom: 60px;  ">
		<div style="width: 100%; height: auto; overflow: hidden; position:relative;">
			<img src="/assets/images/bmw.jpg" style="width:100%;">

			<div style="cursor: pointer;position:absolute; bottom:5px; left:1%; width:44%; text-align:center; color:#fff;">
				<div style="font-size:13px">Earn over <b>30%</b> by inviting friends to start investing</div>
			</div>
			
			<div style="cursor: pointer;position:absolute; bottom:5px; left:52%; width:44%; text-align:center; color:#fff;">
				<div style="font-size:13px">Enjoy fast and hassle-free withdrawals and deposits.</div>
			</div>
		</div>

		<div style="color:#0076de;font-weight: 600;height: auto; overflow: hidden; margin-top:5px; font-size:12px; background:#fff; padding-top:10px; padding-bottom:10px;">
			<div style="color:#000;font-size:14px;margin:0 10px 10px;">Discover multiple earning opportunities through simple tasks and gift codes.</div>
			<div class="linkBTN" data-href="{{ route('user.deposit') }}" style="float:left;width: 25%; text-align:center;" id="Recharge">
				<div style="height:45px;">
					<img src="/assets/images/1.svg?" style="width:32px;">
				</div>
				<div>
					Recharge
				</div>
			</div>
			
			<div class="linkBTN" data-href="{{ route('user.withdraw') }}" style="float: left; width: 25%; text-align: center;" id="Withdraw">
				<div style="height:45px;">
					<img src="/assets/images/2.svg?" style="width: 32px;">
				</div>
				<div>
					Withdrawal
				</div>
			</div>
			<div class=" linkBTN" data-href="{{route('user.app.help')}}" style="float: left; width: 25%; text-align: center;" id="cs">
				<div style="height:45px;">
					<img src="/assets/images/3.svg?" style="width: 32px;">
				</div>
				<div>
					Help
				</div>
			</div>
			<div style="float: left; width: 25%; text-align: center;" id="down">
				<div style="height:45px;">
					<img src="/assets/images/6.svg?" style="width: 32px;">
				</div>
				<div>
					Download
				</div>
			</div>
		</div>

		<div style="height: auto; overflow: hidden; margin-top: 5px; font-size: 12px; background: #fff; color: #fff; padding-top: 10px; padding-bottom: 10px;">
			<div style="float:left;  background: url(/assets/images/ui1/3.jpg?wd); background-size: 100% 100%; width:32%; height:120px; border-radius:0 8px 8px 0; position: relative;">
				<img src="/assets/images/b.png" style="display:none;height:30px;margin-right:5px;position: absolute;right: 10px;background: #ebf2f9;border-radius: 4px;margin-top: 6px;">
				<div style="color:#FFF;margin-top: 70px; font-weight: bold; font-family: HarmonyOS Sans SC; font-size: 16px;" id="amount">{{ config('settings')->cur_sym }}{{ showAmount($userBalance['main'],0) }}</div>
				<div style="color:#FFF;font-family: HarmonyOS Sans SC; font-size: 12px;">Account Balance</div>
			</div>

			<div style="float: left; background: url(/assets/images/ui1/2.jpg?11); background-size: 100% 100%; width: 32%; margin-left:2%; border-radius:8px; height: 120px; position: relative;">
				<img src="/assets/images/c.png" style="display:none;height:30px;margin-right:5px;position: absolute;right: 10px;background: #ebf2f9;border-radius: 4px;margin-top: 6px;">
				<div style="margin-top: 70px; font-weight: bold; font-family: HarmonyOS Sans SC; font-size: 16px;" id="day_income">{{ config('settings')->cur_sym }}{{ showAmount($userBalance['income']) }}</div>
				<div style="font-family: HarmonyOS Sans SC; font-size: 12px;">User income</div>
			</div>
			<div style="float: left; background: url(/assets/images/ui1/gc.jpg?1w); background-size: 100% 100%; width: 32%; margin-left: 2%; border-radius:8px 0 0 8px; height: 120px; position: relative;">
				<img src="/assets/images/d.png" style="display:none;height:30px;margin-right:5px;position: absolute;right: 10px;background: #ebf2f9;border-radius: 4px;margin-top: 6px;">
				<div style="color:#FFF;margin-top: 70px; font-weight: bold; font-family: HarmonyOS Sans SC; font-size: 16px; " id="all_income">{{ config('settings')->cur_sym }}{{ showAmount($user->pending_income) }}</div>
				<div style="color:#FFF;font-family: HarmonyOS Sans SC; font-size:12px;">Pending income</div>
			</div>
		</div>

		<div style="text-align: center; background: #fff; width: 100%; margin: 0 auto; margin-top: 10px; padding-top: 10px; padding-bottom: 10px; border-radius: 5px !important; height: auto; overflow: hidden; position: relative; ">
			<div class="divWrap" style="padding: 10px; padding-top: 5px; padding-bottom: 5px;">
				<div style="float: left; width: 10%; font-size: 12px; color: #1476ff;">
					<img src="/assets/images/tt.png" style="height:17px;margin-right:5px;">
				</div>

				<?php $adLog = \App\Models\Transaction::select('users.username','type','amount', 'details', 'transactions.created_at')->join('users','users.id','=','user_id')->whereIn('type', ['deposit','commission','withdraw','invest'])->orderByRaw('RAND()')->take(30)->get(); ?>

				<div class="div" style="float:left; width:80%; color: #0076de; font-weight: 600;">
					<div class="marquee-root">
						<div class="marquee-content" id="intext" style="animation: 105.95s linear 0s infinite normal none running marqueeAnim;"><?php foreach($adLog as $list ){ ?><?php if($list->type == 'invest'){ echo $list->username . ' ' . $list->details . ' with ' . ($list->amount+0); } ?><?php if($list->type == 'deposit'){ echo $list->username . ' ' . $list->details . ' sum of ' . ($list->amount+0); } ?><?php if($list->type == 'commission'){ echo $list->username . ' got ' . ($list->amount+0) . ' for ' . $list->details; } ?><?php if($list->type == 'withdraw'){ echo $list->username . ' got paid ' . $list->details; } ?>, &nbsp;&nbsp;<?php } ?></div>
					</div>
				</div>
			</div>
		</div>

		<div style="height: auto; overflow: hidden; margin-top:5px; font-size:12px; background:#fff; padding-top:10px; padding-bottom:10px;">
			<img src="/assets/images/bbg.jpg" style="width:100%;">
		</div>

		@if( config('settings')->reward )
		<div class="home" style="height: auto;background: #FFF; overflow: hidden; margin-top:8px; font-size:12px;text-align:left; padding-top:10px; padding-bottom:30px;">
			@if( config('settings')->reward_login > 0 )
				@if($today == 0)
			<div class="my-tasks mb-1 dialyCheck" style="margin-bottom:20px;">
				<div class="title">
					<p><img src="/assets/images/loading.gif" alt="">Daily Checkin</p>
					<a id="loaderCheck"></a>
				</div>
				<a id="dialyCheck" data-href="{{ route('user.daily.check') }}">
					<img src="{{ asset('assets/images/earn-share.jpg') }}" alt="" style="width: 100%;">
				</a>
			</div>
				@endif
			@endif

			@php $rewards = \App\Models\RewardPlan::where(['status' => 1])->orderBy('id')->take(2)->get(); @endphp
			<div class="my-tasks">
				<div class="title">
					<p><img src="/assets/images/bt6.png" alt="">Daily Reward</p>
					<a href="{{ route('user.rewards') }}">More</a>
				</div>

				<div class="tasks">
					@foreach($rewards as $task)
					<div>
						<div>
							<div class="round-badge">
								<img src="/assets/images/{{ strtolower($task->currency) }}.png" alt="">
							</div>
							<p>{{ showAmount($task->amount) }}</p>
						</div>
						<div>
							<div>
								<p>{{ $task->name }}</p>
								<p>{!! $task->summary !!}</p>
							</div>
							<div>
								<button type="button" class="Buy task-submit" data-id="{{ $task->id }}">Get </button>
							</div>
						</div>
					</div>
					@endforeach
				</div>
			</div>
		</div>
		@endif
		
		<div id="noticeBoard" class="layui-form layui-tab-content" style="width:100%;padding:0px; margin-top:8px;display:none;">
			<div style="background: #fff; width: 100%; margin: 0 auto; margin-top: 0px;  padding-bottom:10px; height: auto; overflow: hidden; position: relative;margin-bottom: 5px;">
				<div style="padding:15px; padding-bottom:0px; text-align:left;" class="question" data-role="collapse">
					<div style="color:#000; border-left:3px solid #000;font-size: 18px;">&nbsp;Notice &amp; Updates</div>
				</div>
				<div style="width:98%;margin:0 auto;" class=" collapse" >
					<div style=" text-align:justify; font-size:16px;  border-radius: 10px; width: 95%; color:#666; margin: 0 auto; height: auto; overflow: hidden; margin-top: 10px; position: relative;">
					{!! config('settings')->home_message !!}
					</div>
				</div>
			</div>
		</div>

		<div style="height: auto; overflow: hidden; margin-top:8px; font-size:12px; background:#fff; padding-top:10px; padding-bottom:30px;">

			<div class="linkBTN" data-href="{{ route('user.coupon.index') }}" style="float:left;width: 25.2%; text-align:center;display: flex;place-content: center; border: 1px solid;margin-left:8px;border-radius:5px;" >
				<div style="height:35px;">
					<img src="/assets/images/coupon.jpg" style="height:35px;">
				</div>
			</div>
			
			<div class="linkBTN" data-href="{{ route('user.task') }}" style="float:left;width: 25.2%; text-align:center;display: flex;place-content: center; border: 1px solid;margin-left:8px;border-radius:5px;" >
				<div style="height:35px;">
					<img src="/assets/images/tasklists.png?hk" style="width:40px;">
				</div>
				<div style="place-content:center;margin-left:5px;">
					Tasks
				</div>
			</div>
			
			<div class="" onclick="modalMessage('This section is coming soon')" style="float:left;width: 25.2%; text-align:center;display: flex;place-content: center; border: 1px solid;margin-left:8px;border-radius:5px;" >
				<div style="height:35px;">
					<img src="/assets/images/game.png" style="width:32px;">
				</div>
				<div style="place-content:center;margin-left:5px;">
					Wheel
				</div>
			</div>

			<div class="" onclick="modalMessage('This section is coming soon')" style="float:left;width: 10.5%; text-align:center;display: flex;place-content: center; border: 1px solid;margin-left:8px;border-radius:5px;" >
				<div style="height:35px;font-size: large;align-items: center;display: grid;font-weight: 600;">商業</div>
			</div>
			
		</div>

		<div style="height:2px;"></div>
		
	</div>


@endsection

@push('script')
<script type="text/javascript">
	var lastUpdate = "{{ strtotime(config('settings')->updated_at); }}";
	var lastView = localStorage.getItem('viewNoticeDate');

	if( lastUpdate != lastView ){
        $("#noticeBoard").show();
		localStorage.setItem('viewNoticeDate', lastUpdate);
	}

    $('.task-submit').on('click', function() {
        
        var csrfToken = $('meta[name="csrf-token"]').attr('content');
        var $id = $(this).data('id');

        var $button = this;

        $($button).html('<img id="loader" src="/assets/images/loading.gif" style="width:20px" alt="">');

        // Make AJAX POST request
        $.ajax({
            type: 'POST',
            url: "{{ route('user.reward.activate') }}",
            contentType: 'application/json',
            headers: {
                "Content-Type": "application/json",
                "Accept": "application/json",
                "X-Requested-With": "XMLHttpRequest",
                "X-CSRF-TOKEN": csrfToken
            },
            data:JSON.stringify({id:$id}),
            dataType: 'json',
            success: function(res) {
                if (res.status == 200) {
                    $($button).val('');
                }

                $($button).html('Get');
				modalMessage(res.message);
            },
            error: function(jqXHR, textStatus, res) {
				var data = JSON.parse(jqXHR.responseText);
				var responseMessage = data.message

				if (data.errors) {
					var errorMessages = [];
					for (var key in data.errors) {
						if (data.errors.hasOwnProperty(key)) {
							errorMessages.push(data.errors[key][0]);
						}
					}
					responseMessage = errorMessages.join(", ")
				}

				modalMessage(responseMessage);
                $($button).html('Get');
            }
        });
    });
	
    $('#dialyCheck').on('click', function() {
        
        // Get CSRF token from the meta tag
        var csrfToken = $('meta[name="csrf-token"]').attr('content');
        var $url = $(this).data('href');

        $('#loaderCheck').html('loading <img id="loader" src="/assets/images/loading.gif" style="width:18px" alt="">');

        // Make AJAX POST request
        $.ajax({
            type: 'POST',
            url: $url,
            contentType: 'application/json',
            headers: {
                "Content-Type": "application/json",
                "Accept": "application/json",
                "X-Requested-With": "XMLHttpRequest",
                "X-CSRF-TOKEN": csrfToken
            },
            data:JSON.stringify({id:3}),
            dataType: 'json',
            success: function(res) {
                if (res.status == 200) {
					$('.dialyCheck').hide();
                }

                $('#loaderCheck').html('');
				modalMessage(res.message);
            },
            error: function(jqXHR, textStatus, res) {
				var data = JSON.parse(jqXHR.responseText);
				var responseMessage = data.message
                $('#loaderCheck').html('');
				modalMessage(responseMessage);
            }
        });
    });
	
</script>
@endpush