@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            @if (isset($post))
            @if($post)
            <div class="alert alert-success" role="alert">
                Le tournoi a été créé.
            </div>
            $else
            <div class="alert alert-danger" role="alert">
                Un erreur est intervenue, merci de réessayer.
            </div>
            @endif
            @endif  
                <div class="card-header">Créer un tournoi</div>
                
                <div class="card-body">
                    <form method="POST" action="/form">
                        @csrf
                        <div class="form-group row">
                            <label for="select-game" class="col-md-4 col-form-label text-md-right">Choisissez un jeu</label>
                            <div class="col-md-6">
                                <select name="select-game" id="select-game" class="custom-select" required autofocus>
                                    @foreach ($games as $game)
                                        <option value="{{ $game->id_game }}">{{ $game->id_game }}</option>
                                    @endforeach
                                </select>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="tournament-name" class="col-md-4 col-form-label text-md-right">Nom du tournoi</label>
                            <div class="col-md-6">
                                <input name="tournament-name" id="tournament-name" type="text" class="form-control" required>
                            </div>
                            <div class="invalid-feedback">
                                Veuillez saisir un nom.
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="date-begin" class="col-md-4 col-form-label text-md-right">Date du début du tournoi</label>
                            <div class="col-md-6 row pr-0" name="date-begin" id="date-begin">
                                <div class="col-md-3">
                                    <select name="day-begin" id="day-begin" class="custom-select" required autofocus>
                                        @for ($i = 1; $i < 32; $i++)
                                            <option value="{{ $i }}">{{ $i }}</option>
                                        @endfor
                                    </select>
                                </div>
                                <div class="col-md-5">
                                    <select name="month-begin" id="month-begin" class="custom-select" required autofocus>
                                        @for ($i = 1; $i < 13; $i++)
                                            <option value="{{ $i }}">{{ date('F', mktime(0,0,0,$i) ) }}</option>
                                        @endfor
                                    </select>
                                </div>
                                <div class="col-md-4">
                                    <select name="day-begin" id="day-begin" class="custom-select" required autofocus>
                                        @for ($i = date('Y'); $i < date('Y') + 20; $i++)
                                            <option value="{{ $i }}">{{ $i }}</option>
                                        @endfor
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label for="date-end" class="col-md-4 col-form-label text-md-right">Date du fin du tournoi</label>
                            <div class="col-md-6 row pr-0" name="date-end" id="date-end">
                                <div class="col-md-3">
                                    <select name="day-end" id="day-end" class="custom-select" required autofocus>
                                        @for ($i = 1; $i < 32; $i++)
                                            <option value="{{ $i }}">{{ $i }}</option>
                                        @endfor
                                    </select>
                                </div>
                                <div class="col-md-5">
                                    <select name="month-end" id="month-end" class="custom-select" required autofocus>
                                        @for ($i = 1; $i < 13; $i++)
                                            <option value="{{ $i }}">{{ date('F', mktime(0,0,0,$i) ) }}</option>
                                        @endfor
                                    </select>
                                </div>
                                <div class="col-md-4">
                                    <select name="day-end" id="day-end" class="custom-select" required autofocus>
                                        @for ($i = date('Y'); $i < date('Y') + 20; $i++)
                                            <option value="{{ $i }}">{{ $i }}</option>
                                        @endfor
                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="form-group row">
                            <button class="btn btn-primary mx-auto" type="submit">Submit form</button>
                        </div>
                        
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
@endsection
