{% extends 'base.html' %}
{% load static %}

{% block title %}{{ mp.name }} | {{ project_name }}{% endblock %}

{% block content %}
<div class="container py-5">
    <div class="row mb-5">
        <div class="col-lg-12">
            <nav aria-label="breadcrumb">
              <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="{% url 'home' %}" class="text-muted">Home</a></li>
                <li class="breadcrumb-item"><a href="{% url 'mp_list' %}" class="text-muted">MPs</a></li>
                <li class="breadcrumb-item active" aria-current="page">{{ mp.name }}</li>
              </ol>
            </nav>
        </div>
    </div>

    <div class="row g-4">
        <!-- MP Profile Card -->
        <div class="col-lg-4">
            <div class="card bg-card border-0 rounded-4 p-4 sticky-top" style="top: 2rem;">
                <div class="text-center mb-4">
                    <div class="avatar-large mx-auto mb-3">{{ mp.name|slice:":1" }}</div>
                    <h1 class="h3 fw-bold mb-1">{{ mp.name }}</h1>
                    <div class="badge bg-dark px-3 py-2 rounded-pill mb-3">{{ mp.party }}</div>
                </div>
                
                <hr class="border-secondary opacity-25">
                
                <div class="mb-3">
                    <label class="small text-muted d-block mb-1">Constituency</label>
                    <div class="fw-bold">{{ mp.constituency }}</div>
                </div>
                <div class="mb-3">
                    <label class="small text-muted d-block mb-1">Province</label>
                    <div class="fw-bold">{{ mp.province }}</div>
                </div>
                <div class="mb-4">
                    <label class="small text-muted d-block mb-1">Total Disclosures</label>
                    <div class="fw-bold h4 text-success">{{ trades.count }}</div>
                </div>
                
                <button class="btn {% if is_followed %}btn-success{% else %}btn-primary-custom{% endif %} w-100 rounded-3 fw-bold py-3 mb-2 follow-btn" 
                        data-mp-id="{{ mp.id }}">
                    {% if is_followed %}Following{% else %}Follow {{ mp.name }}{% endif %}
                </button>
                <p class="small text-muted text-center mb-0">Get notified of new disclosures</p>
            </div>
        </div>

        <!-- Trade History -->
        <div class="col-lg-8">
            <div class="card bg-card border-0 rounded-4 p-4">
                <h3 class="h5 mb-4">Disclosure History</h3>
                
                <div class="table-responsive">
                    <table class="table table-dark table-hover align-middle custom-table">
                        <thead>
                            <tr>
                                <th class="text-muted fw-normal">Ticker</th>
                                <th class="text-muted fw-normal">Type</th>
                                <th class="text-muted fw-normal">Amount</th>
                                <th class="text-muted fw-normal">Date</th>
                                <th class="text-end"></th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for trade in trades %}
                            <tr>
                                <td>
                                    <a href="{% url 'ticker_detail' trade.ticker %}" class="text-decoration-none text-white">
                                        <div class="fw-bold">{{ trade.ticker }}</div>
                                        <div class="small text-muted">{{ trade.company_name }}</div>
                                    </a>
                                </td>
                                <td>
                                    {% if trade.trade_type == 'BUY' %}
                                        <span class="badge bg-success-subtle text-success border border-success px-3 py-2">BUY</span>
                                    {% else %}
                                        <span class="badge bg-danger-subtle text-danger border border-danger px-3 py-2">SELL</span>
                                    {% endif %}
                                </td>
                                <td>{{ trade.amount_range }}</td>
                                <td>{{ trade.disclosure_date|date:"M d, Y" }}</td>
                                <td class="text-end">
                                    <a href="#" class="btn btn-dark btn-sm rounded-circle"><i class="bi bi-info-circle"></i></a>
                                </td>
                            </tr>
                            {% empty %}
                            <tr>
                                <td colspan="5" class="text-center py-5 text-muted">No disclosures reported for this MP.</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .bg-card {
        background-color: var(--card-bg) !important;
    }
    .bg-primary-custom {
        background-color: var(--accent-green) !important;
        color: #000;
        border: none;
    }
    .avatar-large {
        width: 100px;
        height: 100px;
        background-color: var(--border-color);
        color: var(--accent-green);
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 50%;
        font-weight: 700;
        font-size: 2.5rem;
        font-family: 'Lexend', sans-serif;
    }
    .custom-table tr {
        background-color: rgba(255, 255, 255, 0.02);
    }
    .custom-table td {
        padding: 1.25rem 1rem;
    }
    .breadcrumb-item + .breadcrumb-item::before {
        color: #6c757d;
    }
</style>
{% endblock %}