@extends('layouts.front')    
@section('content')


<div class="contest-detail-page">
    <div class="mobilesecitoninner" > 
        @if (Session::has('sucmessage')) 
        <div class="alert alert-success alert-dismissible show fade">
            <div class="alert-body">
                <button class="close" data-dismiss="alert">
                    <span>&times;</span>
                </button>
                {{ Session::get('sucmessage') }}
            </div>
        </div> 
        @endif
        @if (Session::has('message')) 
        <div class="alert alert-danger alert-dismissible show fade">
            <div class="alert-body">
                <button class="close" data-dismiss="alert">
                    <span>&times;</span>
                </button>
                {{ Session::get('message') }}
            </div>
        </div>
        @endif                  
        <div id="homepageseciton">                  
            <div class="megacontentbiscion">  
                <div class="megacontentdata">
                    <?php   date_default_timezone_set("Asia/Calcutta");                         
                        $contestprizeamt = explode(',',$matchcobntests->contestprizeamt);
                        $conteststartseat = explode(',',$matchcobntests->conteststartseat);
                        $contestendseat = explode(',',$matchcobntests->contestendseat);
                        //// echo '<pre>'; print_r($matchcobntests); echo '</pre>'; exit;
                        $gameplayhistorycount = DB::table('gameplayhistory')->where('contestid', $matchcobntests->id)->orderBy('id', 'DESC')->count();
                        $remaingseat =  $matchcobntests->contestseat -  $gameplayhistorycount;
                        $appliedseat =  $gameplayhistorycount / $matchcobntests->contestseat *100 ;
                        $compitetionassignment = DB::table('compitetionassignment')->where('compitetionid', $matchcobntests->id)->orderBy('id', 'DESC')->first();
                     ?>
                    <span> <i class="fa fa-check" aria-hidden="true"></i>{{ $compitetionassignment->groupclassname }}  </span>
                    <h3>{{ $matchcobntests->contesttitile }}  </h3>
                    <div class="progress">
                        <div class="progress-bar progress-bar-success progress-bar-striped" role="progressbar"   aria-valuenow="{{ $appliedseat }}" aria-valuemin="0" aria-valuemax="100" style="width:{{ $appliedseat }}%">
                            {{ $appliedseat }}% Joined
                        </div>
                    </div>
                    <p>{{  $remaingseat }} Left  <span>{{ $matchcobntests->contestseat }}  Spot </span> </p>
                    <?php  /// echo '<pre>'; print_r($matchcobntests); echo '</pre>'; exit;                                     
                            //// echo '<pre>'; print_r($compitetionassignment); echo '</pre>'; exit; 
                        if($compitetionassignment ) {
                            $gameplayhistory = DB::table('gameplayhistory')->where('questionsetid', $compitetionassignment->questionsetid)->where('contestid', $matchcobntests->id)->where('userid', Auth::user()->id)->orderBy('id', 'DESC')->get();
                                if( count($gameplayhistory) >= $matchcobntests->userentery  ) { ?> 
                                    <span class="btn btn-block btn-danger">Joined  &#8377;{{ number_format($matchcobntests->joinamt,2) }}</span>
                                    <?php } else { ?> 
                                    <a class="btn btn-block btn-primary" style="width:100%;" data-toggle="modal" href="#myModal">   Join &#8377;{{ number_format($matchcobntests->joinamt,2) }} </a> 
                                    <?php  }  }  ?>
                                    <!-- Modal -->
                                    <div id="myModal" class="modal fade" role="dialog">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <div class="modal-header">                                   
                                                    <h4 class="modal-title">Competition Exam Join Confirmation</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <p>After Confirmation Join Charges will be &#8377;{{ number_format($matchcobntests->joinamt,2) }} apllied.</p>
                                                </div>
                                                <div class="modal-footer">
                                                    <a class="btn btn-success" href="{{ SITEURL }}competitionjoin/{{ $compitetionassignment->id }}?amount={{ $matchcobntests->joinamt }}"> Confirm</a>
                                                    <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                        <?php /* >
                                        <div id="myModal2" class="modal fade" role="dialog">
                                        <div class="modal-dialog">

                                            <!-- Modal content-->
                                            <div class="modal-content">
                                            <div class="modal-header">
                                            
                                                <h4 class="modal-title">Alert Competition Exam  Join  </h4>
                                            </div>
                                            <div class="modal-body">
                                                <p>Yopu have Alreay Joined &#8377;{{ number_format($matchcobntests->joinamt,2) }} Competition . You can not Apply After Given Chances </p>
                                            </div>
                                            <div class="modal-footer">  
                                                <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                            </div>
                                            </div>

                                        </div>
                                        </div>
                                        <?php */?>
                                    <div id="myModal3" class="modal fade" role="dialog">
                                        <div class="modal-dialog">
                                            <div class="modal-content">
                                                <div class="modal-header">                                            
                                                <h4 class="modal-title">Exam Submit</h4>
                                                </div>
                                                <div class="modal-body">
                                                    <p>You have Alreay Submited Competition Exam . Best of Luck for Next Time... </p>
                                                </div>
                                                <div class="modal-footer">  
                                                    <button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="datdetailseciton row">                                                  
                                        <div class="col-6">
                                            <span> Result Date </span>
                                            <p> {{ date('d-m-Y', strtotime($compitetionassignment->resultdate))   }}</p>
                                        </div>
                                        <div class="col-6" style="text-align:center;">
                                            <span> Exam Date and Time</span>
                                            <p>{{ date('d-m-Y', strtotime($compitetionassignment->examdate)) }} Till: {{ date('h:i A', strtotime($compitetionassignment->examendtime)) }}</p>
                                        </div>
                                    </div>
                                    <div class="otgerdetails">
                                        <ul>
                                            <li  data-toggle="tooltip" title="First Prize"><img src="{{ SITEURL }}public/frontend/images/firstprize.png" alt="First Prize">  {{ $contestprizeamt[0] }} </li>
                                            <li  data-toggle="tooltip" title="Winning Percentage">  <img src="{{ SITEURL }}public/frontend/images/trophyicons.jpg" alt="First Prize">  {{ $matchcobntests->winpertange }}%  </li>
                                            <li  data-toggle="tooltip" title="Last Rank"> <img src="{{ SITEURL }}public/frontend/images/sideicons.jpg" alt="First Prize">  {{ end($contestendseat) }}  </li>
                                        </ul>
                                    </div>
                                </div> 
                                <?php $gameplayhistory = DB::table('gameplayhistory')->where('contestid', $matchcobntests->id)->where('userid', Auth::user()->id)->orderBy('id', 'DESC')->first();
                                       //// echo '<pre>'; print_r($gameplayhistory); echo '</pre>';  
                                    if( $gameplayhistory) { ?>
                                <div class="exampartdata">
                                    <?php 
                                        $useranswerdetails = DB::table('useranswerdetails')->where('competitionid', $matchcobntests->id)->where('createdby', Auth::user()->id)->orderBy('id', 'DESC')->first();                                    
                                            if($useranswerdetails) { ?>
                                                <a class="btn btn-block btn-warning" style="width:100%;"   data-toggle="modal" href="#myModal3"> Exam Submited </a>
                                                <?php  /// echo strtotime(date('Y-m-d')) .' hello  '.  strtotime($compitetionassignment->answersheetdate);
                                                    if( strtotime(date('Y-m-d')) >= strtotime($compitetionassignment->answersheetdate) )  { ?>
                                                <a class="btn btn-block btn-info" style="width:100%;"  href="{{ SITEURL }}examsanswersheet/{{ $compitetionassignment->id }}"> Exam Answer Sheet </a>
                                                <?php } else {  ?>
                                                    <p class="resultddplsysection"> Exam Answersheet {{ date( 'd-m-Y',strtotime($compitetionassignment->answersheetdate) ) }}  </p>
                                                <?php } if( strtotime(date('Y-m-d')) >= strtotime($compitetionassignment->resultdate) ) { ?>
                                                <a class="btn btn-block btn-dark" style="width:100%;"  href="{{ SITEURL }}examsresultt/{{ $matchcobntests->id }}"> Exam Result </a>

                                                <?php }  }  else { 

                                                // echo  strtotime(date('H:i:s')); echo '<br /> ';
                                                /////  echo  strtotime($compitetionassignment->examendtime );
                                                    if( strtotime(date('Y-m-d')) == strtotime($compitetionassignment->examdate) && strtotime(date('H:i:s')) <=  strtotime($compitetionassignment->examendtime )  )  {
                                                    ?>
                                                    <a class="btn btn-block btn-success" style="width:100%;" href="{{ SITEURL }}examstart/{{ $compitetionassignment->id }}" >  Start Exam </a>
                                        <?php } }  ?>
                                </div> 
                                  <?php } ?>
                    </div>
                    <div class="leadboradsection">
                        <p><i class="fa fa-trophy"></i> Scholarship Details</p>
                    </div>

                    <div class="scholarship-banner">
                        <img src="{{ asset('public/frontend/images/scholarship_banner.png') }}" alt="Scholarship Rewards">
                    </div>
                    <div class="megacontentdata">                        
                        <div class="winninglist">
                            <ul>
                                <li>
                                    <p class="headelinghges"># Ranks <span>Scholarship</span></p>
                                </li>
                                <?php $cpimtu = 0; foreach($conteststartseat as $conteststartseatdata) { ?>
                                <li>
                                    <div class="rank-row">
                                        <div class="rank-left">
                                            <?php if($cpimtu < 3) { ?>
                                            <i class="fa fa-trophy"></i>
                                            <?php } ?>
                                            <span class="rank-number">
                                            <?php if($contestendseat[$cpimtu] > $conteststartseatdata) { ?>
                                            {{ $conteststartseatdata }} - {{ $contestendseat[$cpimtu] }}
                                            <?php } else { ?>
                                            {{ $conteststartseatdata }}
                                            <?php } ?>
                                            </span>
                                        </div>
                                        <div class="rank-prize">
                                        â‚¹{{ number_format($contestprizeamt[$cpimtu],2) }}
                                        </div>
                                    </div>
                                </li>
                                <?php $cpimtu++; } ?>
                            </ul>
                        </div>
                    </div>
            
        </div>
    </div>
</div>
<script>
$(document).ready(function(){
  $('[data-toggle="tooltip"]').tooltip();   
});
</script>
<script> 
     
    $( document ).ready(function() {
        $( "#showedetails" ).on( "click", function() {
            $('#password').attr('type', 'text'); 
            $('#showedetails').hide(); 
            $('#hideedetails').show(); 
        });

        $( "#hideedetails" ).on( "click", function() {
            $('#password').attr('type', 'password'); 
            $('#hideedetails').hide(); 
            $('#showedetails').show(); 
        });
        
    });
   
</script>
@endsection
