@extends('Admin.master_page')

@section('title') <h5 class="m-0 font-weight-bold text-primary" style="float: left;">Scheduled Mantena Update</h5> 

<a href="{{ route('ScheduledMain.index') }}" style="float: right;"><i class="fas fa-chevron-circle-left"></i></a>
@endsection

@section('content')

<div class="intro-y box"> 
        
        <form action="{{ route('ScheduledMain.update' , $main->id) }}" method="POST">
            @csrf

            <input type="hidden" name="_method" value="put" />
          <label for="Name" >Name:</label>
        <div class="input-group" style="margin-top: 10px;">
           <input type="text" name="name" value="{{ $main->name }}" class="form-control" placeholder="Enter Name">
            @error('name')
            <span class="alert-danger">{{ $message }}</span>
            @enderror
        </div>

        <br>      

        <label for="Name" >Start Date:</label>
        <div class="input-group" style="margin-top: 10px;">
           <input type="datetime-local" value="{{ Carbon\Carbon::parse($main->start_date)->format('Y-m-d\TH:i') }}" name="start_date" class="form-control" placeholder="Start Date">
            @error('start_date')
            <span class="alert-danger">{{ $message }}</span>
            @enderror
        </div>

        <br>
        
        <label for="Name" >To Date:</label>
        <div class="input-group" style="margin-top: 10px;">
           <input type="datetime-local" name="to_date" value="{{ Carbon\Carbon::parse($main->to_date)->format('Y-m-d\TH:i') }}" class="form-control" placeholder="To Date">
            @error('to_date')
            <span class="alert-danger">{{ $message }}</span>
            @enderror
        </div>

        <br>
        
        <label for="Name" >Server Name:</label>
        <div class="input-group" style="margin-top: 10px;">
           <input type="text" name="server_name" value="{{ $main->server_name }}" class="form-control" placeholder="Enter Server Name">
            @error('server_name')
            <span class="alert-danger">{{ $message }}</span>
            @enderror
        </div>

        <br>  



        <label for="Name" >Components:</label>
        <div  style="margin-top: 15px;">

         @foreach($status as $st)
         <input type="checkbox" name="components[]" @foreach($main->components as $com) @if($com == $st->id) checked @endif  @endforeach value="{{ $st->id }}" id="components-{{ $st->id }}"> &nbsp;&nbsp; <label for="components-{{ $st->id }}">{{ $st->name }}</label>

         <select class="form-control" id="status-{{ $st->id }}" name="status[]" style="display:none;">
            <option value="">Please Select one</option>
               <option value="{{ $st->id }}-1" @if($st->status == 1) selected @endif>Operational</option>
               <option value="{{ $st->id }}-2" @if($st->status == 2) selected @endif>Under maintenance</option>
               <option value="{{ $st->id }}-3" @if($st->status == 3) selected @endif>Degraded performance</option>
               <option value="{{ $st->id }}-4" @if($st->status == 4) selected @endif>Partial outage</option>
               <option value="{{ $st->id }}-5" @if($st->status == 5) selected @endif>Major outage</option>option>
         </select>

         <br>
         @endforeach
         @error('components')
         <span class="alert-danger">{{ $message }}</span>
         @enderror
      </div>
        <br>

         <label for="Name" >Message:</label>
        <div class="input-group" style="margin-top: 10px;">
           <textarea name="message" id="editor" class="form-control" placeholder="Message....">{{ $main->CurrentMessage->message }}</textarea>
            @error('message')
            <span class="alert-danger">{{ $message }}</span>
            @enderror
        </div>

        <br>
        
         <label for="Name" >Status:</label>
        <div class="input-group" style="margin-top: 10px;">
           <select class="form-control" name="status_show">
               <option value="" hidden>Select Any</option>
               <option value="0" @if($main->status == 0) selected @endif>Public</option>
               <option value="1" @if($main->status == 1) selected @endif>Private</option>
           </select>
            @error('status')
            <span class="alert-danger">{{ $message }}</span>
            @enderror
        </div>

        <br>
        
        <label for="Name" >Schedule Status:</label>
        <div class="input-group" style="margin-top: 10px;">
           <select class="form-control" name="schedule_status">
               <option value="" hidden>Select Any</option>
               <option value="Started"  @if($main->schedule_status == "Started") selected @endif>Started</option>
               <option value="Completed"  @if($main->schedule_status == "Completed") selected @endif>Completed</option>
               <option value="Not Started" @if($main->schedule_status == "Pending") selected @endif>Pending</option>
           </select>
            @error('schedule_status')
            <span class="alert-danger">{{ $message }}</span>
            @enderror
        </div>

        <br>

        <button type="submit" class="btn btn-primary">Update</button>
        </form>
    </div>



@endsection

@section('script')

<script>
    
 $(document).ready(function(){

   @foreach($status as $s)

      if($('#components-{{ $s->id }}').is(':checked')){
      $('#status-{{ $s->id }}').show();
      $('#status-{{ $s->id }}').attr('disabled',false);
      }else{
      $('#status-{{ $s->id }}').hide();
      $('#status-{{ $s->id }}').attr('disabled',true);
      }
      


   $('#components-{{ $s->id }}').click(function(){
      var id = $(this).val();
      if($(this).is(':checked')){ 
      $('#status-'+id).show();
       $('#status-'+id).attr('disabled',false);
      }else{
      
      $('#status-'+id).hide();
       $('#status-'+id).attr('disabled',true);
      }
      
   })

   @endforeach



 });   
    
</script>

@endsection
