


<?php $__env->startSection('content'); ?>
<style>
.circle { 
   width: 140px;
   height: 140px;
   background: lightgray; 
   -moz-border-radius: 70px; 
   -webkit-border-radius: 70px; 
   border-radius: 70px;
}

.showtime-pill-wrapper {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
}
.showtime-pill-container {
    margin: 8px;
}
.showtime-pill-container .showtime-pill {
    border: 1px solid #999;
    color: #4abd5d;
    padding: 4px;
    border-radius: 4px;
    width: 120px;
    height: 40px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    position: relative;
    font-size: 80%;
}
.showtime-pill-container .showtime-pill .__details .__text {
    margin: 0 auto;
}
.showtime-pill-container .showtime-pill .__details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 0 2px;
    height: 14px;
}

.oval {
 background-color: ghostwhite;
}

.seat {
  
}

.seat.selected {
  
}

.seat.occupied {
  
}

.seata {
    display: inline-block;
    font-size: 10px;
    line-height: 25px;
    font-weight: 400;
    background: #fff;
    vertical-align: top;

    border: 1px solid #1ea83c;

    width: 25px;
    height: 25px;
    border-radius: 2px;
    color: #1ea83c;
    text-align: center;
    font-size: 10px;
}

a._available {
    display: inline-block;
    font-size: 11px;
    line-height: 25px;
    font-weight: 400;
    background: #fff;
    vertical-align: top;

    border: 1px solid #1ea83c;

    width: 25px;
    height: 25px;
    border-radius: 2px;
    color: #1ea83c;
    text-align: center;
    font-size: 11px;
}

a._available:hover {
  background-color: yellow;
}

a._blocked {

    display: inline-block;
    font-size: 11px;
    line-height: 25px;
    font-weight: 400;
    background: #fff;
    vertical-align: top;

    border: 1px solid grey;

    width: 25px;
    height: 25px;
    border-radius: 2px;
    color: #1ea83c;
    text-align: center;
    font-size: 11px;

    background: #e48787!important;
    cursor: default;
    color: #fff!important;
}

a._selected {
    display: inline-block;
    font-size: 11px;
    line-height: 25px;
    font-weight: 400;
    vertical-align: top;


    width: 25px;
    height: 25px;
    border-radius: 2px;
    text-align: center;
    font-size: 11px;

    color: #fff;
    background-color: #1ea83c!important;
    border-color: #1ea83c;
}

td {
    padding:  10px 5px 5px 5px !important;
}

.round-bottom { 
  border-bottom-left-radius: 50% 150px !important;
  border-bottom-right-radius: 50% 150px !important;
  position: relative;
  overflow: hidden;
  width: 160%; 
  margin-bottom:-50px;
  left:-30%; 
  background-color:#444;
  background-image:  background-position: center center;
  background-size: 42% auto;
  height:150px;
  color: white;
  text-align: center;
  font-size: 40px;
  vertical-align: middle;
}
.screencontainer { width: 100%; height: height:100px; padding-bottom:50px; overflow:hidden;}

.payment-method-radio {
  list-style-type: none;
  margin: 25px 0 0 0;
  padding: 0;
}

.payment-method-radio li {
  float: left;
  margin: 0 5px 0 0;
  width: 100px;
  height: 40px;
  position: relative;
}

.payment-method-radio label,
.payment-method-radio input {
  display: block;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.payment-method-radio input[type="radio"] {
  opacity: 0.01;
  z-index: 100;
  cursor: pointer;
}

.payment-method-radio input[type="radio"]:checked+label,
.Checked+label {
  background: lightgreen;
}

.payment-method-radio label {
  text-align: center;
  padding-top: 5px;
  padding-bottom: 5px;
  border: 1px solid #CCC;
  cursor: pointer;
  z-index: 90;
  border-radius: 4px;
  font-size: 80%;
  font-weight: bold;
}

.payment-method-radio label:hover {
  background: #DDD;
}
</style>
<?php
    $totalCount = $adultCount + $childCount;
?>
<script>
      const facilitiesarray = [];
      const showarray = [];   
      const seatnamearray = [];                                               
</script>
<form action="<?php echo url('/ticketpaymentprocessing'); ?>" method="post" enctype="multipart/form-data">
    <input type="hidden" id="loggedinUsername" name="loggedinUsername" value="<?php echo e($visitor_name); ?>">
    <input type="hidden" id="phone_number" name="phone_number" value="<?php echo e($phone_number); ?>">
    <input type="hidden" id="showDate" name="showDate" value="<?php echo e($date_of_visit); ?>">
    <input type="hidden" id="totalCount" name="totalCount" value="<?php echo e($totalCount); ?>">
    <input type="hidden" id="inputCentre" name="inputCentre" value="<?php echo e($inputCentre); ?>">
    <?php echo e(csrf_field()); ?>

    <!-- row -->
	<div class="container-fluid">
        <div class="row" id="facilitySelectdiv">
            <div class="col-xl-12">
				<div class="row">
					<div class="col-lg-12">
						<div class="card">
							<div class="card-header">
								<strong><?php echo e($organisation->organisation_name); ?>, &nbsp;<?php echo e($organisation->city); ?></strong>
                                <span class="float-right">
                                    <strong>Date:&nbsp;</strong><?php echo e(date('d-m-Y', strtotime($date_of_visit))); ?><br>
                                    <!--<strong>Adult:&nbsp;</strong><?php echo e($adultCount); ?>

                                    <strong>Child:&nbsp;</strong><?php echo e($childCount); ?>-->
                                </span>
                                <input type="hidden" name="adultCount" id="adultCount" value="<?php echo e($adultCount); ?>">
                                <input type="hidden" name="childCount" id="childCount" value="<?php echo e($childCount); ?>">
							</div>
							<div class="card-body">
								<div class="table-responsive">
                                    <table class="table table-sm table-responsive-lg mb-0" style="font-size:90%">
                                        <thead>
                                            <tr>
                                                <th class="align-middle">Facility</th>
                                                <th class="align-middle">Adult and Child Count</th>
                                                <th class="align-middle">Seats</th>
                                                <th class="align-middle pr-7">Amount</th>
                                                <th class="align-middle" style="min-width: 12.5rem;">Show Timings</th>
                                                <th class="no-sort"></th>
                                            </tr>
                                        </thead>

                                        <?php $__currentLoopData = $facilities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $facility): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

                                        <script>
                                            facilitiesarray.push(<?php echo e($facility->id); ?>)
                                        </script>
                                        <input type="hidden" name="iffacilitySelected<?php echo e($facility->id); ?>" id="iffacilitySelected<?php echo e($facility->id); ?>">
                                        <input type="hidden" name="showSelected<?php echo e($facility->id); ?>" id="showSelected<?php echo e($facility->id); ?>">
                                        <input type="hidden" name="iffacilityfixed<?php echo e($facility->id); ?>" id="iffacilityfixed<?php echo e($facility->id); ?>" value="<?php echo e($facility->fixedseatflag); ?>">

                                        <input type="hidden" name="famount<?php echo e($facility->id); ?>" id="famount<?php echo e($facility->id); ?>" value="0">

                                        <tr class="btn-reveal-trigger">
                                            <td class="py-2">
                                                <a href="#"><strong><?php echo e($facility->facility_name); ?></strong></a>
                                                <p><small> 
                                                    <?php $__currentLoopData = $facility->rates; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $rate): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                        Adult: &nbsp;<i class='fa fa-rupee'></i><?php echo e($rate->adult_rate); ?>

                                                        Child: &nbsp;<i class='fa fa-rupee'></i><?php echo e($rate->child_rate); ?>

                                                        <input type="hidden" name="rateadult<?php echo e($facility->id); ?>" id="rateadult<?php echo e($facility->id); ?>" value="<?php echo e($rate->adult_rate); ?>">
                                                        <input type="hidden" name="ratechild<?php echo e($facility->id); ?>" id="ratechild<?php echo e($facility->id); ?>" value="<?php echo e($rate->child_rate); ?>">
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                </small></p>
                                            </td>
                                            <td>
                                                <?php
                                                    $total = ($adultCount*1)+($childCount*1);
                                                ?>
                                                <div class="form-check form-check-inline">
                                                    Adult <input type="number" class="form-control xs" style="width: 75px;" name="adultCount<?php echo e($facility->id); ?>" id="adultCount<?php echo e($facility->id); ?>" value="<?php echo e($adultCount); ?>" onchange="checkseat('<?php echo e($facility->id); ?>');load_amount(<?php echo e($facility->id); ?>);">
                                                </div>
                                                <div class="form-check form-check-inline">
                                                    Child <input type="number" class="form-control xs" style="width: 75px;" name="childCount<?php echo e($facility->id); ?>" id="childCount<?php echo e($facility->id); ?>" value="<?php echo e($childCount); ?>" onchange="checkseat('<?php echo e($facility->id); ?>');load_amount(<?php echo e($facility->id); ?>);">
                                                    <input type="hidden" id="total_noof_adult_child<?php echo e($facility->id); ?>" name="total_noof_adult_child<?php echo e($facility->id); ?>" value="<?php echo e($total); ?>">
                                                </div>
                                            </td>
                                            <td class="py-2" align="center">
                                                <?php if($facility->noofseats): ?>
                                                    <strong><?php echo e($facility->noofseats); ?>&nbsp;</strong><p>
                                                    <span id="available<?php echo e($facility->id); ?>" style="color:blue; font-size: small; font-weight: bold;"></span></p> 
                                                <?php else: ?>
                                                    <i>NA</i>
                                                <?php endif; ?>
                                            </td>
                                            <td class="py-2">
                                              <span id="amount<?php echo e($facility->id); ?>" style="color:green; font-size: small; font-weight: bold;"></span>
                                            </td>
                                            <td class="py-2">
                                                <div class="showtime-pill-wrapper">
                                                <?php if($facilityon[$facility->id]): ?>
                                                    <?php $__currentLoopData = $facility->showtimings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $show): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>     
                                                        <?php if($show->show_flag==1): ?>   
                                                            <?php if($showon[$show->id]): ?>  
                                                                <?php $remark =""; ?> 
                                                                <?php if($show->remark): ?>
                                                                    <?php
                                                                        $remark = $show->remark;                                
                                                                    ?>
                                                                <?php endif; ?>                                                     
                                                                <div class="showtime-pill-container <?php echo e($facility->id); ?>" onclick="showselect(this, <?php echo e($facility->id); ?>, <?php echo e($show->id); ?>);checkseat('<?php echo e($facility->id); ?>');">
                                                                    <a class="showtime-pill" href="#!"  data-attributes="" title="<?php echo e($remark); ?>">
                                                                        <div class="__details">
                                                                            <div class="__text"><?php echo e(date("g:i A", strtotime($show->from_time))); ?>

                                                                            <?php if(!$show->dont_show_to_time): ?>
                                                                            -<?php echo e(date("g:i A", strtotime($show->to_time))); ?>

                                                                            <?php endif; ?>
                                                                            </div>
                                                                        </div>
                                                                    </a>
                                                                </div> 
                                                                
                                                            <?php endif; ?> 
                                                        <?php endif; ?>                                                           
                                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                <?php else: ?>
                                                       <i><span style="color:steelblue;"> No shows for this facility on this date </span></i>
                                                <?php endif; ?>
                                                </div>

                                           

                                            </td>
                                            
                                            <td class="py-2 text-right">
                                                <?php if($facilityon[$facility->id]): ?>
                                                <div class="dropdown text-sans-serif"><button class="btn btn-primary tp-btn-light sharp" type="button" id="order-dropdown-0" data-toggle="dropdown" data-boundary="viewport" aria-haspopup="true" aria-expanded="false"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="18px" height="18px" viewBox="0 0 24 24" version="1.1"><g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"><rect x="0" y="0" width="24" height="24"></rect><circle fill="#000000" cx="5" cy="12" r="2"></circle><circle fill="#000000" cx="12" cy="12" r="2"></circle><circle fill="#000000" cx="19" cy="12" r="2"></circle></g></svg></span></button>
                                                    <div class="dropdown-menu dropdown-menu-right border py-0" aria-labelledby="order-dropdown-0">
                                                        <div class="py-2"><a class="dropdown-item" href="#!" onclick="clearselection(<?php echo e($facility->id); ?>);">Clear</a>
                                                        </div>
                                                    </div>
                                                </div>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </table>
                                </div>
							</div>
                            <div class="card-footer">
                                <span class="float-right" style="color: green; font-weight: bold;">Amount Payable:&nbsp;<i class='fa fa-rupee'></i><span id="totalamount">0</span>/-</span>
                                <br><span class="float-right"><button class="btn btn-primary btn-sm" id="facilitySelectbtn" type="button">Continue</button></span>
                            </div>
						</div>
					</div>
                </div>
            </div>
        </div>
    
        <div class="row modal-dialog modal-dialog-centered" id="spinnerdiv" style="display: none;">
            <div class="col-xl-12" style="text-align: center;">
                <div class="spinner-border"></div>
                <h3>Please wait while we load</h3>
            </div>
        </div>

        <div class="row" id="seatSelectiondiv" style="display: none;">
            <div class="col-xl-12">
                <div class="row">
                    
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                Seat Selection
                            </div>
                            <?php
                                $fixedseatflag_facility =[];
                                $totalrows = 0;
                            ?>
                            <?php $__currentLoopData = $facilities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $facility): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <?php
                                $fixedseatflag_facility[$facility->id] = $facility->fixedseatflag;
                            ?>
                            <?php if($facility->fixedseatflag): ?>
                            <div class="card-body">
                                <?php echo e($facility->facility_name); ?><div class="float-right" style="font-size: 80%"><input type="hidden" name="fixedseatflag_facility<?php echo e($facility->id); ?>"  id="fixedseatflag_facility<?php echo e($facility->id); ?>" value="<?php echo e($fixedseatflag_facility[$facility->id]); ?>"><i>Selected Seats:&nbsp;<span id="currentSelected<?php echo e($facility->id); ?>" style="color: darkmagenta;">0&nbsp;</span>/&nbsp;<span id="total<?php echo e($facility->id); ?>"><?php echo e($totalCount); ?></span></i></div>

                                <!--Layout of teh facility-->
                                <div class="table-responsive oval">
                                    <table class="table table-sm table-responsive-lg mb-0" style="font-size:80%">
                                        <?php 
                                            $totalrows = $facility->layout->total_row; 
                                            $cols = $facility->layout->maxinarow;
                                            $totalcols = $cols+2;



                                            for($i=1; $i<=$totalrows; $i++)
                                            {
                                        ?>
                                            <?php if($i==5): ?>
                                                <tr style="background-color: lightgreen;"><td colspan="13"><i class='fa fa-angle-double-left'></i>&nbsp;&nbsp;EXIT</td><td colspan="14" align="right"><i class='fa fa-angle-double-left'></i>&nbsp;&nbsp;ENTRY</td></tr>
                                            <?php endif; ?>



                                            <tr>
                                               <?php
                                                    //get middle col
                                                    $totalcolinrow = $seatcount[$facility->id][$i];
                                                    $middlecol = ceil($totalcolinrow/2);
                                                    if($middlecol<13)
                                                    {
                                                        $diffcol = 13-$middlecol;
                                                        for($m=1;$m<=$diffcol;$m++)
                                                        {
                                                ?>
                                                            <td>&nbsp;</td>
                                                <?php
                                                        }
                                                    }
                                               ?>
                                               <td>
                                                    <input type="checkbox" name="selectAllSeats<?php echo e($i); ?>" id="selectAllSeats<?php echo e($i); ?>" onclick="loadfirsthalfseats(this,'<?php echo e($i); ?>','<?php echo e($facility->id); ?>','<?php echo e($middlecol); ?>');" value="1">
                                               </td>
                                               <?php if(isset($seats[$facility->id][$i])): ?>
                                                   <?php $colcount = 1; ?>
                                                   <?php $__currentLoopData = $seats[$facility->id][$i]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $seat): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <td class="seat"><a href="#!" id="seat<?php echo e($seat->id); ?>" class="_available" onclick="seatselect(this,<?php echo e($facility->id); ?>,<?php echo e($seat->id); ?>);"> <?php echo e($seat->seat_name); ?></a></td>
                                                    <?php if($colcount==$middlecol): ?>
                                                        <?php if($i==5): ?>
                                                        <td align="center"><img  src="<?php echo e(asset('images/planetaurium.png')); ?>" alt="image"width="25"></td>
                                                        <?php else: ?>
                                                        <td>&nbsp;</td>
                                                        <?php endif; ?>
                                                    <?php endif; ?>
                                                    <?php $colcount++; ?>
                                                    <script>
                                                        seatnamearray[<?php echo e($seat->id); ?>]="<?php echo e($seat->seat_name); ?>";
                                                    </script>
                                                   <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                               <?php endif; ?> 
                                               <td>
                                                    <input type="checkbox" name="selectAllSeats<?php echo e($i); ?>" id="selectAllSeats<?php echo e($i); ?>" onclick="loadsecondhalfseats(this,'<?php echo e($i); ?>','<?php echo e($facility->id); ?>','<?php echo e($middlecol); ?>');" value="1">
                                               </td>
                                            </tr>
                                        <?php
                                            }
                                        ?>
                                    </table>
                                </div>

                                

                            </div>
                            <input type="hidden" name="selectedseats<?php echo e($facility->id); ?>" id="selectedseats<?php echo e($facility->id); ?>" value="">
                            <div class="screencontainer"><div class="round-bottom">SCREEN</div></div>
                            <?php endif; ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            
                            <div class="card-footer">
                                <span class="float-right"><button class="btn btn-primary btn-sm" type="button" id="seatSelectionbtn" style="display:none;">Continue</button></span>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="row" id="paymentdiv" style="display:none;">
            <div class="col-xl-12">
                <div class="row">
                    
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-header">
                                Booking Summary

                            </div>
                            <div class="card-body">
                                <span class="small">Visitor Name: <b><?php echo e($visitor_name); ?></b></span><br>
                                <span class="small">Phone Number: <b><?php echo e($phone_number); ?></b></span><br>
                                <span class="small">Centre: <b><?php echo e($organisation->organisation_name); ?>,&nbsp;<?php echo e($organisation->city); ?></b></span>
                                <hr>
                                <?php $__currentLoopData = $facilities; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $facility): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <div id="paymentdivfacility<?php echo e($facility->id); ?>" style="display:none;">
                                        <small>
                                            <span class="float-left">
                                            <strong><?php echo e($facility->facility_name); ?></strong>
                                            <?php if($facility->fixedseatflag): ?>
                                                &nbsp;<i>[Selected Seats:&nbsp;<span id="paymentdivseats<?php echo e($facility->id); ?>"></span>]</i>
                                            <?php endif; ?>
                                            <br>
                                            <?php if($adultCount): ?>
                                            Adults: <b><span id="adultdiv<?php echo e($facility->id); ?>"><?php echo e($adultCount); ?></span></b> 
                                            <?php endif; ?>
                                            <?php if($childCount): ?>
                                            Child: <b><span id="childdiv<?php echo e($facility->id); ?>"><?php echo e($childCount); ?></span></b>
                                            <?php endif; ?>
                                            </span>
                                            <br>
                                            <span class="float-right" style="color:green;"><i class='fa fa-rupee'></i>&nbsp;<span id="paymentdivfamount<?php echo e($facility->id); ?>"></span>
                                            </span>
                                        </small>
                                        <hr>
                                    </div>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                <div class="form-check form-check-inline">
                                    <select class="form-control" id="ticket_type" name="ticket_type" onchange="loadmesg(this.value);" required>
                                        <option value="0">Normal</option>
                                        <option value="1">Differently Abled</option>
                                        <option value="2">Packaged User</option>
                                    </select>
                                    <span id="tickettypediv" style="color:red; font-size: small; font-weight: bold; display:none;">&nbsp;&nbsp;Supervisory Approval Required.</span>
                                    <span id="ticketuploaddiv" style="display:none;">&nbsp;&nbsp;
                                      <input type="file" name="documentfile" id="documentfile" class="form-control" onchange="check_extension(this);check_filesize(this);">
                                    </span>
                                </div>
                                <br><br>
                                <div class="form-check form-check-inline">
                                    <span class="float-left">Payment Method: 
                                        <!--<select id="paymentmethods" name="paymentmethods" class="form-control small" required onchange="loaddet(this.value)">
                                            <option value="">Choose...</option>
                                            <?php $__currentLoopData = $paymentmethods; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $paymentmethod): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <option value="<?php echo e($paymentmethod->id); ?>"><?php echo e($paymentmethod->method); ?></option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        </select>-->
                                        <ul class="payment-method-radio">
                                            <?php $__currentLoopData = $paymentmethods; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $paymentmethod): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <li>
                                                    <input type="radio" id="<?php echo e($paymentmethod->id); ?>" name="paymentmethods" value="<?php echo e($paymentmethod->id); ?>" required onchange="loaddet(this.value)" />
                                                    <label for="<?php echo e($paymentmethod->id); ?>"><?php echo e($paymentmethod->method); ?></label>
                                                </li>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                         
                                        </ul>
                                    </span>
                                    <span id="paymentmethoddiv" style="color:red; font-size: small; font-weight: bold; display:none;">&nbsp;&nbsp;Supervisory Approval Required.</span>
                                </div>
                                <span class="float-right">Amount Payable:&nbsp;<i class='fa fa-rupee'></i>&nbsp;<span id="paymentdivtotalamount"></span></span>
                                <input type="hidden" name="totalamountpayable" id="totalamountpayable">
                            </div>
                            <div class="card-footer">
                                <span class="float-right"><button class="btn btn-primary btn-sm" type="submit">Book Tickets</button></span>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>       
</form>

<script type="text/javascript">
var seatarrayjson = <?php echo json_encode($seats) ?>;
//console.log(seatarrayjson);
const seatarrayjs = [];

for(var i in seatarrayjson) {
    seatarrayjs.push([i,seatarrayjson[i]]);
}


//var seatarrayjs = seatarrayjstemp[0][1];

console.log(seatarrayjs[0][1][1]);
</script>
<script>
    function checkseat(facilityid)
    {
        var adultcount = document.getElementById("adultCount"+facilityid).value;
        var childcount = document.getElementById("childCount"+facilityid).value;
        var total_seat = (adultcount*1)+(childcount*1);
        var showdate = $('#showDate').val();
        var showid = $('#showSelected'+facilityid).val();
        if(showid)
        {
          if($('#available'+facilityid).length)
          {
            $('#spinnerdiv').show();
            $.ajax({
                  type: "GET",
                  url: "<?php echo e(url('fetchAvailableSeatsOffline')); ?>/"+facilityid+"/"+showid+"/"+showdate,
                  success: function( result ) {
                    
                    if(result<total_seat)
                    {
                        sweetAlert("Oops...", "Available Seats less than Selected.", "error");
                        clearselection(facilityid);
                    }
                    //alert(result);
                    $('#spinnerdiv').hide();
                    
                }
            });
          } 
        }
    }
    function loaddet(paymentmethod)
    {
        if(paymentmethod==4)
        {
            $('#paymentmethoddiv').show();  
        }
        else
        {
            $('#paymentmethoddiv').hide();     
        }
    }
    function loadmesg(tickettypeobj)
    {
        var tickettype = tickettypeobj;
        
        if(tickettype!=0)
        {
            $('#tickettypediv').show();  
            $('#ticketuploaddiv').show();  
        }
        else
        {
            $('#tickettypediv').hide();   
            $('#ticketuploaddiv').hide();    
        }
    }
    function loadfirsthalfseats(chkobj,rowno,facilityid,middlecol)
    {
        $('#spinnerdiv').show();
        var totalCount = $('#total_noof_adult_child'+facilityid).val();
        for(let i = ((Math.ceil((seatarrayjs[0][facilityid][rowno].length)/2))-1); i >=0; i--)
        {
            var seat_id = seatarrayjs[0][facilityid][rowno][i].id;
            //console.log(seat_id);
            var seatclassobj = document.getElementById('seat'+seat_id);
            if(chkobj.checked==true)
            {
                seatselect(seatclassobj, facilityid, seat_id);
            }
            if(chkobj.checked==false)
            {
                if(seatclassobj.className=='_selected')
                {
                    seatclassobj.className = '_available';
                    currentCount--;
                    var index = selectedseats.indexOf(seat_id);
                    if (index > -1) {
                       selectedseats.splice(index, 1);
                    }
                }
            }
        }
        if(chkobj.checked==false)
        {
            $('#selectedseats'+facilityid).val(selectedseats);
            $('#paymentdivseats'+facilityid).html('');
           for(s=0;s<selectedseats.length;s++)
           {
                var seatnewid = selectedseats[s];
                if($('#paymentdivseats'+facilityid).html())
                    $('#paymentdivseats'+facilityid).html($('#paymentdivseats'+facilityid).html()+','+seatnamearray[seatnewid]);
                else
                    $('#paymentdivseats'+facilityid).html(seatnamearray[seatnewid]);
           }
        }
       // alert(totalCount);
        if(currentCount==totalCount)
            $('#seatSelectionbtn').show();
        else
            $('#seatSelectionbtn').hide();
        $('#spinnerdiv').hide(); 
    }

    function loadsecondhalfseats(chkobj,rowno,facilityid,middlecol)
    {
        $('#spinnerdiv').show();
        var totalCount = $('#total_noof_adult_child'+facilityid).val();
        for(let i = (Math.ceil((seatarrayjs[0][facilityid][rowno].length)/2)); i <= ((seatarrayjs[0][facilityid][rowno].length)-1) ; i++)
        {
            var seat_id = seatarrayjs[0][facilityid][rowno][i].id;
            var seatclassobj = document.getElementById('seat'+seat_id);
            if(chkobj.checked==true)
            {
                seatselect(seatclassobj, facilityid, seat_id);
            }
            if(chkobj.checked==false)
            {
                if(seatclassobj.className=='_selected')
                {
                    seatclassobj.className = '_available';
                    currentCount--;
                    var index = selectedseats.indexOf(seat_id);
                    if (index > -1) {
                       selectedseats.splice(index, 1);
                    }
                }
            }

        }
        if(chkobj.checked==false)
        {
            $('#selectedseats'+facilityid).val(selectedseats);
            $('#paymentdivseats'+facilityid).html('');
           for(s=0;s<selectedseats.length;s++)
           {
                var seatnewid = selectedseats[s];
                if($('#paymentdivseats'+facilityid).html())
                    $('#paymentdivseats'+facilityid).html($('#paymentdivseats'+facilityid).html()+','+seatnamearray[seatnewid]);
                else
                    $('#paymentdivseats'+facilityid).html(seatnamearray[seatnewid]);
           }
        }
        if(currentCount==totalCount)
            $('#seatSelectionbtn').show();
        else
            $('#seatSelectionbtn').hide();
        $('#spinnerdiv').hide();
    }
    function showselect(obj, facilityid, showid)
    {
        $('#spinnerdiv').show();
        //alert("here");
        $("."+facilityid).css('background-color', '');

        if(obj.style.backgroundColor == 'lightgreen')
        {
            obj.style.backgroundColor = '';
            obj.style.color = '#4abd5d';
        }
        else
        {
            obj.style.backgroundColor = 'lightgreen';
            
        }

        if($('#showSelected'+facilityid).val()==showid)
        {
            clearselection(facilityid);
             $('#spinnerdiv').hide();
            return;
        }

        //select this facility
        //alert(facilitiesarray);
        //fetch available seats for this facility
        var showdate = $('#showDate').val();
        $.ajax({
              type: "GET",
              url: "<?php echo e(url('fetchAvailableSeatsOffline')); ?>/"+facilityid+"/"+showid+"/"+showdate,
              success: function( result ) {
                
                $('#available'+facilityid).html("Available: "+result);
                 
                //alert(result);
                $('#spinnerdiv').hide();
                
            }
        }); 

        $('#iffacilitySelected'+facilityid).val('1');
        $('#showSelected'+facilityid).val(showid);

        //show amount
        var adultrate = $('#rateadult'+facilityid).val();
        var childrate = $('#ratechild'+facilityid).val();

        if(!adultrate)
            adultrate = 0;
        if(!childrate)
            childrate = 0;

        //var adults = document.getElementById("adultCount"+facilityid).value();
        //var child = document.getElementById("childCount"+facilityid).value();
        var adults = $('#adultCount'+facilityid).val();
        var child = $('#childCount'+facilityid).val();
        //alert(adults);
        var amount = (adults*adultrate)+(child*childrate);
        //alert(amount);
        $('#amount'+facilityid).html("<i class='fa fa-rupee'></i> "+amount);
        $('#famount'+facilityid).val(amount);

        calculatetotal();

        //load details in payment div

        $('#paymentdivfacility'+facilityid).show();
        $('#paymentdivfamount'+facilityid).html(amount);
        
    }

    function load_amount(facilityid)
    {
        var showid = $('#showSelected'+facilityid).val();
        $('#spinnerdiv').show();
        //fetch available seats for this facility
        var showdate = $('#showDate').val();
        $.ajax({
              type: "GET",
              url: "<?php echo e(url('fetchAvailableSeatsOffline')); ?>/"+facilityid+"/"+showid+"/"+showdate,
              success: function( result ) {
                
                $('#available'+facilityid).html("Available: "+result);
                 
                //alert(result);
                $('#spinnerdiv').hide();
                
            }
        }); 

        $('#iffacilitySelected'+facilityid).val('1');
        $('#showSelected'+facilityid).val(showid);

        //show amount
        var adultrate = $('#rateadult'+facilityid).val();
        var childrate = $('#ratechild'+facilityid).val();

        if(!adultrate)
            adultrate = 0;
        if(!childrate)
            childrate = 0;

        var adults = $('#adultCount'+facilityid).val();
        var child = $('#childCount'+facilityid).val();
        var total_noof_adult_child = (adults*1)+(child*1);
        //alert(adults);
        var amount = (adults*adultrate)+(child*childrate);
        //alert(amount);
        $('#amount'+facilityid).html("<i class='fa fa-rupee'></i> "+amount);
        $('#famount'+facilityid).val(amount);

        calculatetotal();
        //document.getElementById("totalCount").value = total_noof_adult_child;
        $('#total_noof_adult_child'+facilityid).val(total_noof_adult_child);
        //load details in payment div

        $('#paymentdivfacility'+facilityid).show();
        $('#paymentdivfamount'+facilityid).html(amount);
        
    }

    function calculatetotal()
    {
        var amt = 0;
        for(let i = 0; i < facilitiesarray.length; i++){
            
            var f = facilitiesarray[i];

            //alert(f);
            var facility_amt = $('#famount'+f).val();

            //alert(facility_amt);

            amt = amt*1 + facility_amt*1;

           

        }
        //alert(amt);
        $('#totalamount').html(amt);
        $('#paymentdivtotalamount').html(amt);
        $('#totalamountpayable').val(amt);

    }

    function clearselection(facilityid)
    {
        $("."+facilityid).css('background-color', '');
        $('#iffacilitySelected'+facilityid).val('');
        $('#showSelected'+facilityid).val('');
        $('#available'+facilityid).html('');
        $('#amount'+facilityid).html('');
        $('#famount'+facilityid).val(0);
        $('#total_noof_adult_child'+facilityid).val(0);
        $('#paymentdivfacility'+facilityid).hide();
        $('#paymentdivfamount'+facilityid).html(0);

        calculatetotal();
    }
    var selectedseats=[];

    function seatselect(obj,facilityid,seatid)
    {
        //checking on how many to be selected
        //var totalCount = $('#totalCount').val();
        var totalCount = $('#total_noof_adult_child'+facilityid).val();
        //alert(obj.className);
        if(obj.className=='_selected')
        {
            obj.className = '_available';
            currentCount--;

            //remove this seat from selected list
            for( var ar = 0; ar < selectedseats.length; ar++){ 
                if ( selectedseats[ar] === seatid) { 
            
                    selectedseats.splice(ar, 1); 
                }
            }
        }
        else if(obj.className=='_available')
        {
            if(currentCount<totalCount)
            {
                obj.className = '_selected';
                currentCount++;

                //enter this seat to selected list
                selectedseats.push(seatid);
            }
            
        }
        //alert(currentCount);
        $('#currentSelected'+facilityid).html(currentCount);

        //console.log(selectedseats);
        $('#selectedseats'+facilityid).val(selectedseats);

       $('#paymentdivseats'+facilityid).html('');
       for(s=0;s<selectedseats.length;s++)
       {
        var seatnewid = selectedseats[s];
        if($('#paymentdivseats'+facilityid).html())
            $('#paymentdivseats'+facilityid).html($('#paymentdivseats'+facilityid).html()+','+seatnamearray[seatnewid]);
        else
            $('#paymentdivseats'+facilityid).html(seatnamearray[seatnewid]);
       }
        if(currentCount==totalCount)
            $('#seatSelectionbtn').show();
        else
            $('#seatSelectionbtn').hide();
    }

    var currentCount = 0;

    $('#facilitySelectbtn').click(function(){
        $('#spinnerdiv').show();
        $('#facilitySelectdiv').hide();
        var selectflag = 0; 
        var layoutflag = 0;
        var layoutfacility='';
        //get all facilities selected
        for(let i = 0; i < facilitiesarray.length; i++){
            
            var f = facilitiesarray[i];
            var adults = $('#adultCount'+f).val();
            var child = $('#childCount'+f).val();
            $('#adultdiv'+f).html(adults); 
            $('#childdiv'+f).html(child); 
            //check if this facility is selected
            var ifselected = $('#iffacilitySelected'+f).val();
            if(ifselected)
            {
                console.log(f);
                selectflag = 1;
                //check if layout is there for the facility
                var iffacilityfixed = $('#iffacilityfixed'+f).val();
                if(iffacilityfixed==1)
                {
                    var total = (adults*1)+(child*1);
                    $('#total'+f).html(total);
                    layoutflag = 1;
                    layoutfacility = f;
                }
            }
        }
        //if no facilities selected return false
        if(selectflag==0)
        {
            $('#spinnerdiv').hide();
            $('#facilitySelectdiv').show();
            return false;
        }
        //check if layout needs to be loaded
        if(layoutflag==1)
        {
            //get selected showid and showdate
            var showid = $('#showSelected'+layoutfacility).val();
            var showdate = $('#showDate').val();
            //get blocked seats using ajax
            $.ajax({
                  type: "GET",
                  url: "<?php echo e(url('/fetchBookedSeatsOffline')); ?>/"+layoutfacility+"/"+showid+"/"+showdate,
                  success: function( result ) {
                    for (let i = 0; i < result.length; i++) {
                      //console.log(result[i]);
                      //block this seat
                      $('#seat'+result[i]).removeClass('_available');
                      $('#seat'+result[i]).addClass('_blocked');
                      $('#seat'+result[i]).prop("onclick", null).off("click");
                    }
                    $('#spinnerdiv').hide(); 
                }
            }); 
            $('#seatSelectiondiv').show();
            $('#spinnerdiv').hide();
        }
        else //if no layout proceed to payment page
        {
            $('#paymentdiv').show();
            $('#spinnerdiv').hide();
        }
        $(window).scrollTop(0);
    });

    $('#seatSelectionbtn').click(function(){
        //get all facilities selected
        for(let i = 0; i < facilitiesarray.length; i++)
        {    
            var f = facilitiesarray[i];
            var adults = $('#adultCount'+f).val();
            var child = $('#childCount'+f).val();
            //check if this facility is selected
            $('#adultdiv'+f).html(adults); 
            $('#childdiv'+f).html(child);   

            ////////
            var row = <?php echo e($totalrows); ?>

            $('#paymentdivseats'+f).html('');
            var fixedseatflag = $('#fixedseatflag_facility'+f).val();
            console.log(fixedseatflag);
            if(fixedseatflag==1)
            {
                for(rowcount=1;rowcount<=row;rowcount++)
                {
                    var colmcount=0;
                    var firstseat='';
                    var prevrowname='';
                    var printseatstring='';
                    var seatname = "";
                    for(let s = 0; s < (seatarrayjs[0][f][rowcount].length); s++)
                    {
                        colmcount++;
                        var seat_id = seatarrayjs[0][f][rowcount][s].id;
                        ///check whether the selected seat is there in the seatarrayjs in each rows.///////////
                        if(selectedseats.indexOf(seat_id) !== -1)  
                        {  
                            var seatname = seatnamearray[seat_id];
                            if(!firstseat)
                            {
                                firstseat = seatname;
                                printseatstring = firstseat;
                            }

                            prevrowname = seatname;
                            if((colmcount==(seatarrayjs[0][f][rowcount].length)) && firstseat!=seatname)
                            {
                                printseatstring = printseatstring+'-'+seatname;
                            }
                        }  
                        else  
                        {  
                            if(prevrowname)
                                printseatstring = printseatstring+'-'+prevrowname;
                            prevrowname = '';
                            firstseat ='';

                        
                            if(printseatstring)
                            {
                                if($('#paymentdivseats'+f).html())
                                    $('#paymentdivseats'+f).html($('#paymentdivseats'+f).html()+','+printseatstring);
                                else
                                    $('#paymentdivseats'+f).html(printseatstring);
                            }

                            printseatstring = '';
                            //console.log("inside else.."+printseatstring);
                        }  
                        
                    }
                    if(printseatstring)
                    {
                        if($('#paymentdivseats'+f).html())
                            $('#paymentdivseats'+f).html($('#paymentdivseats'+f).html()+','+printseatstring);
                        else
                            $('#paymentdivseats'+f).html(printseatstring);
                    }
                }  
            }            
        }
        $('#spinnerdiv').show();
        $('#seatSelectiondiv').hide();
        $('#paymentdiv').show();
        $('#spinnerdiv').hide();
        $(window).scrollTop(0);
    });
</script>

<?php $__env->stopSection(); ?>			
<?php echo $__env->make('layout.default', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/html/ksstmprod/resources/views/Sales/special_show_book_tickets.blade.php ENDPATH**/ ?>