<?php $__env->startSection('content'); ?>
<style>
    .bd-example-modal-lg{
    display: table;
    position: relative;
    margin: 0 auto;
    top: calc(50% - 24px);
  }
  
  .bd-example-modal-lg{
    background-color: transparent;
    border: none;
  }
</style>
    <div class="container-fluid">
        <div class="page-titles">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="<?php echo e(URL::to('/facility')); ?>">Facility</a></li>
                <li class="breadcrumb-item active"><a href="javascript:void(0)">Show Timings</a></li>
            </ol>
        </div>
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-primary">
                        <div class="card-body">
                            <!-- -->
                            <form id="organisation_form" name="organisation_form" class="form-horizontal" action="<?php echo e(URL::to('/showtimings_create_post')); ?>" method="post" onsubmit="return validation();" autocomplete="off" enctype="multipart/form-data">
                                <?php echo e(csrf_field()); ?>

                                <div class="card bg-light">
                                    <div class="card-header">
                                        <h5 class="card-title"><?php echo e($facilities->facility_name); ?></h5>
                                    </div>
                                    <div class="card-body mb-0">
                                        <p class="card-text">
                                            <b>Organisation Name :</b> <?php echo e($facilities->organisation->organisation_name); ?>&nbsp;&nbsp;<?php echo e($facilities->organisation->city); ?><br>
                                            <b>Number of Seats :</b> <?php echo e($facilities->noofseats); ?>

                                        </p>
                                    </div>
                                </div>
                                <div class="form-row">
                                    <div class="form-group  col-md-4">
                                        <label>Date</label>
                                        <input type="date" class="form-control" id="show_date" name="show_date" min="<?php echo e(date('Y-m-d')); ?>" value="<?php echo e(date('Y-m-d')); ?>">
                                        <input type="hidden" name="facility_id" id="facility_id" value="<?php echo e($facilities->id); ?>">
                                    </div>
                                    <div class="form-group col-4"><br>
                                        <label>Special Show ?</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <input type="checkbox" name="show_flag" id="show_flag" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" data-size="small" data-style="ios" value="1" checked>
                                    </div>
                                </div>
                                <div class="form-row">
                                    <div class="form-group col-md-4">
                                        <label>Show Start Time</label>
                                        <div class="input-group clockpicker" data-placement="bottom" data-align="top" data-autoclose="true">
                                            <input type="time" class="form-control" name="show_start_time" id="show_start_time" required>  
                                        </div>
                                    </div>
                                    <div class="form-group col-md-4">
                                        <label>Show End Time</label>
                                        <div class="input-group clockpicker" data-placement="bottom" data-align="top" data-autoclose="true">
                                            <input type="time" class="form-control" name="show_end_time" id="show_end_time" required> 
                                        </div>
                                    </div>
                                </div>
                                <div class="form-row">
                                    <div class="form-group col-md-4">
                                        <label>Remark</label>
                                        <input type="text" class="form-control" name="remark" id="remark">  
                                    </div>
                                </div>
                                <div class="card-footer">
                                    <button type="button" class="btn btn-primary" id="savebutton">Submit</button>
                                    <a href="<?php echo e(URL::to('/facility')); ?>" title="View Facility" class="btn btn-warning">Back</a>

                                </div>

                            </form>
                        </div> 
                        <div class="card-body  bg-light">      
                            <div class="table-responsive">
                                <?php if(count($showtimings)!=0): ?>
                                <table class="display" style="width:100%" id="example">
                                    <thead class="thead-info">
                                        <tr>
                                            <th>Slno</th>
                                            <th>Date</th>
                                            <th>Show Start Time</th>
                                            <th>Show End Time</th>
                                            <th>Special/Normal Show</th>
                                            <th>Status</th>
                                            <th></th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php if(count($showtimings)==0): ?>
                                            <tr>
                                                <td colspan="3"><br><br>
                                                    <div class="alert alert-danger alert-dismissible fade show">
                                                        <strong>No Show TImings Added !!!</strong>
                                                    </div>
                                                    
                                                </td>
                                            </tr>
                                        <?php endif; ?>
                                        <?php
                                            $n = 0;
                                            $status_name ="";
                                            $show_status ="";
                                        ?>
                                        <?php if(isset($showtimings)): ?>
                                            <?php $__currentLoopData = $showtimings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $showtiming): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                <?php  
                                                    $n++;
                                                    $status = $showtiming->active_flag;
                                                    if($status==1)
                                                    {
                                                        $status_name = "Active";
                                                    }
                                                    else
                                                    {
                                                        $status_name = "Not Active";
                                                    }
                                                    $show_flag = $showtiming->show_flag;
                                                    if($show_flag==1)
                                                    {
                                                        $show_status = "Special Show";
                                                    }
                                                    else
                                                    {
                                                        $show_status = "Normal Show";
                                                    }
                                                ?>
                                                <tr>
                                                    <td><?php echo e($n); ?></td>
                                                    <td>
                                                        <?php if(isset($showtiming->date)): ?>
                                                            <?php echo e($showtiming->date); ?>

                                                        <?php endif; ?>
                                                    </td>
                                                    <td><?php echo e($showtiming->from_time); ?></td>
                                                    <td><?php echo e($showtiming->to_time); ?></td>
                                                    <td><?php echo e($show_status); ?></td>
                                                    <td><?php echo e($status_name); ?></td>
                                                    <td>
                                                        <div class="form-group">
                                                            <div class="form-check form-check-inline" style="margin-right:0px !important;">
                                                                <a href="<?php echo e(URL::to('/showtimings_update')); ?>/<?php echo e($showtiming->id); ?>" title="Update Show Time" class="btn btn-primary shadow btn-xs sharp mr-1" style="padding: 0.438rem 0.5rem !important;"><i class="fa fa-pencil"></i></a>
                                                            </div>
                                                        </div>
                                                    </td>
                                                </tr>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                        <?php endif; ?>
                                    </tbody>
                                </table>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div id="loaderModal" class="modal fade" role="dialog" aria-modal="true">
        <div class="modal-dialog">
            <div class="modal-content" style="width: 48px">
                <span class="fa fa-spinner fa-spin fa-3x"></span>
            </div>
        </div>
    </div>

    <div id="MessageModal" class="modal fade" role="dialog" aria-modal="true">
        <div class="modal-dialog modal-lg">
            <!-- Modal content-->
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">OVERLAPPING SHOWTIMINGS</h5>
                </div>
                <div class="modal-body">
                    <div class="col-sm-12" id="showmessage">  
                         
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger light" data-bs-dismiss="modal" onclick="closemodal();">Close</button>
                </div>
            </div>
        </div>
    </div>
    <script type="application/javascript">
    $(document).ready(function() {
        $('#savebutton').click(function(){ 

            $('#loaderModal').modal('show');
            var show_date=$('#show_date').val();
            var facility_id=$('#facility_id').val();
            var show_flag=$('#show_flag').val();
            var show_start_time = $('#show_start_time').val();
            var show_end_time = $('#show_end_time').val();
            //alert(facility_id);
            var csrf = "<?php echo e(csrf_token()); ?>";
            $.ajax({
                type: "GET",
                url: "<?php echo e(url('/showtimingscheck')); ?>"+"/"+facility_id+"/"+show_date+"/"+show_start_time+"/"+show_end_time,
                
                success: function( msg ) 
                {
                    console.log(msg);
                    var msgflag = 0;
                    if(msg)
                    {
                        var data = JSON.parse(msg);
                        
                        $('#showmessage').html('<div class="col-sm-12" style="border:1px solid grey; background:#FDEBD0; min-height:30px; display:table;">There are overlapping shows for the same facility, Please check the timings!</div>');
                        for (let i in data) {
                            msgflag = 1;
                          $('#showmessage').append('<div class="col-sm-12" style="border:1px solid grey; background:#fff; min-height:30px; display:table;">'+data[i].facility_name+' with show time '+data[i].from_time+' - '+data[i].to_time+'</div>');
                        }

                        if(msgflag ==0)
                        {
                            $('#loaderModal').modal('hide');
                            $('#MessageModal').modal('hide');
                            document.organisation_form.submit();
                        }
                        else
                        {
                             $('#loaderModal').modal('hide');
                            $('#MessageModal').modal('show');
                           
                        }

                       
                    }   
                    else
                    {
                        $('#loaderModal').modal('hide');
                        $('#MessageModal').modal('hide');
                        document.organisation_form.submit();
                    }
                }
            });
        });
    });

    function saveform()
    {
        document.organisation_form.submit();
    }

    function closemodal()
    {
        $('#MessageModal').modal('hide');
        $('#loaderModal').modal('hide');
    }

        $(document).ready(function() {
            toastr.options.timeOut = 10000;
            <?php if(Session::has('error')): ?>
                toastr.error('<?php echo e(Session::get('error')); ?>');
            <?php elseif(Session::has('success')): ?>
                toastr.success('<?php echo e(Session::get('success')); ?>');
            <?php endif; ?>
        });
    </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/Facility/showtimings_create.blade.php ENDPATH**/ ?>