@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">Edit virtual</div>

                <div class="card-body">
                    @if (session('status'))
                        <div class="alert alert-success" role="alert">
                            {{ session('status') }}
                        </div>
                    @endif
                    <form action="{{ route('virtuals.update', $virtual) }}" method="POST">
                        @csrf
                        {{ method_field('PUT') }}
                        <div class="form-group row">

                            <label for="System" class="col-md-4 col-form-label text-md-right">System</label>
                            <div class="col-md-6">                            
                                <select name="system" id="system" class="form-control">  
                                    @forelse ($systems as $system)
                                        <option <?php if( $virtual->system==$system->name){ echo "selected"; } ?> value={{$system->name}}>{{$system->name}}</option>
                                    @empty
                                        <p>No systems to choose from</p>
                                    @endforelse                                
                                </select>
                                <br>
                            </div>

                            <label for="System" class="col-md-4 col-form-label text-md-right">Mem size</label>
                            <div class="col-md-6">
                                <table>
                                    <tr>
                                    <td>
                                        <input value="{{$virtual->memory}}" name="memory" id="memory" type="number" size="3" min="1" max="100"/>
                                    </td>
                                    <td>GB</td>
                                    </tr>
                                </table>
                                <p style="color: red">@error('memory') {{ $message }} @enderror</p>
                            </div>

                            <label for="System" class="col-md-4 col-form-label text-md-right">Disk size</label>
                            <div class="col-md-6">
                                <table>
                                    <tr>
                                    <td>
                                        <input value="{{$virtual->disk}}" name="disk" id="disk" type="number" size="3" min="1" max="100"/>
                                    </td>
                                    <td>GB</td>
                                    </tr>
                                </table>
                                <p style="color: red">@error('disk') {{ $message }} @enderror</p>
                            </div>

                            <label for="System" class="col-md-4 col-form-label text-md-right">Number of CPU</label>
                            <div class="col-md-6">
                                    <table>
                                        <tr>
                                        <td>
                                            <input value="{{$virtual->cpu}}" name="cpu" id="cpu" type="number" size="3" min="1" max="100"/>
                                        </td>
                                        <td>CPU</td>
                                        </tr>
                                    </table>
                                    <p style="color: red">@error('cpu') {{ $message }} @enderror</p>
                            </div>
                            
                            @can('manage-virtuals')
                            <label for="Server" class="col-md-4 col-form-label text-md-right">Server</label>
                            <div class="col-md-6">
                                <table>
                                    <tr>
                                        <td>
                                            <input style="color: grey" readonly value="{{$server}}" name="Server" id="Server" />
                                        </td>
                                    </tr>
                                </table>
                            </div>

                            <label for="Server" class="col-md-4 col-form-label text-md-right">Network</label>
                            <div class="col-md-6">
                                <table>
                                    <tr>
                                        <td>
                                            <input style="color: grey" readonly value="{{$virtual->switch}}" name="Server" id="Server" />
                                        </td>
                                        
                                        <td> 
                                            <a href="/virtuals/{{$virtual->id}}/editserver">
                                                <button type="button" class="btn btn-primary float-left">Change</button>
                                            </a>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            @endcan
                        </div>
                        <button type="submit" class="btn btn-primary">
                            Update
                        </button>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection
