{% load static %}
{% load compress %}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <meta content="chrome=1" http-equiv="X-UA-Compatible">
    <title>{% block head_title %}{% endblock %} Dashboard | Port Townsend Roasting Co.</title>

    <link rel="apple-touch-icon" sizes="180x180" href="{% static 'images/apple-touch-icon.png' %}">
    <link rel="icon" type="image/png" sizes="32x32" href="{% static 'images/favicon-32x32.png' %}">
    <link rel="icon" type="image/png" sizes="16x16" href="{% static 'images/favicon-16x16.png' %}">
    <link rel="manifest" href="{% static 'images/site.webmanifest' %}">

    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@100;400;700&display=swap" rel="stylesheet">

    {% compress css %}
    <link rel="stylesheet" type="text/css" href="{% static "styles/dashboard.css" %}">
    {% endcompress %}

    <script type="module" defer src="{% static 'scripts/initializers/timezone.js' %}"></script>
    <script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
    <script type="module" src="{% static 'scripts/sorting.js' %}" defer></script>

    {% block head %}
    {% endblock %}
</head>
<body>
<div class="dashboard-main">
    <aside class="dashboard-sidebar">
        <nav class="dashboard-nav">
            <a href="{% url 'dashboard:home' %}">
                <img src="{% static 'images/store.png' %}">
                Home
            </a>
            <a href="{% url 'dashboard:catalog' %}">
                <img src="{% static 'images/cubes.png' %}">
                Catalog
            </a>
            <a href="{% url 'dashboard:stock' %}">
                <img src="{% static 'images/warehouse.png' %}">
                Stock
            </a>
            <a href="{% url 'dashboard:order-list' %}">
                <img src="{% static 'images/box.png' %}">
                Orders
            </a>
            <a href="{% url 'dashboard:customer-list' %}">
                <img src="{% static 'images/customer.png' %}">
                Customers
            </a>
            <a href="{% url 'dashboard:coupon-list' %}">
                <img src="{% static 'images/coupon.png' %}">
                Coupons
            </a>
            <a href="{% url 'dashboard:config' %}">
                <img src="{% static 'images/gear.png' %}">
                Config
            </a>
        </nav>
        <div class="dashboard-user">
            <a href="{% url 'storefront:product-list' %}">Storefront</a>
        {% if user.is_authenticated %}
            <a href="account">{{ user.get_full_name }}</a>
            <a href="{% url 'account_logout' %}">Log Out</a>
        {% else %}
            <p>You are not logged in</p>
            <a href="{% url 'account_login' %}">Log In</a> |
            <a href="{% url 'account_signup' %}">Sign Up</a>
        {% endif %}
        </div>
    </aside>
    <main>
    {% block content %}
    {% endblock content %}
    </main>
</div>
{% if messages %}
<div class="messages">
{% for message in messages %}
    <div class="messages-message {% if message.tags %}{{ message.tags }}{% endif %}">{{ message }} <span class="message-dissmiss">&times;</span></div>
{% endfor %}
</div>
{% endif %}

{% url 'dashboard:update-sorting' as sorting_url %}
{{ sorting_url|json_script:"sorting-url" }}

<script>
    document.addEventListener('DOMContentLoaded', () => {
        document.querySelectorAll('.message-dissmiss').forEach(dissmissEl => {
            setTimeout(() => {
                dissmissEl.parentElement.style.display = 'none'
            }, 5000)
            dissmissEl.addEventListener('click', event => {
                event.target.parentElement.style.display = 'none'
            })
        })
    })
</script>
</body>
</html>
