{% extends "bootstrap/base.html" %}

{% block title %}
{% if title %}
{{ title }}
{% else %}
CostHive
{% endif %}
{% endblock %}

{% block metas %}
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
{% endblock %}

{% block styles %}
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<link rel="stylesheet" href={{ url_for('static', filename="sidebars.css")}}>
{% endblock %}

{% block navbar %}
<main>
    <div class="flex-shrink-0 p-3 bg-black bg-opacity-10 scrollbar-primary h-100 position-fixed" style="width: 280px;">
        <a href="/"
            class="d-flex align-items-center pb-3 mb-3 link-dark text-decoration-none border-bottom border-dark">
            <svg class="bi me-2" width="30" height="24">
                <use xlink:href="#bootstrap"></use>
            </svg>
            <span class="fs-5 fw-semibold">
                {% if title %}
                {{ title }}
                {% else %}
                CostHive
                {% endif %}
            </span>
        </a>
        <ul class="list-unstyled ps-0">
            <li class="mb-1">
                <button class="btn btn-toggle align-items-center rounded collapsed" data-bs-toggle="collapse"
                    data-bs-target="#home-collapse" aria-expanded="true">
                    Home (WIP)
                </button>
                <div class="collapse show" id="home-collapse">
                    <ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small">
                        <li><a href="{{ url_for('establishment.list.show_establishments') }}"
                                class="link-dark rounded">Einrichtungen</a></li>
                        <li><a href="{{ url_for('item.list.show_items') }}" class="link-dark rounded">Inventar</a></li>
                    </ul>
                </div>
            </li>
            {% if current_user.is_authenticated %}
            <li class="mb-1">
                <button class="btn btn-toggle align-items-center rounded collapsed" data-bs-toggle="collapse"
                    data-bs-target="#dashboard-collapse" aria-expanded="false">
                    Übersicht
                </button>
                <div class="collapse" id="dashboard-collapse">
                    <ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small">
                        {% if current_user_establishments %}
                        {% for establishment in current_user_establishments %}
                        <li>
                            <a href="{{ url_for('establishment.overview.get_report_from_user', establishment_id=establishment.id) }}"
                                class="link-dark rounded">{{ establishment.name }}</a>
                        </li>
                        {% endfor %}
                        {% endif %}
                        <li>
                            <a href="{{ url_for('establishment.new.create_new_establishment') }}"
                                class="link-dark rounded">➕ Neu</a>
                        </li>
                    </ul>
                </div>
            </li>
            {% endif %}
            <li class="border-top border-dark my-3"></li>
            <li class="mb-1">
                <button class="btn btn-toggle align-items-center rounded collapsed" data-bs-toggle="collapse"
                    data-bs-target="#account-collapse" aria-expanded="false">
                    Account
                </button>
                <div class="collapse" id="account-collapse" style="">
                    <ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small">
                        <!-- <li><a href="#" class="link-dark rounded">New...</a></li>
                                <li><a href="#" class="link-dark rounded">Settings</a></li> -->
                        {% if current_user.is_authenticated %}
                        <!-- <li><a href="#" class="link-dark rounded">Profile</a></li> -->
                        <li><a href={{ url_for('auth.web_logout') }} class="link-dark rounded">Sign out</a></li>
                        {% else %}
                        <li><a href={{ url_for('auth.web_register') }} class="link-dark rounded">Register</a></li>
                        <li><a href={{ url_for('auth.web_login') }} class="link-dark rounded">Sign in</a></li>
                        {% endif %}
                    </ul>
                </div>
            </li>
        </ul>
    </div>
    {% endblock %}

    {% block content %}
    {% with messages = get_flashed_messages() %}
    {% if messages %}
    <ul>
        {% for message in messages %}
        <li>{{ message }}</li>
        {% endfor %}
    </ul>
    {% endif %}
    {% endwith %}
    <div style="width: 280px;"></div>
    <div class="container">
        <div class="row my-3"></div>
        <div class="row-md-3">
            {% block app_content %}{% endblock %}
        </div>
        <div class="row my-3"></div>
    </div>
</main>
{% endblock %}

{% block scripts %}
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
    integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
    crossorigin="anonymous"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
{% endblock %}