@extends('Admin.master_page')

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

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

@section('content')

<div class="intro-y box"> 
        
        <form action="{{ route('Incident.update' , $in->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="{{ $in->name }}" class="form-control" placeholder="Enter Name">
            @error('name')
            <span class="alert-danger">{{ $message }}</span>
            @enderror
        </div>

        <br> 

        <label for="Name" >Impact:</label>
        <div class="input-group" style="margin-top: 10px;">
           <select name="impact" class="form-control">
              <option value="">Select Imact</option>
              <option value="None" @if($in->impact == 'None') selected @endif>None</option>
              <option value="Minor" @if($in->impact == 'Minor') selected @endif>Minor</option>
              <option value="Mayor" @if($in->impact == 'Mayor') selected @endif>Mayor</option>
              <option value="Critical" @if($in->impact == 'Critical') selected @endif>Critical</option>
           </select>
            @error('impact')
            <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="{{ $in->server_name }}" class="form-control" placeholder="Enter 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($in->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" >Status:</label>
        <div class="input-group" style="margin-top: 10px;">
           <select name="m_status" class="form-control">
              <option value="">Select Status</option>
              <option value="Investigating" @if(optional($in->CurrentIncidentMessage)->status == 'Investigating') selected @endif>Investigating</option>
              <option value="Identified" @if(optional($in->CurrentIncidentMessage)->status == 'Identified') selected @endif>Identified</option>
              <option value="Monitoring" @if(optional($in->CurrentIncidentMessage)->status == 'Monitoring') selected @endif>Monitoring</option>
              <option value="Resolved" @if(optional($in->CurrentIncidentMessage)->status == 'Resolved') selected @endif>Resolved</option>
           </select>
            @error('m_status')
            <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....">{{ optional($in->CurrentIncidentMessage)->message }}</textarea>
            @error('message')
            <span class="alert-danger">{{ $message }}</span>
            @enderror
        </div>

        <br>
        
        <label for="Name" >Show Status:</label>
        <div class="input-group" style="margin-top: 10px;">
           <select class="form-control" name="show_status">
               <option value="" hidden>Select Any</option>
               <option value="0" @if($in->show_status == 0) selected @endif>Public</option>
               <option value="1" @if($in->show_status == 1) selected @endif>Private</option>
           </select>
            @error('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
