@extends('layouts.app')

@section('content')
@auth
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card text-white bg-dark">
                @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="{{ route('createTournament') }}">
                        @csrf
                        <div class="form-group row">
                            <label for="description" class="col-md-4 col-form-label text-md-right">Nom du tournoi</label>
                            <div class="col-md-6">
                                <input name="description" id="description" type="text" class="form-control" required autofocus>
                            </div>
                            <div class="invalid-feedback">
                                Veuillez saisir un nom.
                            </div>
                        </div>

                        <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>
                                    @foreach ($games as $game)
                                        <option value="{{ $game->id_game }}">{{ $game->titre }}</option>
                                    @endforeach
                                </select>
                            </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>
                                        @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="year-begin" id="year-begin" class="custom-select" required>
                                        @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">Enregistrer le tournoi</button>
                        </div>
                        
                    </form>

                </div>
            </div>
        </div>
    </div>
</div>
@else
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            
            <div class="alert alert-danger" role="alert">
                Vous devez être connecté pour accéder à cette page.
            </div>
        </div>
    </div>
</div>
@endauth
@endsection
