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

{% block title %}{{ ticker }} | {{ 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 'ticker_list' %}" class="text-muted">Tickers</a></li>
                <li class="breadcrumb-item active" aria-current="page">{{ ticker }}</li>
              </ol>
            </nav>
        </div>
    </div>

    <div class="row g-4 mb-5">
        <div class="col-lg-8">
            <div class="d-flex align-items-center mb-4">
                <div class="ticker-logo me-4">{{ ticker|slice:":1" }}</div>
                <div>
                    <h1 class="display-6 fw-bold mb-0">{{ ticker }}</h1>
                    <p class="lead text-muted mb-0">{{ company_name }}</p>
                </div>
            </div>
        </div>
        <div class="col-lg-4 text-lg-end">
            <button class="btn {% if is_followed %}btn-success{% else %}btn-outline-success{% endif %} btn-lg rounded-pill px-4 follow-btn" 
                    data-ticker="{{ ticker }}">
                <i class="bi {% if is_followed %}bi-star-fill{% else %}bi-star{% endif %} me-2"></i>
                {% if is_followed %}Following Ticker{% else %}Watch Ticker{% endif %}
            </button>
        </div>
    </div>

    <div class="row g-4">
        <div class="col-lg-12">
            <div class="card bg-card border-0 rounded-4 p-4">
                <h3 class="h5 mb-4">MPs Trading {{ ticker }}</h3>
                
                <div class="table-responsive">
                    <table class="table table-dark table-hover align-middle custom-table">
                        <thead>
                            <tr>
                                <th class="text-muted fw-normal">Member of Parliament</th>
                                <th class="text-muted fw-normal">Action</th>
                                <th class="text-muted fw-normal">Amount</th>
                                <th class="text-muted fw-normal">Disclosure Date</th>
                                <th class="text-end"></th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for trade in trades %}
                            <tr>
                                <td>
                                    <a href="{% url 'mp_detail' trade.mp.pk %}" class="text-decoration-none text-white d-flex align-items-center">
                                        <div class="avatar-sm me-3">{{ trade.mp.name|slice:":1" }}</div>
                                        <div>
                                            <div class="fw-bold">{{ trade.mp.name }}</div>
                                            <div class="small text-muted">{{ trade.mp.party }}</div>
                                        </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="{% url 'mp_detail' trade.mp.pk %}" class="btn btn-dark btn-sm rounded-pill px-3">View Profile</a>
                                </td>
                            </tr>
                            {% empty %}
                            <tr>
                                <td colspan="5" class="text-center py-5 text-muted">No trades found for this ticker.</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .bg-card {
        background-color: var(--card-bg) !important;
    }
    .ticker-logo {
        width: 80px;
        height: 80px;
        background: linear-gradient(135deg, #2a2d34 0%, #1a1c21 100%);
        border: 1px solid var(--border-color);
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 20px;
        font-size: 2.5rem;
        font-weight: 800;
        color: var(--accent-green);
    }
    .avatar-sm {
        width: 32px;
        height: 32px;
        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: 0.8rem;
    }
    .custom-table tr {
        background-color: rgba(255, 255, 255, 0.02);
    }
    .custom-table td {
        padding: 1.25rem 1rem;
    }
</style>
{% endblock %}