{% extends 'unfold/layouts/skeleton.html' %}

{% load admin_list i18n unfold %}

{% block base %}
    <div id="page" class="flex max-w-full min-h-screen {% element_classes 'page' %}">
        {% if not is_popup and is_nav_sidebar_enabled %}
            {% block nav-sidebar %}
                {% include "admin/nav_sidebar.html" %}
            {% endblock %}
        {% endif %}

        <div id="main" class="bg-white flex flex-col grow min-w-0 dark:bg-base-900 {% element_classes 'main' %}">
            {% block header %}
                {% include "unfold/helpers/header.html" %}
            {% endblock %}

            {% block messages %}
                <div class="px-4">
                    <div class="{% if not cl.model_admin.list_fullwidth and is_fullwidth != "1" %}container{% endif %} mx-auto {% element_classes 'messages' %}">
                        {% include "unfold/helpers/messages.html" %}
                    </div>
                </div>
            {% endblock messages %}

            <div class="@container px-4 pb-4 grow">
                <div id="content" class="{% if not cl.model_admin.list_fullwidth and is_fullwidth != "1" %}container{% endif %} mx-auto {% block coltype %}colM{% endblock %} {% element_classes 'content' %}">
                    {% if cl %}
                        {% tab_list "changelist" cl.opts %}
                    {% elif opts %}
                        {% tab_list "changeform" opts %}
                    {% endif %}

                    {% block content %}
                        {% block object-tools %}{% endblock %}

                        {{ content }}
                    {% endblock %}

                    {% block sidebar %}{% endblock %}
                </div>
            </div>

            {% block footer %}{% endblock %}
        </div>
    </div>
{% endblock %}

{% block blockbots %}
    {{ block.super }}
    <script>
        (function() {
            if (typeof window.theme === 'function') {
                var originalTheme = window.theme;
                window.theme = function(defaultTheme) {
                    var themeData = originalTheme(defaultTheme);
                    
                    var getSidebarOpen = function() {
                        var sidebarOpenValue = localStorage.getItem("sidebarOpen");
                        if (sidebarOpenValue === null) {
                            return true;
                        }
                        return sidebarOpenValue !== "0";
                    };
                    
                    themeData.sidebarOpen = getSidebarOpen();
                    
                    themeData.sidebarToggle = function() {
                        this.sidebarOpen = !this.sidebarOpen;
                        localStorage.setItem("sidebarOpen", this.sidebarOpen ? "1" : "0");
                    };
                    
                    if (themeData.themeBindings && themeData.themeBindings["x-resize.window"]) {
                        themeData.themeBindings["x-resize.window"] = function() {
                            // Do nothing
                        };
                    }
                    
                    return themeData;
                };
            }
        })();
    </script>
{% endblock %}
