@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">Virtuals</div>

                <div class="card-body">
                    <form action="/search" method="GET" role="search">
                        {{ csrf_field() }}
                        <div class="input-group">
                            <input type="text" class="form-control" name="q"
                                placeholder="Search virtual"><span class="input-group-btn">
                            </span>
                            <button type="submit" class="btn btn-default">
                                <span class="glyphicon glyphicon-search">Search</span>
                            </button>
                        </div>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="state[]" value=0> Requested
                        </label>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="state[]" value=1> Waiting
                        </label>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="state[]" value=2> Deployed
                        </label>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="state[]" value=3> Request delete
                        </label>
                        <label class="checkbox-inline">
                            <input type="checkbox" name="state[]" value=4> Delete
                        </label>
                    </form>
                    <table class="table">
                        <thead>
                          <tr>
                            <th scope="col">Creator</th>
                            <th scope="col">System</th>
                            <th scope="col">State</th>
                            <th scope="col">Actions</th>
                          </tr>
                        </thead>
                        <tbody>
                        @forelse ($virtuals as $virtual)
                            <tr>
                                <td>{{ $virtual->user_name }}</td>
                                <td>{{ $virtual->system }}</td>
                                <td>                                    
                                @switch($virtual->ready)
                                    @case(0)
                                            Requested   
                                        @break;
                                    @case(1)
                                            Waiting to deploy
                                        @break;
                                    @case(2)
                                            Deployed
                                        @break;
                                    @case(3)
                                            Asked to delete
                                        @break;
                                    @case(4)
                                            Deleting
                                        @break;
                                    @default
                                        Undefined
                                @endswitch 
                                </td>
                                <td>
                                    @if (($virtual->ready == '0')||($virtual->ready == '1'))
                                        <form action="{{ route('virtuals.destroy', $virtual) }}" method="POST" class="float-left">
                                            @csrf
                                            {{ method_field('DELETE') }}
                                            <button type="submit" class="btn btn-warning">Delete</button>
                                        </form>
                                    @endif
                                    @if ($virtual->ready < '2')
                                      <form action="{{ route('virtuals.show', $virtual->id) }}" method="GET">
                                            @csrf
                                            <button type="submit" class="btn btn-secondary float-left">Show</button>
                                        </form>
                                    @endif 

                                    @if ($virtual->ready == '2')
                                        <form action="/virtuals/{{ $virtual->id }}/requestdelete" method="GET">
                                            @csrf
                                            <button type="submit" class="btn btn-warning float-left">Delete Virtual</button>
                                        </form> 
                                    @endif 
                                    @if ($virtual->ready == '3')
                                    <form action="/virtuals/{{ $virtual->id }}/canceldelete" method="GET">
                                        @csrf
                                        <button type="submit" class="btn btn-success float-left">Cancel delete</button>
                                    </form> 
                                    <form action="/virtuals/{{ $virtual->id }}/delete" method="GET">
                                        @csrf
                                        <button type="submit" class="btn btn-warning float-left">Delete</button>
                                    </form> 
                                    @endif 
                        
                                </td>
                            </tr>
                        @empty
                            <tr>
                                <td>No Virtuals</td>                                
                            </tr>
                        @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
