<!--
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">Book information</h1>
    </div>
    <div class="row">
        <div class="col-xl-5 col-lg-6 col-md-8 col-12 mx-auto">
            <div class="container">
                <div class="row mb-3">
                    <span class="col-xl-4 col-12 my-xl-auto mb-2">ISBN</span>
                    <span class="col-xl-8 col-12 mb-xl-0 mb-2">{{ $book->isbn }}</span>
                </div>
                <div class="row mb-3">
                    <span class="col-xl-4 col-12 my-xl-auto mb-2">Title</span>
                    <span class="col-xl-8 col-12 mb-xl-0 mb-2">{{ $book->title }}</span>
                </div>
                <div class="row mb-3">
                    <span class="col-xl-4 col-12 my-xl-auto mb-2">Image</span>
                    <img src="{{ asset($book->image) }}"  class="col-xl-6 col-12 mb-xl-0 mb-2 img-thumbnail" alt="{{ $book->title }}"/>
                </div>
                <div class="row mb-3">
                    <span class="col-xl-4 col-12 my-xl-auto mb-2">Authors</span>
                    <span class="col-xl-8 col-12 mb-xl-0 mb-2">{{ $book->authors }}</span>
                </div>
                <div class="row mb-3">
                    <span class="col-xl-4 col-12 my-xl-auto mb-2">Year</span>
                    <span class="col-xl-8 col-12 mb-xl-0 mb-2">{{ $book->year ? $book->year : 'Undated' }}</span>
                </div>
                <div class="row mb-3">
                    <span class="col-xl-4 col-12 my-xl-auto mb-2">Editorial</span>
                    <span class="col-xl-8 col-12 mb-xl-0 mb-2">{{ $book->editorial ? $book->editorial : 'Self-published' }}</span>
                </div>
                @if($book->document)
                <div class="row mb-3">
                    <span class="col-xl-4 col-12 my-xl-auto mb-2">Document</span>
                    <span class="col-xl-8 col-12 mb-xl-0 mb-2">
                        <a href="{{ $book->document }}" target="_blank">Download</a>
                    </span>
                </div>
                @endif
                <div class="row mb-3">
                    <span class="col-xl-4 col-12 my-xl-auto mb-2">Category</span>
                    <span class="col-xl-8 col-12 mb-xl-0 mb-2">{{ $book->category_id ? $book->category->name : 'Unclassified' }}</span>
                </div>
                <div class="row">
                    <span class="col-xl-4 col-12 my-xl-auto mb-2">Availability</span>
                    @if(\App\Models\Book::where('id', $book->id)
                                            ->whereHas('loans', function ($query) {
                                                $query->whereNull('end');
                                            })->exists())
                    <span class="col-xl-8 col-12 mb-xl-0 mb-2">Unavailable</span>
                    @else
                    <span class="col-xl-8 col-12 mb-xl-0 mb-2">Available</span>
                    @endif
                </div>
            </div>
        </div>
    </div>
</div>
</div>
@endsection
