{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}RMS{% endblock %}</title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css" rel="stylesheet">
    <link rel="stylesheet" href="{% static 'css/style.css' %}">
</head>

<body>

<div class="d-flex">

    {% if user.is_authenticated %}
    <!-- ================= SIDEBAR ================= -->
    <div class="bg-dark text-white p-3 d-none d-md-block"
         style="width: 260px; min-height: 100vh; position: fixed; left: 0; top: 0;">

        <h5 class="mb-4 fw-bold">
            <i class="bi bi-buildings"></i> RMS Panel
        </h5>

        <ul class="nav flex-column gap-2">

            <!-- DASHBOARD -->
            <li class="nav-item">
                {% if user.role == 'landlord' %}
                    <a href="{% url 'landlord_dashboard' %}" class="nav-link text-white">
                {% elif user.role == 'caretaker' %}
                    <a href="{% url 'caretaker_dashboard' %}" class="nav-link text-white">
                {% elif user.role == 'tenant' %}
                    <a href="{% url 'tenant_dashboard' %}" class="nav-link text-white">
                {% endif %}
                    <i class="bi bi-speedometer2"></i> Dashboard
                </a>
            </li>

            <!-- ================= LANDLORD ================= -->
            {% if user.role == 'landlord' %}

                <li class="nav-item"><a href="{% url 'building_list' %}" class="nav-link text-white"><i class="bi bi-building"></i> Buildings</a></li>
                <li class="nav-item"><a href="{% url 'unit_list' %}" class="nav-link text-white"><i class="bi bi-door-closed"></i> Units</a></li>
                <li class="nav-item"><a href="{% url 'tenant_list' %}" class="nav-link text-white"><i class="bi bi-people"></i> Tenants</a></li>
                <li class="nav-item"><a href="{% url 'caretaker_list' %}" class="nav-link text-white"><i class="bi bi-person-badge"></i> Caretakers</a></li>
                <li class="nav-item"><a href="{% url 'inspection_history' %}" class="nav-link text-white"><i class="bi bi-clipboard-check"></i> Inspections</a></li>
                <li class="nav-item"><a href="{% url 'expense_list' %}" class="nav-link text-white"><i class="bi bi-receipt"></i> Expenses</a></li>

                <!-- REPORTS -->
                {% with request.path|slice:":8" as path_prefix %}
                <li class="nav-item">
                    <a class="nav-link text-white d-flex justify-content-between align-items-center"
                       data-bs-toggle="collapse"
                       href="#reportsMenu">
                        <span><i class="bi bi-bar-chart"></i> Reports</span>
                        <i class="bi bi-chevron-down small"></i>
                    </a>

                    <div class="collapse {% if path_prefix == '/reports' %}show{% endif %}" id="reportsMenu">
                        <ul class="nav flex-column ms-3 mt-2">
                            <li><a href="{% url 'reports_dashboard' %}" class="nav-link text-white">Dashboard</a></li>
                            <li><a href="{% url 'financial_report' %}" class="nav-link text-white">Financial</a></li>
                            <li><a href="{% url 'unit_report' %}" class="nav-link text-white">Units</a></li>
                            <li><a href="{% url 'tenant_report' %}" class="nav-link text-white">Tenants</a></li>
                            <li><a href="{% url 'maintenance_report' %}" class="nav-link text-white">Maintenance</a></li>
                            <li><a href="{% url 'tax_report' %}" class="nav-link text-white">Tax</a></li>
                        </ul>
                    </div>
                </li>
                {% endwith %}

                <li class="nav-item"><a href="{% url 'landlord_finance' %}" class="nav-link text-white"><i class="bi bi-cash-stack"></i> Financials</a></li>
                <li class="nav-item"><a href="{% url 'notifications' %}" class="nav-link text-white"><i class="bi bi-bell"></i> Notifications</a></li>
                <li class="nav-item"><a href="{% url 'send_announcement' %}" class="nav-link text-white"><i class="bi bi-megaphone"></i> Announcements</a></li>

            {% endif %}

            <!-- ================= CARETAKER ================= -->
            {% if user.role == 'caretaker' %}

                <li class="nav-item"><a href="{% url 'building_list' %}" class="nav-link text-white"><i class="bi bi-building"></i> Buildings</a></li>
                <li class="nav-item"><a href="{% url 'unit_list' %}" class="nav-link text-white"><i class="bi bi-door-closed"></i> Units</a></li>
                <li class="nav-item"><a href="{% url 'tenant_list' %}" class="nav-link text-white"><i class="bi bi-people"></i> Tenants</a></li>
                <li class="nav-item"><a href="{% url 'inspection_history' %}" class="nav-link text-white"><i class="bi bi-clipboard-check"></i> Inspections</a></li>
                <li class="nav-item"><a href="{% url 'expense_list' %}" class="nav-link text-white"><i class="bi bi-receipt"></i> Expenses</a></li>

                <li class="nav-item"><a href="{% url 'complaint_list' %}" class="nav-link text-white"><i class="bi bi-chat-left-text"></i> Complaints</a></li>
                <li class="nav-item"><a href="{% url 'repair_list' %}" class="nav-link text-white"><i class="bi bi-tools"></i> Repairs</a></li>

                <li class="nav-item"><a href="{% url 'notifications' %}" class="nav-link text-white"><i class="bi bi-bell"></i> Notifications</a></li>
                <li class="nav-item"><a href="{% url 'send_announcement' %}" class="nav-link text-white"><i class="bi bi-megaphone"></i> Announcements</a></li>

            {% endif %}

            <!-- ================= TENANT ================= -->
            {% if user.role == 'tenant' %}

                <li class="nav-item">
                    <a href="{% url 'tenant_finance' %}" class="nav-link text-white">
                        <i class="bi bi-wallet2"></i> Payments
                    </a>
                </li>

                <li class="nav-item">
                    <a href="{% url 'tenant_announcements' %}" class="nav-link text-white">
                        <i class="bi bi-megaphone"></i> Announcements
                    </a>
                </li>

                <li class="nav-item">
                    <a href="{% url 'notifications' %}" class="nav-link text-white">
                        <i class="bi bi-bell"></i> Notifications
                    </a>
                </li>

                <li class="nav-item">
                    <a href="{% url 'complaint' %}" class="nav-link text-white">
                        <i class="bi bi-chat-left-text"></i> Complaints
                    </a>
                </li>

                <li class="nav-item">
                    <a href="{% url 'repair_list' %}" class="nav-link text-white">
                        <i class="bi bi-tools"></i> Repairs
                    </a>
                </li>

                <li class="nav-item">
                    <a href="{% url 'inspection_history' %}" class="nav-link text-white">
                        <i class="bi bi-clock-history"></i> Inspection History
                    </a>
                </li>

                <li class="nav-item">
                    <a href="{% url 'tenant_vacate_self' %}" class="nav-link text-warning">
                        <i class="bi bi-box-arrow-right"></i> Vacate Unit
                    </a>
                </li>

            {% endif %}

            <!-- ================= PROFILE (ALL USERS) ================= -->
            <li class="nav-item mt-3">
                <a href="{% url 'profile' %}" class="nav-link text-white">
                    <i class="bi bi-person-circle"></i> Profile
                </a>
            </li>

            <!-- LOGOUT -->
            <li class="nav-item">
                <a href="{% url 'logout' %}" class="nav-link text-danger">
                    <i class="bi bi-box-arrow-right"></i> Logout
                </a>
            </li>

        </ul>
    </div>
    {% endif %}

    <!-- ================= MAIN CONTENT ================= -->
    <div class="flex-grow-1" style="margin-left: 260px;">

        <div class="page-container p-3">

            {% if messages %}
                {% for message in messages %}
                    <div class="alert alert-{{ message.tags }} alert-dismissible fade show shadow-sm">
                        {{ message }}
                        <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                    </div>
                {% endfor %}
            {% endif %}

            {% block content %}
            {% endblock %}

        </div>
    </div>

</div>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="{% static 'js/main.js' %}"></script>

</body>
</html>