{% extends "base.html" %}

{% block title %}Discover Students | Warwick Connect{% endblock %}

{% block extra_css %}
<style>
    .discovery-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 1.5rem;
        margin-top: 2rem;
    }

    .profile-card {
        background: white;
        border-radius: 20px;
        overflow: hidden;
        border: 1px solid rgba(0,0,0,0.03);
        box-shadow: 0 4px 15px rgba(0,0,0,0.02);
        transition: transform 0.2s, box-shadow 0.2s;
        cursor: pointer;
        position: relative;
    }

    .profile-card:hover {
        transform: translateY(-5px);
        box-shadow: 0 10px 30px rgba(0,0,0,0.05);
    }

    .profile-img-container {
        width: 100%;
        height: 320px;
        background-color: #E2E8F0;
        position: relative;
        overflow: hidden;
    }

    .profile-img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .placeholder-img {
        width: 100%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        background: linear-gradient(135deg, #f1f5f9 0%, #cbd5e1 100%);
        color: var(--warwick-navy);
        font-size: 3rem;
        font-weight: 800;
    }

    .profile-info {
        padding: 1.25rem;
    }

    .profile-name {
        font-weight: 800;
        font-size: 1.25rem;
        margin-bottom: 0.25rem;
        color: var(--warwick-navy);
    }

    .profile-meta {
        font-size: 0.85rem;
        color: var(--text-muted);
        margin-bottom: 0.75rem;
        font-weight: 500;
    }

    .profile-tags {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .badge-tag {
        background-color: var(--bg-light);
        color: var(--warwick-navy);
        padding: 0.35rem 0.75rem;
        border-radius: 50px;
        font-size: 0.75rem;
        font-weight: 600;
    }

    .locked-overlay {
        position: absolute;
        inset: 0;
        background: rgba(255, 255, 255, 0.4);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        z-index: 10;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 2rem;
        text-align: center;
    }

    .locked-card {
        background: white;
        padding: 1.5rem;
        border-radius: 16px;
        box-shadow: 0 10px 25px rgba(0,0,0,0.1);
    }

    .locked-title {
        font-weight: 800;
        font-size: 1.1rem;
        margin-bottom: 0.5rem;
        color: var(--warwick-navy);
    }

    .locked-price {
        color: var(--accent-coral);
        font-weight: 700;
        font-size: 1.25rem;
        margin-bottom: 1rem;
    }

    .discovery-title {
        font-weight: 800;
        font-size: 2.5rem;
        margin-bottom: 0.5rem;
        color: var(--warwick-navy);
    }

    .discovery-subtitle {
        color: var(--text-muted);
        font-size: 1.1rem;
    }

    .online-indicator {
        position: absolute;
        bottom: 12px;
        right: 12px;
        width: 12px;
        height: 12px;
        background-color: #10B981;
        border: 2px solid white;
        border-radius: 50%;
        box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
    }
</style>
{% endblock %}

{% block content %}
<div class="header-section mt-4">
    <h1 class="discovery-title">Who's Online</h1>
    <p class="discovery-subtitle">Find fellow students at Warwick university.</p>
</div>

<div class="discovery-grid">
    {% for profile in visible_profiles %}
        <div class="profile-card">
            <div class="profile-img-container">
                {% if profile.primary_photo %}
                    <img src="{{ profile.primary_photo.image.url }}" class="profile-img" alt="{{ profile.user.username }}">
                {% else %}
                    <div class="placeholder-img">{{ profile.user.username|slice:":1"|upper }}</div>
                {% endif %}
                <div class="online-indicator"></div>
            </div>
            <div class="profile-info">
                <div class="profile-name">{{ profile.user.first_name|default:profile.user.username }}</div>
                <div class="profile-meta">{{ profile.course|default:"Student" }} · {{ profile.year }}</div>
                <div class="profile-tags">
                    <span class="badge-tag">{{ profile.location }}</span>
                    <span class="badge-tag">Looking for: {{ profile.looking_for }}</span>
                </div>
            </div>
        </div>
    {% empty %}
        <div class="text-center py-5 col-12">
            <h3 class="text-muted">No students found yet. Be the first to join!</h3>
        </div>
    {% endfor %}

    {% for profile in locked_profiles %}
        <div class="profile-card">
            <div class="profile-img-container" style="filter: blur(15px);">
                <div class="placeholder-img">{{ profile.user.username|slice:":1"|upper }}</div>
            </div>
            <div class="locked-overlay">
                <div class="locked-card">
                    <div class="locked-title">Unlock Full Grid</div>
                    <div class="locked-price">£3.99/mo</div>
                    <button class="btn btn-primary btn-sm w-100">Subscribe</button>
                    <p class="small text-muted mt-2 mb-0">See all students online</p>
                </div>
            </div>
            <div class="profile-info" style="filter: blur(10px);">
                <div class="profile-name">Student Name</div>
                <div class="profile-meta">Course · Year</div>
            </div>
        </div>
    {% endfor %}
</div>

{% if not is_subscribed and locked_profiles %}
    <div class="alert mt-5 p-4 text-center rounded-4" style="background: white; border: 2px dashed #CBD5E1;">
        <h4 class="fw-bold" style="color: var(--warwick-navy);">Ready to see everyone?</h4>
        <p class="text-muted">Join other subscribers and unlock the full discovery grid, messaging, and more.</p>
        <button class="btn btn-accent px-5">Subscribe for £3.99/month</button>
    </div>
{% endif %}
{% endblock %}
