{% extends "base.html" %}

{% block title %}Maintenance Report{% endblock %}

{% block content %}

<div class="container-fluid">

    <!-- HEADER -->
    <div class="mb-4">
        <h4><i class="bi bi-tools"></i> Maintenance & Cost Analysis</h4>
    </div>

    <!-- KPI SUMMARY -->
    <div class="row g-3 mb-4">

        <div class="col-md-3">
            <div class="card shadow-sm">
                <div class="card-body">
                    <h6>Total Complaints</h6>
                    <h4>{{ summary.total_complaints|default_if_none:0 }}</h4>
                </div>
            </div>
        </div>

        <div class="col-md-3">
            <div class="card shadow-sm">
                <div class="card-body">
                    <h6>Total Repairs</h6>
                    <h4>{{ summary.total_repairs|default_if_none:0 }}</h4>
                </div>
            </div>
        </div>

        <div class="col-md-3">
            <div class="card shadow-sm">
                <div class="card-body">
                    <h6>Avg Resolution Time</h6>
                    <h4>{{ summary.avg_resolution_time|default_if_none:0 }} days</h4>
                </div>
            </div>
        </div>

    </div>

    <!-- STATUS BREAKDOWN -->
    <div class="card shadow-sm mb-4">
        <div class="card-body">
            <h6>Status Breakdown</h6>

            <table class="table table-bordered">
                <thead>
                    <tr>
                        <th>Pending</th>
                        <th>In Progress</th>
                        <th>Completed</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>{{ summary.pending|default_if_none:0 }}</td>
                        <td>{{ summary.in_progress|default_if_none:0 }}</td>
                        <td>{{ summary.completed|default_if_none:0 }}</td>
                    </tr>
                </tbody>
            </table>

        </div>
    </div>

    <!-- COST ANALYSIS -->
    <div class="card shadow-sm mb-4">
        <div class="card-body">
            <h6>Maintenance Cost Analysis</h6>

            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>Category</th>
                        <th>Total Cost</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in loss.cost_breakdown %}
                    <tr>
                        <td>{{ item.category|default:"Other" }}</td>
                        <td>KES {{ item.total|default_if_none:0 }}</td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="2" class="text-center text-muted">No cost data available</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>

        </div>
    </div>

    <!-- LOSS IMPACT -->
    <div class="card shadow-sm">
        <div class="card-body">
            <h6>Loss Impact</h6>

            <ul class="list-group">
                <li class="list-group-item">
                    Vacancy Loss: KES {{ loss.vacancy_loss|default_if_none:0 }}
                </li>
                <li class="list-group-item">
                    Repair Delays Loss: KES {{ loss.delay_loss|default_if_none:0 }}
                </li>
                <li class="list-group-item">
                    Total Loss Impact: <strong>KES {{ loss.total_loss|default_if_none:0 }}</strong>
                </li>
            </ul>

        </div>
    </div>

</div>

{% endblock %}