{% extends "base.html" %}

{% block title %}My Outfits - New Style{% endblock %}

{% block extra_css %}
<style>
    .folder-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
        margin-bottom: 30px;
    }
    .folder-card {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 8px;
        padding: 20px;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 10px;
        cursor: pointer;
        transition: border-color 0.2s;
        text-decoration: none;
        color: var(--text);
    }
    .folder-card:hover {
        border-color: var(--accent);
    }
    .folder-card i {
        font-size: 2rem;
        color: var(--accent);
    }
    .folder-card .folder-name {
        font-weight: 700;
        font-size: 0.8rem;
        text-transform: uppercase;
        letter-spacing: 1px;
    }
    .folder-card .item-count {
        font-size: 0.6rem;
        color: var(--text-muted);
    }

    .outfit-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    .outfit-card {
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: 4px;
        overflow: hidden;
        position: relative;
    }
    .outfit-preview {
        aspect-ratio: 1/1.2;
        background: #1a1a1a;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .outfit-preview img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }
    .outfit-info {
        padding: 10px;
        background: rgba(0,0,0,0.8);
        position: absolute;
        bottom: 0;
        width: 100%;
    }
    .outfit-name {
        font-weight: 700;
        font-size: 0.7rem;
        text-transform: uppercase;
        margin: 0;
    }
</style>
{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2 class="font-montserrat m-0" style="font-size: 1.2rem;">COLLECTIONS</h2>
    <button class="btn-custom py-1" data-bs-toggle="modal" data-bs-target="#folderModal">
        <i class="bi bi-folder-plus"></i> NEW
    </button>
</div>

<div class="folder-grid">
    {% for folder in folders %}
        <div class="folder-card">
            <i class="bi bi-folder2-open"></i>
            <span class="folder-name">{{ folder.name }}</span>
            <span class="item-count">{{ folder.outfits.count }} OUTFITS</span>
        </div>
    {% empty %}
        <div class="col-12 text-center text-muted py-3 small">No folders created yet.</div>
    {% endfor %}
</div>

<div class="line-separator"></div>

<h2 class="font-montserrat mb-4" style="font-size: 1.2rem;">UNCATEGORIZED FITS</h2>

<div class="outfit-grid">
    {% for outfit in outfits %}
        <div class="outfit-card">
            <div class="outfit-preview">
                {% if outfit.items.exists %}
                    <img src="{{ outfit.items.first.image.url }}" alt="{{ outfit.name }}">
                {% else %}
                    <i class="bi bi-images text-muted"></i>
                {% endif %}
            </div>
            <div class="outfit-info">
                <p class="outfit-name">{{ outfit.name|default:"UNTITLED" }}</p>
                <div class="d-flex justify-content-between align-items-center">
                    <span class="text-muted" style="font-size: 0.6rem;">{{ outfit.items.count }} ITEMS</span>
                </div>
            </div>
        </div>
    {% empty %}
        <div class="col-12 text-center text-muted py-5">
            <p class="small">No outfits found.</p>
            <a href="{% url 'new_fit' %}" class="btn-accent">CREATE NEW FIT</a>
        </div>
    {% endfor %}
</div>

<!-- Folder Modal -->
<div class="modal fade" id="folderModal" tabindex="-1">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content">
            <div class="modal-header border-0">
                <h5 class="modal-title font-montserrat">NEW COLLECTION</h5>
                <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
            </div>
            <form action="{% url 'create_folder' %}" method="POST">
                {% csrf_token %}
                <div class="modal-body">
                    <div class="mb-3">
                        <label class="form-label text-muted small">Collection Name</label>
                        <input type="text" name="name" class="form-control" placeholder="e.g. Winter Essentials" required>
                    </div>
                </div>
                <div class="modal-footer border-0">
                    <button type="button" class="btn-custom" data-bs-dismiss="modal">CANCEL</button>
                    <button type="submit" class="btn-accent">CREATE</button>
                </div>
            </form>
        </div>
    </div>
</div>
{% endblock %}