{% extends "base.html" %}

{% block style %}
    {{ super() }}
    {% for widget in manager.get_widgets('style') %}
        <link rel="stylesheet" type="text/css" href="{{ widget.href }}"/>
    {% endfor %}
{% endblock %}

{% block scripts %}
    {{ super() }}
    {% for widget in manager.get_widgets('javascript') %}
        <script src="{{ widget.src }}"></script>
    {% endfor %}
{% endblock %}

{% block header %}
<h1>
    {% for parent in file.ancestors[::-1] %}
        <a href="{{ url_for('browse', path=parent.urlpath) }}">{{ parent.name }}</a>
        <span> / </span>
    {% endfor %}
    {{ file.name }}
</h1>
{% endblock %}

{% block content %}
{% if file.can_upload %}
    <form class="upload" method="post" action="{{ url_for('upload', path=file.urlpath) }}" enctype="multipart/form-data">
        <label>
            <h2>Upload</h2>
            <input type="file" name="file"/>
        </label>
        <input type="submit"/>
    </form>
{% endif %}
{% if file.is_empty %}
    <p>No files in directory</p>
{% else %}
    <table class="browser">
        <thead>
            <tr>
                <th colspan="3">Name</th>
                <th>Mimetype</th>
                <th>Modified</th>
                <th>Size</th>
            </tr>
        </thead>
        <tbody>
            {% for f in file.listdir() %}
                <tr>
                    {% set endpoint, widget = f.default_action %}
                    <td class="{{ widget.icon }}"></td>
                    <td>
                        <a href="{{ url_for(endpoint, path=f.urlpath) }}"
                           {% if widget.css %}class="{{ widget.css }}"{% endif %}
                           >{{ widget.text }}</a>
                    </td>
                    <td>
                        {% if f.can_remove %}
                        <a href="{{ url_for('remove', path=f.urlpath) }}" class="remove button"></a>
                        {% endif %}
                        {% if f.can_download %}
                        <a href="{{ url_for('download_directory' if f.is_directory else 'download_file', path=f.urlpath) }}" class="download button"></a>
                        {% endif %}
                        {% for endpoint, widget in f.actions %}
                            {% if widget.place == 'button' %}
                                <a href="{{ url_for(endpoint, path=f.urlpath) }}"
                                   class="button{% if widget.css %} {{widget.css}}{% endif %}"
                                   >{{ widget.content }}</a>
                            {% endif %}
                        {% endfor %}
                    </td>
                    <td>{{ f.type }}</td>
                    <td>{{ f.modified }}</td>
                    <td>{{ "" if f.is_directory else f.size }}</td>
                </tr>
            {% endfor %}
        </tbody>
    </table>
{% endif %}
{% endblock %}
