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

<div class="container">
            <div class="row">
            <div class="col-sm-12">
                    <div class="mobilesecitoninner" >                   
                        <div id="homepageseciton">                  
                  
                            <div class="megacontentbiscion"  >  
                                <h2> Quiz Contest Question </h2> 
                                <div class="megacontentdata">
                                    <div class="questionderailseciton">
                                        <form action="{{ SITEURL }}saveuseranswersheet" method="post">
                                            <ul>
                                                <?php    ////   echo '<pre>'; print_r($contestquestions); echo '</pre>'; exit;
                                                
                                            $quesitonsidarray =  explode(',',$contestquestions->quesitonsid);

                                            $questionsdetails = DB::table('questionsdetails')->whereIn('id', $quesitonsidarray)->orderBy('id', 'DESC')->get();

                                            $countert = 1; 

                                            foreach(  $questionsdetails as  $questionsdetailsdata ) {
                                             
                                                $teamsdetails = DB::table('teamsdetails')->where('id', $contestquestions->firstteamid)->orderBy('id', 'DESC')->first();
                                                $teamsdetailsecond = DB::table('teamsdetails')->where('id', $contestquestions->secondteamid)->orderBy('id', 'DESC')->first();

                                                         $urldatafirst = SITEURL.'public/newlogo.jpg';
                                                         $urldatasecond = SITEURL.'public/newlogo.jpg';
                                                        if($teamsdetails->teamimg > 0) { 
                                                            $attachements = DB::table('attachements')->where('id', $teamsdetails->teamimg)->first();
                                                                if($attachements) { $urldatafirst = SITEURL.'files/'.$attachements->att_url; }
                                                            }

                                                            if($teamsdetailsecond->teamimg > 0) { 
                                                                $attachements = DB::table('attachements')->where('id', $teamsdetailsecond->teamimg)->first();
                                                                    if($attachements) { $urldatasecond = SITEURL.'files/'.$attachements->att_url; }
                                                                }  
                                                         ?>
                                               <li> 
                                                    <h5> Question  {{ $countert }} : {{ $questionsdetailsdata->questiontitle }}  <h5>
                                                    <p>  ( {{ $questionsdetailsdata->questionhindi }} ) </p>
                                                    <?php if($questionsdetailsdata->questiontype == 1) { ?>
                                                        <div class="plaeyrslissection">
                                                           
                                                            <div class="row">
                                                                <div class="col-6">
                                                                    <div class="plaerysshow">
                                                                        <h2> {{ $contestquestions->firstteamname }}   </h2>
                                                                        <ul>
                                                                            <li>
                                                                                <div  class="playerlistsecitonteam">
                                                                                    <img src="{{ $urldatafirst }}" alt="{{ $teamsdetails->teamshtname }}"> 
                                                                                    <input type="text" maxlength="3" name="teamdata[{{ $questionsdetailsdata->id }}][{{ $contestquestions->firstteamid }}]" id="playerrumcounting1" placeholder="Enter Your Answer" class="form-control playerrumcounting1"  onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" required> 
                                                                                    <div class="selected playerselected1"> <img src="{{ SITEURL }}public/frontend/images/rightcheck.png" alt=""> </div>
                                                                         
                                                                                </div>
                                                                            </li> 
                                                                        </ul>
                                                                    </div> 
                                                                </div> 

                                                                <div class="col-6">
                                                                    <div class="plaerysshow">
                                                                        <h2> {{ $contestquestions->secondteamname }}   </h2>
                                                                        <ul>
                                                                            <li>
                                                                                <div  class="playerlistsecitonteam">
                                                                                    <img src="{{ $urldatasecond }}" alt="{{ $teamsdetailsecond->teamshtname }}"> 
                                                                                    <input type="text" maxlength="3"   name="teamdata[{{ $questionsdetailsdata->id }}][{{ $contestquestions->secondteamid }}]" id="playerrumcounting21" placeholder="Enter Your Answer" class="form-control playerrumcounting21"  onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" required>

                                                                                     
                                                                                    <div class="selected playerselected21"> <img src="{{ SITEURL }}public/frontend/images/rightcheck.png" alt=""> </div>
                                                                                </div>
                                                                            </li> 
                                                                        </ul>
                                                                    </div> 
                                                                </div> 
                                                                
                                                            </div>  
                                                             
                                                        </div> 

                                                        <?php } 
                                                        
                                                       else if($questionsdetailsdata->questiontype == 2) {
                                                       $playercount =  $questionsdetailsdata->playercount;
                                                        ?> 
                                                         <div class="row">
                                        <div class="col-6">
                                            <div class="plaerysshow">
                                                <h2>{{ $contestquestions->firstteamname }}   </h2>
                                                <ul>
                                                    <?php
                                                     $teamplayerslist = DB::table('teamplayerslist')->where('teamid', $contestquestions->firstteamid)->orderBy('id', 'DESC')->get(); 
                                                        foreach( $teamplayerslist as  $teamplayerslistdata) {
                                                            $playersdetails = DB::table('players')->where('id', $teamplayerslistdata->playerid)->orderBy('id', 'DESC')->first();
                                                            $playerfirstimg = SITEURL.'public/frontend/images/teamplayer1.png';
                                                            /// echo '<pre>'; print_r($playersdetails ); echo '</pre>'; exit;
                                                            if($playersdetails) { 
                                                                 if($playersdetails->playerimg > 0) { 
                                                                        $attachements = DB::table('attachements')->where('id', $playersdetails->playerimg)->first();
                                                                   if($attachements) { $playerfirstimg = SITEURL.'files/'.$attachements->att_url; }
                                                               }
                                                            }
                                                     ?>
                                                    <li>
                                                        <div class="playerlistseciton">
                                                            <img src="{{ $playerfirstimg }}"  dataid=".playerselected{{  $playersdetails->id  }}"  datashow=".playerrumcounting{{  $playersdetails->id  }}" alt="Team 1">
                                                            <h3> {{  $playersdetails->playername  }}</h3>
                                                            <input type="text" maxlength="3" disabled name="playersdata[{{ $questionsdetailsdata->id }}][{{  $playersdetails->id  }}]" id="playerrumcounting{{  $playersdetails->id  }}" placeholder="Enter Your Answer" class="form-control playerrumcounting{{  $playersdetails->id  }}"  onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" required>
                                                            <div class="selected playerselected{{  $playersdetails->id  }}"> <img src="{{ SITEURL }}public/frontend/images/rightcheck.png" alt="{{  $playersdetails->playername  }}"> </div>
                                                            
                                                        </div>
                                                    </li>
                                                    <?php } ?>
                                                </ul>
                                            </div> 
                                        </div> 

                                        <div class="col-6">
                                            <div class="plaerysshow">
                                                <h2>  {{ $contestquestions->secondteamname }} </h2>
                                                <ul>
                                                <?php
                                                     $teamplayerslistsecond = DB::table('teamplayerslist')->where('teamid', $contestquestions->secondteamid)->orderBy('id', 'DESC')->get(); 
                                                        foreach( $teamplayerslistsecond as  $teamplayerslistseconddata) {
                                                            $playersdetailsecond = DB::table('players')->where('id', $teamplayerslistseconddata->playerid)->orderBy('id', 'DESC')->first();
                                                            $playersecondimg = SITEURL.'public/frontend/images/teamplayer1.png';
                                                            if($playersdetailsecond) { 
                                                                 if($playersdetailsecond->playerimg > 0) { 
                                                                        $attachements = DB::table('attachements')->where('id', $playersdetailsecond->playerimg)->first();
                                                                   if($attachements) { $playersecondimg = SITEURL.'files/'.$attachements->att_url; }
                                                               }
                                                            } 
                                                     ?>
                                                    <li>
                                                        <div  class="playerlistseciton">
                                                            <img src="{{  $playersecondimg }}"  dataid=".playerselected{{  $playersdetailsecond->id  }}" datashow=".playerrumcounting{{  $playersdetailsecond->id  }}" alt="Team 1">
                                                            <h3>{{  $playersdetailsecond->playername  }}</h3>
                                                            <input type="text" maxlength="3" disabled name="playersdata[{{ $questionsdetailsdata->id }}][{{  $playersdetailsecond->id  }}]" id="playerrumcounting{{  $playersdetailsecond->id  }}" placeholder="Enter Your Answer" class="form-control playerrumcounting{{  $playersdetailsecond->id  }}"  onkeyup="if (/\D/g.test(this.value)) this.value = this.value.replace(/\D/g,'')" required>

                                                      
                                                            <div class="selected playerselected{{  $playersdetailsecond->id  }}"> <img src="{{ SITEURL }}public/frontend/images/rightcheck.png" alt="{{  $playersdetailsecond->playername  }}"> </div>
                                                        </div>
                                                    </li>
                                                    <?php } ?>
                                                    
                                                </ul>
                                            </div> 
                                            </div> 
                                            <div class="col-12">
                                                <input type="hidden" name="userid" id="userid" value="{{  Auth::user()->id }}">
                                                {!! csrf_field() !!}
                                            </div>
                                        </div>  
                                                        
                                                        <?php } 
                                                        
                                                         else {   ?>   

                                                        <input type="text" name="userchoice[{{ $questionsdetailsdata->id }}][]" id="userchoice" maxlength="150" class="form-control" placeholder="Enter Your Answer" required>

                                                        <?php } ?>
                                                </li>

                                            <?php    $countert =    $countert + 1;   } ?>

                                              </ul>

                                              <div class="col-12">       
                                              <input type="hidden"  name="leagueid" id="leagueid" value="{{ $contestquestions->leagueid }}">
                                              <input type="hidden"  name="matchid" id="matchid" value="{{ $contestquestions->matchid }}">
                                              <input type="hidden"  name="contestid" id="contestid" value="{{ $contestquestions->contestid }}">
                                              <input type="hidden"  name="teamidfirst" id="teamidfirst" value="{{ $contestquestions->firstteamid }}">
                                              <input type="hidden"  name="teamidsecond" id="teamidsecond" value="{{ $contestquestions->secondteamid }}">
                                              <input type="hidden"  name="questionid" id="questionid" value="{{ $contestquestions->quesitonsid }}">
                                              <input type="hidden"  name="matchname" id="matchname" value="{{ $contestquestions->matchname }}">

                                                <input type="hidden"  name="playercount" id="playercount" value="{{ $playercount }}">
                                                    <input type="submit" id="submituserform" class="submitdata" value="Save">
                                                </div>

                                              </form>
                                        </div>
                                    </div>
                                </div>

                        </div>
                    </div>
            </div>
        </div>
    </div>
<script> 
     
    $( document ).ready(function() {
        $( ".playerlistseciton img" ).on( "click", function() {
           var hdowiddata = $(this).attr('dataid');
           var playercount = $('#playercount').val();
          var countplayers =  $('.playerlistseciton input[type="text"]:enabled').filter(function(){return $(this).val()=="";}).length;
           if(parseInt(countplayers) < parseInt(playercount) )
                    {
                    var feilsinable = $(this).attr('datashow');
                    if($(feilsinable).is(':disabled')){
                            $(hdowiddata).fadeIn(); 
                            $(feilsinable).prop('disabled', false);
                        } else {
                            $(hdowiddata).fadeOut();
                            $(feilsinable).prop('disabled', true); 
                        }
                    }
           return false;
        });

 
    });
   
</script>
@endsection   