{% extends "base.html" %}
{% load crispy_forms_filters %}
{% load static %}
{% load i18n %}

{% block title %}{% trans "Overview" %}{% endblock %}


{% block content %}

    <div style="text-align: center">

        <h3 class="">{% trans 'Space' %}</h3>

        <div class="row">
            <div class="col col-md-12">
                {% trans 'Recipes, foods, shopping lists and more are organized in spaces of one or more people.' %}
                {% trans 'You can either be invited into an existing space or create your own one.' %}
            </div>
        </div>

        {% if request.user.userspace_set.all|length > 0 %}
            <div class="row mt-2">
                <div class="col col-12">
                    <h5>{% trans 'Your Spaces' %}</h5>
                </div>
            </div>

            <div class="row mt-2">
                <div class="col col-12">
                    <div class="card-deck">
                        {% for us in request.user.userspace_set.all %}

                            <div class="card">
                                {% if us.space.image and us.space.image.is_image %}
                                    <img style="height: 15vh; object-fit: cover" src="{{ us.space.image.file.url }}"
                                         class="card-img-top" alt="Image">
                                {% else %}

                                    <img style="height: 15vh; object-fit: cover" src="{% static 'assets/recipe_no_image.svg' %}"
                                         class="card-img-top" alt="Image">
                                {% endif %}
                                <div class="card-body">
                                    <h5 class="card-title"><a
                                            href="{% url 'view_switch_space' us.space.id %}">{{ us.space.name }}</a>
                                    </h5>
                                    {#                                    {% if us.active %}#}
                                    {#                                        <i class="far fa-dot-circle fa-fw"></i>#}
                                    {#                                    {% else %}#}
                                    {#                                        <i class="far fa-circle fa-fw"></i>#}
                                    {#                                    {% endif %}#}
                                    <p class="card-text"><small
                                            class="text-muted">{% trans 'Owner' %}: {{ us.space.created_by }}</small>
                                        {% if us.space.created_by != us.user %}
                                            <p class="card-text"><small
                                                class="text-muted"><a
                                                href="{% url 'delete_user_space' us.pk %}">{% trans 'Leave Space' %}</a></small>
                                        {% endif %}
                                        <!--TODO add direct link to management page -->
                                        </p>
                                </div>
                            </div>
                        {% endfor %}
                    </div>
                </div>

            </div>
        {% endif %}

        <div class="row" style="margin-top: 2vh">
            <div class="col col-md-12">

                <div class="card-group">


                    <div class="card">
                        <div class="card-header">
                            {% trans 'Join Space' %}
                        </div>
                        <div class="card-body">
                            <h5 class="card-title">{% trans 'Join an existing space.' %}</h5>
                            <p class="card-text"
                               style="height: 64px">{% trans 'To join an existing space either enter your invite token or click on the invite link the space owner send you.' %}</p>

                            <form method="POST" action="{% url 'view_space_overview' %}">
                                {% csrf_token %}
                                {{ join_form | crispy }}
                                <input type="submit" class="btn btn-primary" value="{% trans 'Join Space' %}"/>
                            </form>

                        </div>
                    </div>

                    <div class="card">
                        <div class="card-header">
                            {% trans 'Create Space' %}
                        </div>
                        <div class="card-body">
                            <h5 class="card-title">{% trans 'Create your own recipe space.' %}</h5>
                            <p class="card-text"
                               style="height: 64px">{% trans 'Start your own recipe space and invite other users to it.' %}</p>
                            <form method="POST" action="{% url 'view_space_overview' %}">
                                {% csrf_token %}
                                {{ create_form | crispy }}
                                <input type="submit" class="btn btn-primary" value="{% trans 'Create Space' %}"/>
                            </form>
                        </div>
                    </div>


                </div>
            </div>

        </div>

    </div>

{% endblock %}

