{% extends "main/layout.html" %}
{% from 'global_macros.html' import data, preload_circle, select %}
{% from 'main/macros.html' import App, Collection, Custom %}

{% block page_vendor_css %}
{% endblock page_vendor_css %}

{% block page_lvl_css %}
    {{ process_css_sources(src="main/home.css")|safe }}
    {% if settings.background and settings.background != 'None' %}
        <style>
            #main {
                background-image: url("{{ settings.background }}");
                background-size: cover;
                background-attachment: fixed;
                min-height: 100vh;
            }
        </style>
    {% endif %}
{% endblock page_lvl_css %}

{% block content %}
    <div id="main" class="main-full">
        <div class="container">
            <div class="row card-filter-container">
                <div class="col s12 m12 l6 xl4 input-field">
                    <span>
                        <i class="material-icons prefix card-search-icon">search</i>
                        <input type="text" id="apps-filter" class="card-filter theme-surface-transparent" placeholder="Search apps" autofocus>

                        <i id="toggle-tag-expand-all-btn" class="material-icons right filter-action pointer">unfold_less</i>
                    </span>
                </div>
                {% if tags_form.tags.choices|count > 1 %}
                    <div class="input-field col s6 m4 l2 offset-s3 offset-m4 tags-select-col theme-surface-transparent">
                        {{ tags_form.tags(id='tags-select') }}
                    </div>
                {% endif %}
            </div>
            <div class="row">
                {% if apps %}
                    {# If tags are enabled, render the apps like this #}
                    {% if tags|count > 1 %}
                        {% for tag in tags %}
                            <div class="tag-group" data-tag="{{ tag.name }}">
                                <div class="divider"></div>
                                <div class="row">
                                    <div class="col s12 m12 l6 xl4">
                                        <div class="card theme-surface-transparent">
                                            <div class="card-content pt-0 pb-0">
                                                <h5 style="font-size: 1.4em">
                                                    {% if tag.icon %}
                                                        <i class="material-icons-outlined mr-2 theme-primary-text" style="position: relative; top: .2rem">{{ tag.icon }}</i>
                                                    {% endif %}
                                                    {{ tag.name }}
                                                    <i class="material-icons-outlined theme-secondary-text icon-btn toggle-tag-expand-btn right" data-expanded="true" style="position: relative; bottom: 5px">keyboard_arrow_up</i>
                                                </h5>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row tag-apps-row">
                                    {% for app in apps %}
                                        {% if app.tags and tag.name in app.tags %}
                                            {% if app.type == "app" %}
                                                {{ App(app) }}
                                            {% elif app.type == "collection" %}
                                                {{ Collection(app) }}
                                            {% elif app.type == "custom" %}
                                                {{ Custom(app) }}
                                            {% endif %}

                                        {% endif %}
                                    {% endfor %}
                                </div>
                            </div>
                        {% endfor %}
                    {% else %}
                        {# otherwise, render the apps like this #}
                        {% for app in apps %}
                            {% if app.type == "app" %}
                                {{ App(app) }}
                            {% elif app.type == "collection" %}
                                {{ Collection(app) }}
                            {% elif app.type == "custom" %}
                                {{ Custom(app) }}
                            {% endif %}
                        {% endfor %}
                    {% endif %}
                {% else %}
                    <a href="{{ url_for('settings_system.settings') }}">
                        <div class="col s12 m6 l3">
                            <div class="card theme-surface-transparent">
                                <div class="card-action center-align">
                                    <h5>No apps yet, go to settings.</h5>
                                </div>
                            </div>
                        </div>
                    </a>
                {% endif %}
            </div>
        </div>
    </div>
{% endblock content %}

{% block page_vendor_js %}
{% endblock page_vendor_js %}

{% block page_lvl_js %}
    {{ process_js_sources(src="main/home.js")|safe }}
{% endblock page_lvl_js %}