<div class="jumbotron">
  <div class="container">
    <div class="row">
        <div class="col-sm-8 col-xs-8">
        <p>Period <span style="font-weight:400; font-size:20px;">{{ $lastResult['periodid'] + 1}}</span></p>
        </div>
        <div class="col-sm-3 col-xs-4">
        <div class="couterDiv" >
            <div class="couterInner">
                <p>Count Down</p>
                <ul id="countdown">
                
                    <li > <span style="font-size:20px; color: #0f1223; font-weight:400;background: #F2F2F2; border-radius:5px;" class="hours">00</span>
                  
                    </li>
                    <li> <span style="font-size:20px; color: #0f1223; font-weight:400;background: #F2F2F2;border-radius:5px;" class="minutes">00</span>
                   
                    </li>
                 
                    </ul>
            </div>
        </div>
</div>

    </div>
    <div class="row">
        <div class="col-sm-4 col-xs-4 result">
            <p>PrePeriod <span style="font-weight:400; font-size:20px;">{{ $lastResult['periodid']}}</span></p>
        </div>
        <div style="margin-left:25px;" class="col-sm-4 col-xs-4 price-section">
        @php
            $textColor = 'Red';
        @endphp
        @if(trim($lastResult['resulttype']) == 'random')
            @if(strtolower($lastResult['randomcolor']) == 'green')
                @php  $textColor = 'Green'; @endphp
            @elseif(strtolower($lastResult['randomcolor']) == 'green++violet' || strtolower($lastResult['randomcolor']) == 'red+violet' || strtolower($lastResult['randomcolor']) == 'green & violet')
                @php  $textColor = 'VioletGreen'; @endphp
            @elseif(strtolower($lastResult['randomcolor']) == 'red++violet'  || strtolower($lastResult['randomcolor']) == 'red+violet'|| strtolower($lastResult['randomcolor']) == 'red & violet')
                @php  $textColor = 'VioletRed'; @endphp
            @endif
        @endif
        @if(trim($lastResult['resulttype']) == 'real')
            @if(strtolower($lastResult['color']) == 'green')
                @php  $textColor = 'Green'; @endphp
            @elseif(strtolower($lastResult['color']) == 'green++violet' || strtolower($lastResult['color']) == 'red+violet' || strtolower($lastResult['color']) == 'green & violet')
                @php  $textColor = 'VioletGreen'; @endphp
            @elseif(strtolower($lastResult['color']) == 'red++violet' || strtolower($lastResult['color']) == 'red+violet'  || strtolower($lastResult['color']) == 'red & violet')
                @php  $textColor = 'VioletRed'; @endphp
            @endif
        @endif
            <p>Result <span class="item{{ $textColor }}" style="font-size:16px">{{ $lastResult['resulttype'] == 'random' ? $lastResult['randomresult'] : $lastResult['result'] }}</span></p>
        </div>
        <div class="">
            <p>OpenPrice <span style="font-weight:400; font-size:20px; color: #e839f1;">{{ $lastResult['randomprice']  }}</span></p>
        </div>
    </div>
    <div class="row">
         <div class="col-sm-4 col-xs-4 result text-Red">
        
            <p style="font-weight:400;
    font-size:16px;">Red:<span style="display: inline; font-weight:400;
    font-size:16px;">{{ $totalRed }}</span></p>
        </div>
        <div class="col-sm-4 col-xs-4 price-section text-Green">
           
            <p style="font-weight:400; font-size:16px;">Green:<span style="display: inline; font-weight:400;
    font-size:16px;">{{ $totalGreen }}</span></p>
        </div>
       
        
        <div class="col-sm-4 col-xs-4 text-Violet">
            <p style="font-weight:400;
    font-size:16px;">Violet:<span style="display: inline; font-weight:400;
    font-size:16px;">{{ $totalCounts['violet'] }}</span></p>
        </div>
    </div>
  </div>
</div>

<div class="container text-center">
    <div class="">
        <div class="row" style="padding-bottom:10px;">
             <div class="col-sm-12 text-center" style="margin-bottom:5px;">
               
             <div style="float:right" role="group" aria-label="Basic example">
                <button type="button" style="padding: 7px; outline: none;" class="btn btn-{{$ShowPeriod == 2?'success':'outline-dark'}} changeBts button2" onclick="changeLayout(2)">ShowPeriod</button>
                <button type="button" style="padding: 7px; outline: none;" class="btn btn-{{$ShowPeriod == 1?'success':'outline-dark'}} changeBts button1" onclick="changeLayout(1)">ShowOpenNum</button>
            </div>
        </div>
        </div>
        <div class="row">
            <div class="heading">
                <div class="resultHead">
                    @php
                    if($mxColumn > 0){
                        for($i = 1; $i <= $mxColumn; $i++){
                    @endphp
                        <div class="head-item">{{ $i }}</div>
                    @php
                        }
                    }
                    @endphp
                </div>
            </div>
            <div class="results">
            <div class="resultBox">
            @php
                if(count($resultData) > 0){
                @endphp
                    @foreach($resultData as $result)
                    <div class="resultRow">
                    @php
                    if($mxColumn > 0){
                        for($i = 0; $i < $mxColumn; $i++){
                        @endphp
                            <div class="rowItem">
                            @if(isset($result[$i]))
                            @php
                                $textColor = 'Red';
                            @endphp
                            @if(trim($result[$i]['resulttype']) == 'random')
                                @if(strtolower($result[$i]['randomcolor']) == 'green')
                                    @php  $textColor = 'Green'; @endphp
                                @elseif(strtolower($result[$i]['randomcolor']) == 'green++violet' ||  strtolower($result[$i]['randomcolor']) == 'green+violet' || strtolower($result[$i]['randomcolor']) == 'green & violet')
                                    @php  $textColor = 'VioletGreen'; @endphp
                                @elseif(strtolower($result[$i]['randomcolor']) == 'red++violet' ||  strtolower($result[$i]['randomcolor']) == 'red+violet'  || strtolower($result[$i]['randomcolor']) == 'red & violet')
                                    @php  $textColor = 'VioletRed'; @endphp
                                @endif
                            @endif

                            @if(trim($result[$i]['resulttype']) == 'real')
                                @if(strtolower($result[$i]['color']) == 'green')
                                    @php  $textColor = 'Green'; @endphp
                                @elseif(strtolower($result[$i]['color']) == 'green++violet' || strtolower($result[$i]['color']) == 'green+violet' || strtolower($result[$i]['color']) == 'green & violet')
                                    @php  $textColor = 'VioletGreen'; @endphp
                                @elseif(strtolower($result[$i]['color']) == 'red++violet' || strtolower($result[$i]['color']) == 'red+violet' || strtolower($result[$i]['color']) == 'red & violet')
                                    @php  $textColor = 'VioletRed'; @endphp
                                @endif
                            @endif

                                <span class="item{{ $textColor }} showData showData1">{{ $result[$i]['resulttype'] == 'random' ? $result[$i]['randomresult']:$result[$i]['result'] }}</span>
                                <span class="item{{ $textColor }} showData showData2">{{ substr($result[$i]['periodid'], -3) }}</span>
                            @else
                                &nbsp;
                            @endif
                            </div>
                        @php
                        }
                    }
                    @endphp
                    </div>


                    @endforeach
                @php
                }
                @endphp
            </div>
            </div>
        </div>
    </div>
</div><br>

<div class="container-fluid bg-3 text-center">
   
     
                 
                <div style="margin-bottom:8px;">
                     <ul class="nav nav-tabs size1" id="myTab3" role="tablist">
        <li class="nav-item"> 
<a class="nav-link active" id="home-tab3" data-toggle="tab"  role="tab" onClick="changeRD(3,2)">Rd.3</a> 
        </li>
     <li class="nav-item"> 
<a class="nav-link" id="home-tab3" data-toggle="tab" role="tab" onClick="changeRD(4,2)">Rd.4</a> 
        </li>
          <li class="nav-item"> 
<a class="nav-link" id="home-tab3" data-toggle="tab" role="tab" onClick="changeRD(5,2)">Rd.5</a> 
        </li>
          <li class="nav-item"> 
<a class="nav-link" id="home-tab3" data-toggle="tab" role="tab" onClick="changeRD(6,2)">Rd.6</a> 
        </li>
          <li class="nav-item"> 
<a class="nav-link" id="home-tab3" data-toggle="tab" role="tab" onClick="changeRD(7,2)">Rd.7</a> 
        </li>
          <li class="nav-item"> 
<a class="nav-link" id="home-tab3" data-toggle="tab" role="tab" onClick="changeRD(8,2)">Rd.8</a> 
        </li>
      </ul>
                </div>
               
      
        <div class="row" id="bottomTable">
            <div class="heading">
                <div class="resultHead">
                    @php
                        for($i = 1; $i <= $ShowRD; $i++){
                    @endphp
                        <div class="head-item">{{ $i }}</div>
                    @php
                    }
                    @endphp
                </div>
            </div>
            <div class="results">
            <div class="resultBox">
            @php
                if(count($results) > 0){
                @endphp
                @php
                    $i = 1;
                @endphp
                <div class="resultRow">
                    @foreach($results as $result)
                            <div class="rowItem">
                            @if(isset($result))
                            @php
                                $textColor = 'Red';
                            @endphp
                            @if(trim($result['resulttype']) == 'random')
                                @if($result['randomcolor'] == 'green')
                                    @php  $textColor = 'Green'; @endphp
                                @elseif(strtolower($result['randomcolor']) == 'green++violet' || strtolower($result['randomcolor']) == 'green+violet' || strtolower($result['randomcolor']) == 'green & violet')
                                    @php  $textColor = 'VioletGreen'; @endphp
                                @elseif(strtolower($result['randomcolor']) == 'red++violet' || strtolower($result['randomcolor']) == 'red+violet' || strtolower($result['randomcolor']) == 'red & violet')

                                    @php  $textColor = 'VioletRed'; @endphp
                                @endif
                            @endif
                            @if(trim($result['resulttype']) == 'real')
                                @if($result['color'] == 'green')
                                    @php  $textColor = 'Green'; @endphp
                                @elseif($result['color'] == 'green++violet')
                                    @php  $textColor = 'VioletGreen'; @endphp
                                @elseif($result['color'] == 'red++violet')
                                    @php  $textColor = 'VioletRed'; @endphp
                                @endif
                            @endif
                                <span class="item{{ $textColor }} showData showData1">{{ trim($result['resulttype']) == 'random' ? $result['randomresult'] : $result['result'] }}</span>
                                <span class="item{{ $textColor }} showData showData2">{{ substr($result['periodid'], -3) }}</span>
                            @else
                                &nbsp;
                            @endif
                            </div>

                            @if($i % $ShowRD == 0)
                            </div>
                            <div class="resultRow">
                            @endif
                            @php
                                $i++;
                            @endphp
                    @endforeach
                    </div>

                @php
                }
                @endphp
            </div>
            </div>
        </div>
    </div>
</div><br>
<!--Progress bar-->
 <?php $con = mysqli_connect("localhost","rxin_moneygame007","rxin_moneygame007","rxin_moneygame007");
    
    $sql0 = "SELECT * from `tbl_result` where `randomresult`='0'  and `tabtype`='parity'";
	if ($fetche0 = mysqli_query($con, $sql0));
	$fetch0 = mysqli_num_rows( $fetche0 );
	
	$sql1 = "SELECT * from `tbl_result` where `randomresult`='1'  and `tabtype`='parity'";
	if ($fetche1 = mysqli_query($con, $sql1));
	$fetch1 = mysqli_num_rows( $fetche1 );
	
	$sql2 = "SELECT * from `tbl_result` where `randomresult`='2'  and `tabtype`='parity'";
	if ($fetche2 = mysqli_query($con, $sql2));
	$fetch2 = mysqli_num_rows( $fetche2 );
	
	
	$sql3 = "SELECT * from `tbl_result` where `randomresult`='3'  and `tabtype`='parity'";
	if ($fetche3 = mysqli_query($con, $sql3));
	$fetch3 = mysqli_num_rows( $fetche3 );
	
	$sql4 = "SELECT * from `tbl_result` where `randomresult`='4'  and `tabtype`='parity'";
	if ($fetche4 = mysqli_query($con, $sql4));
	$fetch4 = mysqli_num_rows( $fetche4 );
	
	$sql5 = "SELECT * from `tbl_result` where `randomresult`='5'  and `tabtype`='parity'";
	if ($fetche5 = mysqli_query($con, $sql5));
	$fetch5 = mysqli_num_rows( $fetche5 );
	
	$sql6 = "SELECT * from `tbl_result` where `randomresult`='6'  and `tabtype`='parity'";
	if ($fetche6 = mysqli_query($con, $sql6));
	$fetch6 = mysqli_num_rows( $fetche6 );
	
	$sql7 = "SELECT * from `tbl_result` where `randomresult`='7'  and `tabtype`='parity'";
	if ($fetche7 = mysqli_query($con, $sql7));
	$fetch7 = mysqli_num_rows( $fetche7 );
	
	$sql8 = "SELECT * from `tbl_result` where `randomresult`='8'  and `tabtype`='parity'";
	if ($fetche8 = mysqli_query($con, $sql8));
	$fetch8 = mysqli_num_rows( $fetche8 );
	
	$sql9 = "SELECT * from `tbl_result` where `randomresult`='9'  and `tabtype`='parity'";
	if ($fetche9 = mysqli_query($con, $sql9));
	$fetch9 = mysqli_num_rows( $fetche9 );
    ?>

<div class="container-fluid bg-3">
    <div class="">
        <div class="row">
            <div class="col-sm-12">
                @php
                    $totalRec = count($results);
                    $redPercnt = $greenPercnt = $violetPercnt = 0;
                    if($totalRed > 0){ $redPercnt = number_format(floatval($totalRed / $totalRec)*100,2); }
                    if($totalGreen > 0){ $greenPercnt = number_format(floatval($totalGreen / $totalRec)*100,2); }
                    if($totalCounts['violet'] > 0){ $violetPercnt = number_format(floatval($totalCounts['violet'] / $totalRec)*100,2); }
                @endphp
                  <div class="progress">
                    <div class="progress-bar progress-bar-danger progress-bar-striped" role="progressbar" aria-valuenow="{{ $redPercnt }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ $redPercnt }}%">
                        <span class="sr-only">Red:{{ $totalRed }}</span>
                    </div>
                </div>
                
                    <div class="progress">
                    <div class="progress-bar progress-bar-success progress-bar-striped" role="progressbar" aria-valuenow="{{ $greenPercnt }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ $greenPercnt }}%">
                        <span class="sr-only">Green:{{ $totalGreen }}</span>
                    </div>
                </div>
              
                <div class="progress">
                    <div class="progress-bar progress-bar-warning progress-bar-striped" role="progressbar" aria-valuenow="{{ $violetPercnt }}" aria-valuemin="0" aria-valuemax="100" style="width: {{ $violetPercnt }}%">
                        <span class="sr-only">Violet:{{ $totalCounts['violet'] }}</span>
                    </div>
                </div>
                
                <div class="progress">
                      <div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="<?php echo $fetch0;?>" aria-valuemin="0" aria-valuemax="{{ $totalRec }}" style="width: <?php echo $fetch0;?>%">
                        <span class="sr-only">0:<?php echo $fetch0;?></span>
                    </div>
                </div>
                
                <div class="progress">
                      <div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="<?php echo $fetch1;?>" aria-valuemin="0" aria-valuemax="{{ $totalRec }}" style="width: <?php echo $fetch1;?>%">
                        <span class="sr-only">1:<?php echo $fetch1;?></span>
                    </div>
                </div>
                
                <div class="progress">
                      <div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="<?php echo $fetch2;?>" aria-valuemin="0" aria-valuemax="{{ $totalRec }}" style="width: <?php echo $fetch2;?>%">
                        <span class="sr-only">2:<?php echo $fetch2;?></span>
                    </div>
                </div>

                <div class="progress">
                      <div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="<?php echo $fetch3;?>" aria-valuemin="0" aria-valuemax="{{ $totalRec }}" style="width: <?php echo $fetch3;?>%">
                        <span class="sr-only">3:<?php echo $fetch3;?></span>
                    </div>
                </div>

                <div class="progress">
                      <div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="<?php echo $fetch4;?>" aria-valuemin="0" aria-valuemax="{{ $totalRec }}" style="width: <?php echo $fetch4;?>%">
                        <span class="sr-only">4:<?php echo $fetch4;?></span>
                    </div>
                </div>
                
                <div class="progress">
                      <div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="<?php echo $fetch5;?>" aria-valuemin="0" aria-valuemax="{{ $totalRec }}" style="width: <?php echo $fetch5;?>%">
                        <span class="sr-only">5:<?php echo $fetch5;?></span>
                    </div>
                </div>
                
                <div class="progress">
                      <div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="<?php echo $fetch6;?>" aria-valuemin="0" aria-valuemax="{{ $totalRec }}" style="width: <?php echo $fetch6;?>%">
                        <span class="sr-only">6:<?php echo $fetch6;?></span>
                    </div>
                </div>
                
                <div class="progress">
                      <div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="<?php echo $fetch7;?>" aria-valuemin="0" aria-valuemax="{{ $totalRec }}" style="width: <?php echo $fetch7;?>%">
                        <span class="sr-only">7:<?php echo $fetch7;?></span>
                    </div>
                </div>
                
                <div class="progress">
                      <div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="<?php echo $fetch8;?>" aria-valuemin="0" aria-valuemax="{{ $totalRec }}" style="width: <?php echo $fetch8;?>%">
                        <span class="sr-only">8:<?php echo $fetch8;?></span>
                    </div>
                </div>
                
                <div class="progress">
                      <div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="<?php echo $fetch9;?>" aria-valuemin="0" aria-valuemax="{{ $totalRec }}" style="width: <?php echo $fetch9;?>%">
                        <span class="sr-only">9:<?php echo $fetch9;?></span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div><br><br>
<input type="hidden" name="counter" id="counter" class="form-control" >
<input type="hidden" id="changeLayoutRow" value="{{ $ShowPeriod }}">
<input type="hidden" id="ShowRDRow" value="{{ $ShowRD }}">
<script>
    @if($ShowPeriod == 2)
        $(document).ready(function(){
            var changeLayoutRow = $('#changeLayoutRow').val();
            changeLayout(changeLayoutRow);
        });
    @endif
    @if($ShowRD == 3)
        $(document).ready(function(){
            var ShowRDRow = $('#ShowRDRow').val();
            changeRD(ShowRDRow, 1);
        });
    @endif

    function changeLayout(rowId){
        $('.changeBts').removeClass('btn-success').addClass('btn-outline-dark');
        $('.button'+rowId).addClass('btn-success');
        $('.showData').hide();
        $('.showData'+rowId).show();
        $('#changeLayoutRow').val(rowId);
        $.ajax({
            type: 'POST',
            url: '{{ url("/set-show-period") }} ',
            data: {"_token": "{{ csrf_token() }}", rowId:rowId},
            success: function(msg){
            }
        });

    }
     function changeRD(columNo, time){
        $('.changeRDBts').removeClass('btn-success').addClass('btn-outline-dark');
        $('.rdButton'+columNo).addClass('btn-success');
        $.ajax({
            type: 'POST',
            url: '{{ url("/get-column-records") }} ',
            data: {"_token": "{{ csrf_token() }}", columNo:columNo},
            success: function(msg){
                $('#bottomTable').html(msg);
                var changeLayoutRow = $('#changeLayoutRow').val();
                changeLayout(changeLayoutRow);
                if(time == 1){ $('.resultBox').animate({scrollLeft: 1000000000}, 500); }
            }
        });
    }

    //countdown
 	/*var timer2 = "03:00";
	var interval = setInterval(function() {

        var timer = timer2.split(':');
        //by parsing integer, I avoid all extra string processing
        var minutes = parseInt(timer[0], 10);
        var seconds = parseInt(timer[1], 10);
        if(minutes == 0 && seconds == 0){return false;}
        --seconds;
        minutes = (seconds < 0) ? --minutes : minutes;
        if (minutes < 0) clearInterval(interval);
            seconds = (seconds < 0) ? 59 : seconds;
            seconds = (seconds < 10) ? '0' + seconds : seconds;
            //minutes = (minutes < 10) ?  minutes : minutes;
            $('.hours').html(minutes);
            $('.minutes').html(seconds);
            timer2 = minutes + ':' + seconds;
            if(timer2 == '0:02'){
               location.reload();
               return false;
            }

	}, 1000);*/

    $(document).ready(function () {

   var x = setInterval(function() {
            start_count_down();
        }, 1e3);
   });

    function start_count_down() {
        $(".showload").hide();
        $(".none").show();
        var countDownDate = Date.parse(new Date) / 1e3;
        var now = new Date().getTime();
        var distance = 180 - countDownDate % 180;
        //alert(distance);
        var i = distance / 60,
        n = distance % 60,
        o = n / 10,
        s = n % 10;
        var minutes = Math.floor(i);
        var seconds = ('0'+Math.floor(n)).slice(-2);
        document.getElementById("countdown").innerHTML = "<li> <span style='font-size:20px; color: #0f1223; font-weight:400;background: #F2F2F2;border-radius:5px;' class='hours'>0"+Math.floor(minutes)+"</span></li><li> <span style='font-size:20px; color: #0f1223; font-weight:400;background: #F2F2F2;border-radius:5px;' class='minutes'>"+seconds+"</span></li>";
        document.getElementById("counter").value = distance;
        if(minutes <= 0 && seconds <= 1){
            setTimeout(function(){location.reload();},10000);
               return false;
            }

}


</script>
<style>
.progress-bar-warning {
    background-color: #e839f1;
}
.sr-only {
    overflow: initial;
    clip: auto;
    width: auto;
}
</style>
