{% extends "filechest/base.html" %}

{% block title %}FileChest{% endblock %}

{% block extra_head %}
    <style>
        body {
            display: flex;
            flex-direction: column;
        }

        .container {
            max-width: 800px;
            margin: 40px auto;
            padding: 0 20px;
            flex: 1;
        }

        .page-title {
            text-align: center;
            font-size: 2.5em;
            color: #333;
            margin: 0 0 10px 0;
        }

        .page-subtitle {
            text-align: center;
            color: #666;
            margin: 0 0 40px 0;
        }

        .user-bar {
            display: flex;
            justify-content: flex-end;
            align-items: center;
            gap: 15px;
            margin-bottom: 20px;
            padding: 10px 0;
            border-bottom: 1px solid #ddd;
        }

        .user-bar .username {
            color: #333;
            font-weight: 500;
        }

        .user-bar .btn-logout {
            padding: 6px 12px;
            background: #eee;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 13px;
        }

        .user-bar .btn-logout:hover {
            background: #ddd;
        }

        .user-bar .btn-login {
            padding: 8px 16px;
            background: #1976d2;
            color: white;
            border-radius: 4px;
            text-decoration: none;
            font-size: 14px;
        }

        .user-bar .btn-login:hover {
            background: #1565c0;
        }

        .volume-list {
            display: grid;
            gap: 15px;
        }

        .volume-card {
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            padding: 20px;
            display: flex;
            align-items: center;
            text-decoration: none;
            color: inherit;
            transition: box-shadow 0.2s, transform 0.2s;
        }

        .volume-card:hover {
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
            transform: translateY(-2px);
        }

        .volume-icon {
            font-size: 2.5em;
            margin-right: 20px;
        }

        .volume-info {
            flex: 1;
        }

        .volume-name {
            font-size: 1.3em;
            font-weight: 500;
            color: #333;
            margin: 0 0 5px 0;
        }

        .volume-description {
            color: #666;
            margin: 0;
            font-size: 0.95em;
        }

        .volume-role {
            font-size: 0.85em;
            padding: 4px 10px;
            border-radius: 12px;
            background: #e3f2fd;
            color: #1976d2;
        }

        .volume-role.editor {
            background: #e8f5e9;
            color: #388e3c;
        }

        .empty-message {
            text-align: center;
            padding: 60px 20px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            color: #666;
        }
    </style>
{% endblock %}

{% block content %}
    <div class="container">
        <div class="user-bar">
            {% if not adhoc_mode %}
              {% if user.is_authenticated %}
                <span class="username">{{ user.username }}</span>
                <form action="{% url 'filechest:logout' %}" method="post" style="display:inline;">
                  {% csrf_token %}
                  <button type="submit" class="btn-logout">Logout</button>
                </form>
              {% else %}
                <a href="{% url 'filechest:login' %}" class="btn-login">Login</a>
              {% endif %}
            {% endif %}
        </div>

        <h1 class="page-title">FileChest</h1>
        <p class="page-subtitle">Select a volume to browse files</p>

        {% if volumes %}
        <div class="volume-list">
            {% for item in volumes %}
            <a href="{% url 'filechest:index' item.volume.name %}" class="volume-card">
                <span class="volume-icon">{% if item.volume.is_s3 %}🪣{% else %}📁{% endif %}</span>
                <div class="volume-info">
                    <h2 class="volume-name">{{ item.volume.verbose_name }}</h2>
                    {% if item.volume.description %}
                    <p class="volume-description">{{ item.volume.description }}</p>
                    {% endif %}
                </div>
                <span class="volume-role {% if item.role == 'editor' %}editor{% endif %}">{{ item.role }}</span>
            </a>
            {% endfor %}
        </div>
        {% else %}
        <div class="empty-message">
            {% if user.is_authenticated or adhoc_mode %}
            <p>No volumes available.</p>
            {% else %}
            <p>Please <a href="{% url 'filechest:login' %}">login</a> to access your files.</p>
            {% endif %}
        </div>
        {% endif %}
    </div>
{% endblock %}
