{% extends 'base.html.twig' %}

{% block title %}{{ book.title }}{% endblock %}

{% block content %}
	<div class="page_content">
		<h2>{{ book.title }}</h2>

		<div class="columns">
			<div class="column col-7 col-md-12">
				{% embed 'book/_details.html.twig' %}
					{% block footer %}
						<div class="panel-footer">
							<a class="btn"
							   href="{{ path('book_edit', {id: book.id}) }}">{% trans %}book_action_edit{% endtrans %}</a>
						</div>
					{% endblock %}
				{% endembed %}

				{{ include('book/_history.html.twig', {history: book.borrowHistory}) }}
			</div>
			<div class="column col-5 col-md-12">
				<div class="panel book-panel">
					<div class="panel-header">
						<div class="panel-title h5">{% trans %}cover_section_title{% endtrans %}</div>
					</div>
					{% if book.cover %}
						<div class="panel-body">
							{{ include('book/_cover.html.twig') }}
							<form action="{{ path('cover_remove', {id: book.id}) }}" method="post">
								<input type="hidden" name="_token" value="{{ csrf_token('remove-cover' ~ book.id) }}"/>
								<button class="btn btn-link btn-sm">{% trans %}cover_action_remove{% endtrans %}</button>
							</form>
						</div>
					{% endif %}
					<div class="panel-footer">
						{{ form(cover_form) }}
					</div>
				</div>

				<div class="panel book-panel">
					<div class="panel-header">
						<div class="panel-title h5">{% trans %}borrow_section_title{% endtrans %}</div>
					</div>
					{% if book.borrow %}
						<div class="panel-body">
							<p>{{ 'borrow_lent_to'|trans({'%who%': book.borrow.who, '%date%': book.borrow.at|date('Y-m-d')}) }}</p>
						</div>
						<div class="panel-footer">
							<form action="{{ path('book_return', {id: book.id}) }}" method="post">
								<input type="hidden" name="_token" value="{{ csrf_token('return' ~ book.id) }}"/>
								<button class="btn btn-primary">{% trans %}borrow_action_return{% endtrans %}</button>
							</form>
						</div>
					{% else %}
						<div class="panel-footer">
							{{ form(borrow_form) }}
						</div>
					{% endif %}
				</div>

				<div class="panel book-panel">
					<div class="panel-header">
						<div class="panel-title h5">{% trans %}menu_labels{% endtrans %}</div>
					</div>
					{% if book.labels is not empty %}
						<div class="panel-body">
							<ul class="book-labels">
								{% for label in book.labels %}
									<li>
										{% if label.type.value == 'text' %}
											<span class="label label-rounded">{{ label.label }}</span>
										{% else %}
											<span class="label label-rounded">{{ ('label_type_' ~ label.type.value)|trans }}: {{ label.label }}</span>
										{% endif %}
										<form class="inline" action="{{ path('label_remove', {id: label.id}) }}"
											  method="post">
											<input type="hidden" name="_token"
												   value="{{ csrf_token('remove-label' ~ label.id) }}"/>
											<button class="btn btn-link btn-sm">{% trans %}label_action_remove{% endtrans %}</button>
										</form>
									</li>
								{% endfor %}
							</ul>
						</div>
					{% endif %}
					<div class="panel-footer">
						{{ form(label_form) }}
					</div>
				</div>

				{% if not book.borrowed %}
					<div class="panel book-panel">
						<div class="panel-header">
							<div class="panel-title h5">{% trans %}ousted_section_title{% endtrans %}</div>
							<div class="panel-subtitle text-gray">{% trans %}ousted_section_desc{% endtrans %}</div>
						</div>
						<div class="panel-footer">
							{{ form(oust_form) }}
						</div>
					</div>
				{% endif %}
			</div>
		</div>
	</div>
{% endblock %}
