{{-- Extends layout --}}
@extends('layout.default')
@section('content')
    <div class="container-fluid">
        <div class="page-titles">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="javascript:void(0)">Facility</a></li>
                <li class="breadcrumb-item active"><a href="javascript:void(0)">Facility</a></li>
            </ol>
        </div>
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-primary">
                        <div class="card-header custom-tab-1">
                            @php
                                $activeclass_other ="";
                                $activeclass = "";
                                $showclass ="";
                                $showclass_other = "";
                            @endphp
                            @if($slugrolename=="counteruser")
                                @php
                                    $activeclass = "active";
                                    $showclass = "show active";
                                @endphp
                            @else
                                @php
                                    $activeclass_other = "active";
                                    $showclass_other = "show active";
                                @endphp
                            @endif
                            <ul class="nav nav-tabs" role="tablist">
                                @if($slugrolename!="counteruser")
                                <li class="nav-item">
                                    <a class="nav-link {{$activeclass_other}}" data-toggle="tab" href="#organisation_form"><b>Add Facility</b></a>
                                </li>
                                @endif
                                <li class="nav-item">
                                    <a class="nav-link {{$activeclass}}" data-toggle="tab" href="#listorgdata"><b>View Facility</b></a>
                                </li>
                            </ul>
                        </div>
                        <div class="card-body">
                            <div class="default-tab">
                                
                                <div class="tab-content">
                                    @if($slugrolename!="counteruser")
                                    <div class="tab-pane fade{{$showclass_other}}" id="organisation_form" role="tabpanel">
                                        <form id="organisation_form" class="form-horizontal" action="{{URL::to('/facility_post')}}" method="post" onsubmit="return validation();" autocomplete="off" enctype="multipart/form-data">
                                            {{ csrf_field() }}
                                            <div class="form-group col-6">
                                                <label>Organisation</label>
                                                <select id="organisation_id" name="organisation_id" class="form-control" required>
                                                    <option value="">Choose Organisation</option>
                                                    @foreach($organisations as $organisation)
                                                        <option value="{{$organisation->id}}">{{$organisation->organisation_name}}&nbsp;&nbsp;{{$organisation->city}}</option>
                                                    @endforeach    
                                                </select>
                                            </div>
                                            <div class="form-row">
                                                <div class="form-group col-6">
                                                    <label>Facility Name</label>
                                                    <input type="text" class="form-control" id="facility_name" name="facility_name" placeholder="Enter Facility Name" required maxlength="250">
                                                </div>
                                                <div class="form-group col-3">
                                                    <label>Facility Short Code</label>
                                                    <input type="text" class="form-control" id="short_code" name="short_code" placeholder="Enter Facility Short Code" required maxlength="250">
                                                </div>
                                                <div class="form-group col-3">
                                                    <label>Order By</label>
                                                    <input type="text" name="order_by" id="order_by" class="form-control" maxlength="3" onkeypress="return isNumber(event);" placeholder="Enter Facility Order By">
                                                </div>
                                            </div>
                                            <div class="form-row">
                                                <div class="form-group col-6">
                                                    <label>Number of Seats</label>
                                                    <input type="text" class="form-control" id="noofseats" name="noofseats" placeholder="Enter Number of Seats" maxlength="3" onkeypress="return isNumber(event);">
                                                </div>
                                                <div class="form-group col-6">
                                                    <label>Maximum Ticket per Person</label>
                                                    <input type="text" class="form-control" id="maxticketperperson" name="maxticketperperson" placeholder="Enter Maximum Ticket per Person" maxlength="3" onkeypress="return isNumber(event);">
                                                </div>
                                            </div>
                                            <div class="form-row">
                                                <div class="form-group col-6">
                                                    <label>Fixed Show Time ?</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    <input type="checkbox" checked="checked" name="timedshowflag" id="timedshowflag" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" data-size="small" data-style="ios" value="1">
                                                </div>
                                                <div class="form-group col-6">
                                                    <label>Fixed Seat ?</label>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                                    <input type="checkbox" checked="checked" name="fixedseatflag" id="fixedseatflag" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" data-size="small" data-style="ios" value="1">
                                                </div>
                                            </div>
                                            
                                            <div class="card-footer">
                                                <button type="submit" class="btn btn-primary">Submit</button>
                                            </div>
                                        </form>
                                    </div>
                                    @endif
                                    <div class="tab-pane fade {{$showclass}}" id="listorgdata">
                                        <div class="table-responsive">
                                            
                                            <table class="display" style="width:100%" id="example" style="font-size: 70% !important;">
                                                <thead class="thead-info">
                                                    <tr>
                                                        <th>#</th>
                                                        <th>Organisation Name</th>
                                                        <th>Facility Name</th>
                                                        <!--<th width="7%">Fixed Show Time</th>-->
                                                        <th>Seats</th>
                                                        <!--<th>Fixed Seats</th>
                                                        <th width="7%">Max Ticket/Person</th>-->
                                                        <th>Status</th>
                                                        <th>Actions</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    @if(count($faclities)==0)
                                                        <tr>
                                                            <td colspan="3"><br><br>
                                                                <div class="alert alert-danger alert-dismissible fade show">
                                                                    <strong>No Facilities Added !!!</strong>
                                                                </div>
                                                                
                                                            </td>
                                                        </tr>
                                                    @endif
                                                    @php
                                                        $n = 0;
                                                        $organisation_name= "";
                                                        $fixedseatflag_status ="";
                                                        $timedshowflag_status = "";
                                                        $maxticketperperson ="";
                                                        $status_name ="";
                                                    @endphp
                                                    @if(isset($faclities))
                                                        @foreach($faclities as $facility)
                                                            @php  
                                                                $n++;
                                                                if($facility->organisation_id)
                                                                {
                                                                    $organisation_name = $facility->organisation->organisation_name;
                                                                    $city = $facility->organisation->city;
                                                                }
                                                                $timedshowflag = $facility->timedshowflag;
                                                                if($timedshowflag==1)
                                                                {
                                                                    $timedshowflag_status = "Yes";
                                                                }
                                                                else
                                                                {
                                                                    $timedshowflag_status = "No";
                                                                }
                                                                $fixedseatflag = $facility->fixedseatflag;
                                                                if($fixedseatflag==1)
                                                                {
                                                                    $fixedseatflag_status = "Yes";
                                                                }
                                                                else
                                                                {
                                                                    $fixedseatflag_status = "No";
                                                                }
                                                                if($facility->maxticketperperson)
                                                                {
                                                                    $maxticketperperson = $facility->maxticketperperson;
                                                                }
                                                                $status = $facility->active_flag;
                                                                if($status==1)
                                                                {
                                                                    $status_name = "Active";
                                                                }
                                                                else
                                                                {
                                                                    $status_name = "Not Active";
                                                                }
                                                            @endphp
                                                            <tr>
                                                                <td>{{$n}}</td>
                                                                <td>{{$organisation_name}}&nbsp;{{$city}}</td>
                                                                <td>{{$facility->facility_name}} ({{$facility->short_code}})</td>
                                                                <!--<td>{{$timedshowflag_status}}</td>-->
                                                                <td>{{$facility->noofseats}}</td>
                                                                <!--<td>{{$fixedseatflag_status}}</td>
                                                                <td>{{$maxticketperperson}}</td>-->
                                                                <td>{{$status_name}}</td>
                                                                <td>
                                                                    <div class="form-group">
                                                                        @if($slugrolename!="counteruser")
                                                                        <div class="form-check form-check-inline" style="margin-right:0px !important;">
                                                                            <a href="{{URL::to('/show_facility')}}/{{$facility->id}}" title="Update Facility" 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>
                                                                        @endif
                                                                        <div class="form-check form-check-inline" style="margin-right:0px !important;">
                                                                           <a href="{{URL::to('/showtimings_create')}}/{{$facility->id}}" title="Show Timings" class="btn btn-warning shadow btn-xs" style="padding: 0.438rem 0.5rem !important;">Shows</a>
                                                                        </div>
                                                                        @if($slugrolename!="counteruser")
                                                                        <div class="form-check form-check-inline" style="margin-right:0px !important;">
                                                                           <a href="{{URL::to('/layout_create')}}/{{$facility->id}}" title="Layout" class="btn btn-secondary shadow btn-xs" style="padding: 0.438rem 0.5rem !important;">Layout</a>
                                                                        </div>
                                                                        @endif
                                                                    </div>

                                                                    
                                                                    
                                                                    
                                                                </td>
                                                            </tr>
                                                        @endforeach
                                                    @endif
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script type="application/javascript">
        /////////validate integer fields///////////////////////////
        function isNumber(evt) 
        {
          evt = (evt) ? evt : window.event;
          var charCode = (evt.which) ? evt.which : evt.keyCode;
          if (charCode > 31 && (charCode < 48 || charCode > 57)) 
          {
            //alert("Please enter only Numbers.");
            return false;
          }

          return true;
        }
        /////////////////////////////////////////////////////////////////////
        $(document).ready(function() {
            toastr.options.timeOut = 10000;
            @if (Session::has('error'))
                toastr.error('{{ Session::get('error') }}');
            @elseif(Session::has('success'))
                toastr.success('{{ Session::get('success') }}');
            @endif
        });
    </script>
@stop
