<!--
Copyright (C) 2022 Echedey López Romero <elr@disroot.org>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row mb-3">
        <h1 class="col-12 mb-0 text-center">Loan creation</h1>
    </div>
    @if ($errors->any())
    <div class = "row mb-3">
        <div class="col-xl-6 col-lg-8 col-md-10 col-12 mx-auto alert alert-danger">
            <div class="container">
                <div class="row mb-2">
                    <span class="col-12 text-center"><strong>Whoops!</strong> There were some problems with your input.</span>
                </div>
                <div class="row">
                    <ul class="col-12 mb-0">
                        @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            </div>
        </div>
    </div>
    @endif
    <div class="row">
        <form class="col-xl-6 col-lg-8 col-md-10 col-12 mx-auto" action="{{ route('loans.store') }}" method="POST">
            @csrf
            <div class="container">
                <div class="row mb-3">
                    <div class="col-12">
                        <label class="form-label" for="user">User</label>
                        <select class="form-control" id="user" name="user_id" required="">
                            <option value="">-- Choose --</option>
                            @foreach ($users as $user)
                            @if ($user->id . '' === old('user_id'))
                            <option value="{{ $user->id }}" selected="">{{ $user->name }}</option>
                            @else
                            <option value="{{ $user->id }}">{{ $user->name }}</option>
                            @endif
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="row mb-3">
                    <div class="col-12">
                        <label class="form-label" for="book">Book</label>
                        <select class="form-control" id="book" name="book_id" required="">
                            <option value="">-- Choose --</option>
                            @foreach ($books as $book)
                            @if ($book->id . '' === old('book_id'))
                            <option value="{{ $book->id }}" selected="">{{ $book->title . ' - ' . $book->authors }}</option>
                            @else
                            <option value="{{ $book->id }}">{{ $book->title . ' - ' . $book->authors }}</option>
                            @endif
                            @endforeach
                        </select>
                    </div>
                </div>
                <div class="row mb-3">
                    <div class="col-12">
                        <label class="form-label" for="start">Start</label>
                        <input class="form-control" type="date" id="start" name="start" value="{{ old('start') }}" required=""/>
                    </div>
                </div>
                <div class="row">
                    <div class="col-lg-6 col-12 mb-lg-0 mb-2">
                        <div class="d-grid gap-2">
                            <button type="submit" class="btn btn-primary">Add</button>
                        </div>
                    </div>
                    <div class="col-lg-6 col-12">
                        <div class="d-grid gap-2">
                            <button type="reset" class="btn btn-danger">Reset</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
@endsection
