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

{% block title %}Strony statyczne - {{ setting('title') }}{% endblock %}

{% block content %}
<hgroup class="page-header">
	<h1><i class="fas fa-file-alt"></i> Strony statyczne</h1>
	<a href="{{ path('static_pages_new') }}" class="btn btn-primary" title="Dodaj stronę">Dodaj stronę</a>
</hgroup>

{% include 'partial/alert.html.twig' %}

{% if pages|length > 0 %}
	<div class="table-responsive">
		<table class="table table-striped table-sm table-bordered">
			<thead>
				<tr>
					<th>Tytuł</th>
					<th class="text-center">Utworzono</th>
					<th class="text-center">Edytuj</th>
					<th class="text-center">Usuń</th>
				</tr>
			</thead>
			<tbody>
				{% for page in pages %}
					<tr>
						<td>
							<a href="{{ path('static_page', {slug: page.slug}) }}" target="_blank"><strong>{{ page.name }}</strong></a>
						</td>
						<td class="text-center">
							<small>{{ page.createdAt|date('d.m.Y H:i') }}</small>
						</td>
						<td class="text-center">
							<a href="{{ path('static_pages_edit', {id: page.id}) }}" class="btn btn-link" title="Edytuj">
								<i class="fas fa-edit"></i>
							</a>
						</td>
						<td class="text-center">
							<button class="btn btn-link text-danger" data-bs-toggle="modal" data-bs-target="#remove_{{ page.id }}" aria-label="Usuń" title="Usuń"><i class="fas fa-trash-alt"></i></button>
						</td>
					</tr>
				{% endfor %}
			</tbody>
		</table>
	</div>

	{% for page in pages %}
		<div class="modal fade" id="remove_{{ page.id }}" tabindex="-1" role="dialog" aria-labelledby="titleModal{{ page.id }}">
			<div class="modal-dialog" role="document">
				<div class="modal-content">
					<div class="modal-header">
						<h5 class="modal-title" id="titleModal{{ page.id }}">Usuń {{ page.name }}</h5>
						<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Anuluj"></button>
					</div>
					<form method="post" action="{{ path('static_pages_delete', { id: page.id }) }}">
						<input type="hidden" name="token" value="{{ csrf_token('delete-page') }}"/>
						<div class="modal-body">
							<p class="mb-1">Na pewno chcesz usunąć: {{ page.name }}?</p>
						</div>
						<div class="modal-footer">
							<input type="button" class="btn btn-secondary" data-bs-dismiss="modal" value="Anuluj">
							<input type="submit" class="btn btn-danger" value="Usuń">
						</div>
					</form>
				</div>
			</div>
		</div>
  {% endfor %}
{% else %}
	<h5 class="text-danger">Nic nie znaleziono</h5>
{% endif %}

{% endblock %}
