<!--
  This file is part of Flask-Wiki
  Copyright (C) 2020 RERO

  Flask-Wiki is free software; you can redistribute it and/or modify
  it under the terms of the Revised BSD License; see LICENSE file for
  more details
-->

{% extends config.get('WIKI_BASE_TEMPLATE') %}
{% set active_page = "files" %}

{% block content %}
<div data-delay="1500" class="toast hide">
    <div class="toast-header text-primary font-weight-bold">
        Markdown
    </div>
    <div class="toast-body">
        {{ _('Copied to your clipboard') }}
    </div>
</div>
<main class="row mt-4 wiki-files">
    <article class="offset-md-1 col-md-10">
        <header class="d-flex flex-column flex-lg-row justify-content-lg-between">
            <h1>{{ _('List of Uploaded Files') }}</h1>
            {% if can_edit_wiki %}
            <form class="" method="post" enctype="multipart/form-data">
                <div class="custom-file">
                    <button class="btn btn-outline-primary btn-sm"><i class="fa fa-upload" aria-hidden="true"></i> {{ _('Upload a file') }}</button>
                    <input class="custom-file-input" type="file" name="file" accept="image/*" />
                </div>
            </form>
            {% endif %}
        </header>
        <article class="d-flex flex-wrap">
            {% for file in files -%}
            <figure id="{{file}}" class="figure m-2">
                <img src="{{ url_for('uploaded_files', filename=file) }}" class="figure-img img-fluid rounded img-thumbnail"
                                                                          alt="{{ file }}" />
                <figcaption class="figure-caption text-center">
                    <a href="{{ url_for('uploaded_files', filename=file) }}">{{ file }}</a>
                    <button data-name="{{ file }}" data-link="{{ url_for('uploaded_files', filename=file) }}"
                                                   class="copy-md-code btn btn-sm btn-outline-primary">
                        <i class="fa fa-clipboard"></i>
                    </button>
                    <button data-toggle="modal" data-target="#deleteModal" id="{{file}}" class="delete-file btn btn-sm btn-outline-danger">
                        <i class="fa fa-trash"></i>
                    </button>
                </figcaption>
            </figure>
            {%- endfor %}
        </article>
    </article>
</main>

<!-- Delete modal -->
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalCenterTitle"
    aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="deleteModalCenterTitle">{{ _('Delete file') }}</h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                {{ _('Are you sure you want to delete this file? Be warned that links from existing pages will be broken.') }}
            </div>
            <div class="modal-footer">
                <a id="confirm" href="{{ url_for('wiki.delete_file', filename=file) }}" type="button"
                    class="btn btn-danger">{{ _('Delete file') }}</a>
                <button type="button" class="btn btn-outline-primary" data-dismiss="modal">{{ _('Back') }}</button>
            </div>
        </div>
    </div>
</div>
</div>

{% endblock %}
