{% extends 'base.html' %}
{% from 'macros/image.html' import gallery_item %}
{% block nav_groups %}selected{% endblock %}

{% block head %}
    {% if images %}
        <meta property="og:image" content="{{ url_for('api.media', path='uploads/' + images.0.filename) }}"/>
        <meta name="twitter:image" content="{{ url_for('api.media', path='uploads/' + images.0.filename) }}">
        <meta name="theme-color" content="rgb{{ images.0.colours.0 }}"/>
        <meta name="twitter:card" content="summary_large_image">
    {% endif %}

    <script type="text/javascript">
        group_data = {
            'id': {{ group.id }},
            'name': "{{ group.name }}",
            'description': "{{ group.description }}",
        }
    </script>

    <style>
        {% if images %}
            :root { --bg-100: {{ images.0.colours.0.0 }}, {{ images.0.colours.0.1 }}, {{ images.0.colours.0.2 }} }

            body {
                background: rgb{{ images.0.colours.0 }} !important;
                color: {{ text_colour }} !important;
            }
            main {
                background: rgba(var(--white), 0.6) !important;
            }


            .navigation-item.selected { color: {{ text_colour }} !important; }

            .banner .banner-content .banner-header,
            .banner .banner-content .banner-info,
            .banner .banner-content .banner-subtitle {
                color: {{ text_colour }} !important;
            }
            .banner-content .link {
                background-color: {{ text_colour }} !important;
                color: rgb{{ images.0.colours.0 }} !important;
            }
            .banner-content .link:hover {
                background-color: rgb{{ images.0.colours.0 }} !important;
                color: {{ text_colour }} !important;
            }

            .banner-filter {
                background: linear-gradient(90deg, rgb{{ images.0.colours.0 }}, rgba({{ images.0.colours.1.0 }}, {{ images.0.colours.1.1 }}, {{ images.0.colours.1.2 }}, 0.3)) !important;
            }
            @media (max-width: 800px) {
                .banner-filter {
                    background: linear-gradient(180deg, rgba({{ images.0.colours.1.0 }}, {{ images.0.colours.1.1 }}, {{ images.0.colours.1.2 }}, 0.4), rgba({{ images.0.colours.0.0 }}, {{ images.0.colours.0.1 }}, {{ images.0.colours.0.2 }}, 0.3)) !important;
                }
            }
        {% endif %}
    </style>
{% endblock %}

{% block header %}
    {% if images %}
        <div class="banner">
            <picture>
                <source srcset="{{ url_for('api.media', path='uploads/' + images.0.filename) }}?r=prev&e=webp">
                <source srcset="{{ url_for('api.media', path='uploads/' + images.0.filename) }}?r=prev&e=png">
                <img
                    src="{{ url_for('api.media', path='uploads/' + images.0.filename) }}?r=prev"
                    alt="{% if images.0.alt %}{{ images.0.alt }}{% else %}Group Banner{% endif %}"
                    onload="imgFade(this)" style="opacity:0;"
                />
            </picture>
            <span class="banner-filter"></span>
            <div class="banner-content">
                <p class="banner-info"><a href="{{ url_for('profile.profile', id=group.author.id) }}" class="link">By {{ group.author.username }}</a></p>
                <h1 class="banner-header">{{ group.name }}</h1>
                <p class="banner-subtitle">{{ images|length }} Images · {{ group.description }}</p>
                <div class="pill-row">
                    <div>
                        <button class="pill-item" onclick="copyToClipboard(window.location.href)"><i class="ph ph-export"></i></button>
                    </div>
                    {% if current_user.id == group.author.id %}
                        <div>
                            <button class="pill-item pill__critical" onclick="groupDeletePopup()"><i class="ph ph-trash"></i></button>
                            <button class="pill-item pill__critical" onclick="groupEditPopup()"><i class="ph ph-pencil-simple"></i></button>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    {% else %}
        <div class="banner-small">
            <div class="banner-content">
                <h1 class="banner-header">{{ group.name }}</h1>
                <p class="banner-info">By {{ group.author.username }}</p>
                <div class="pill-row">
                    <div>
                        <button class="pill-item" onclick="copyToClipboard(window.location.href)"><i class="ph ph-export"></i></button>
                    </div>
                    {% if current_user.id == group.author.id %}
                        <div>
                            <button class="pill-item pill__critical" onclick="groupDeletePopup()"><i class="ph ph-trash"></i></button>
                            <button class="pill-item pill__critical" onclick="groupEditPopup()"><i class="ph ph-pencil-simple"></i></button>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    {% endif %}
{% endblock %}

{% block content %}
    {% if images %}
        <div class="gallery-grid">
            {% for image in images %}{{ gallery_item(image) }}{% endfor %}
        </div>
    {% else %}
        <div class="big-text">
            <h1>*crickets chirping*</h1>
            {% if current_user.is_authenticated %}
                <p>Add some images to the group!</p>
            {% else %}
                <p>Login to start managing this image group!</p>
            {% endif %}
        </div>
    {% endif %}
{% endblock %}
