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

{% block title %}Alpha 触发器 - AgomTradePro{% endblock %}

{% block extra_css %}
<link rel="stylesheet" href="{% static 'css/alpha-triggers.css' %}">
{% endblock %}

{% block content %}
<div class="alpha-trigger-container">
    <!-- 头部 -->
    <div class="alpha-trigger-header">
        <div>
            <h1>⚡ Alpha 触发器</h1>
            <p>离散、可证伪、可行动的 Alpha 信号触发机制</p>
        </div>
        <a href="{% url 'alpha_trigger:create' %}" class="btn btn-primary">
            <i class="bi bi-plus-lg"></i> 创建触发器
        </a>
    </div>

    <!-- 投资免责声明 -->
    {% include 'components/investment_disclaimer.html' %}

    {% if error %}
    <div class="alert alert-error">
        <i class="bi bi-exclamation-triangle"></i> {{ error }}
    </div>
    {% endif %}

    <!-- 统计卡片 -->
    <div class="stats-grid">
        <div class="stat-card watch">
            <div class="stat-value">{{ candidate_stats.watch_count|default:0 }}</div>
            <div class="stat-label">👀 观察中</div>
        </div>
        <div class="stat-card candidate">
            <div class="stat-value">{{ candidate_stats.candidate_count|default:0 }}</div>
            <div class="stat-label">📋 候选</div>
        </div>
        <div class="stat-card actionable">
            <div class="stat-value">{{ candidate_stats.actionable_count|default:0 }}</div>
            <div class="stat-label">✅ 可行动</div>
        </div>
        <div class="stat-card triggered">
            <div class="stat-value">{{ candidate_stats.triggered_count|default:0 }}</div>
            <div class="stat-label">⚡ 已触发</div>
        </div>
    </div>

    <!-- 面板网格 -->
    <div class="panel-grid">
        <!-- 观察中 -->
        <div class="panel-card">
            <div class="panel-header">
                <div class="panel-title">观察中</div>
                <div class="panel-count watch">{{ watch_list|length }}</div>
            </div>
            <div class="panel-body">
                {% if watch_list %}
                <table class="trigger-table">
                    <thead>
                        <tr>
                            <th>代码</th>
                            <th>名称</th>
                            <th>强度</th>
                            <th>方向</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for trigger in watch_list %}
                        <tr class="trigger-row">
                            <td>{{ trigger.asset_code }}</td>
                            <td>{{ trigger.asset_name|default:"-" }}</td>
                            <td>
                                <span class="strength-badge strength-{{ trigger.strength }}">
                                    {{ trigger.get_strength_display }}
                                </span>
                            </td>
                            <td>
                                <span class="direction-badge direction-{{ trigger.direction|lower }}">
                                    {{ trigger.get_direction_display }}
                                </span>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
                {% else %}
                <div class="empty-state">
                    <div class="empty-icon">👀</div>
                    <p>暂无观察中的触发器</p>
                </div>
                {% endif %}
            </div>
        </div>

        <!-- 候选 -->
        <div class="panel-card">
            <div class="panel-header">
                <div class="panel-title">候选</div>
                <div class="panel-count candidate">{{ candidate_list|length }}</div>
            </div>
            <div class="panel-body">
                {% if candidate_list %}
                <table class="trigger-table">
                    <thead>
                        <tr>
                            <th>代码</th>
                            <th>名称</th>
                            <th>强度</th>
                            <th>方向</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for trigger in candidate_list %}
                        <tr class="trigger-row">
                            <td>
                                <a href="{% url 'alpha_trigger:detail' trigger.trigger_id %}" class="trigger-link">
                                    {{ trigger.asset_code }}
                                </a>
                            </td>
                            <td>{{ trigger.asset_name|default:"-" }}</td>
                            <td>
                                <span class="strength-badge strength-{{ trigger.strength }}">
                                    {{ trigger.get_strength_display }}
                                </span>
                            </td>
                            <td>
                                <span class="direction-badge direction-{{ trigger.direction|lower }}">
                                    {{ trigger.get_direction_display }}
                                </span>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
                {% else %}
                <div class="empty-state">
                    <div class="empty-icon">📋</div>
                    <p>暂无候选触发器</p>
                </div>
                {% endif %}
            </div>
        </div>

        <!-- 可行动 -->
        <div class="panel-card">
            <div class="panel-header">
                <div class="panel-title">可行动</div>
                <div class="panel-count actionable">{{ actionable_list|length }}</div>
            </div>
            <div class="panel-body">
                {% if actionable_list %}
                <table class="trigger-table">
                    <thead>
                        <tr>
                            <th>代码</th>
                            <th>名称</th>
                            <th>强度</th>
                            <th>方向</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for trigger in actionable_list %}
                        <tr class="trigger-row">
                            <td>
                                <a href="{% url 'alpha_trigger:candidate_detail' trigger.candidate_id %}" class="trigger-link">
                                    {{ trigger.asset_code }}
                                </a>
                            </td>
                            <td>{{ trigger.asset_name|default:"-" }}</td>
                            <td>
                                <span class="strength-badge strength-{{ trigger.strength }}">
                                    {{ trigger.get_strength_display }}
                                </span>
                            </td>
                            <td>
                                <span class="direction-badge direction-{{ trigger.direction|lower }}">
                                    {{ trigger.get_direction_display }}
                                </span>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
                {% else %}
                <div class="empty-state">
                    <div class="empty-icon">✅</div>
                    <p>暂无可行动的触发器</p>
                </div>
                {% endif %}
            </div>
        </div>

        <!-- 已触发 -->
        <div class="panel-card">
            <div class="panel-header">
                <div class="panel-title">已触发</div>
                <div class="panel-count triggered">{{ triggered_list|length }}</div>
            </div>
            <div class="panel-body">
                {% if triggered_list %}
                <table class="trigger-table">
                    <thead>
                        <tr>
                            <th>代码</th>
                            <th>触发时间</th>
                            <th>强度</th>
                            <th>方向</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for trigger in triggered_list %}
                        <tr class="trigger-row">
                            <td>{{ trigger.asset_code }}</td>
                            <td>{{ trigger.triggered_at|date:"Y-m-d H:i" }}</td>
                            <td>
                                <span class="strength-badge strength-{{ trigger.strength }}">
                                    {{ trigger.get_strength_display }}
                                </span>
                            </td>
                            <td>
                                <span class="direction-badge direction-{{ trigger.direction|lower }}">
                                    {{ trigger.get_direction_display }}
                                </span>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
                {% else %}
                <div class="empty-state">
                    <div class="empty-icon">⚡</div>
                    <p>暂无已触发的信号</p>
                </div>
                {% endif %}
            </div>
        </div>
    </div>

    <!-- 快速操作 -->
    <div class="card">
        <div class="card-header">
            <h3 class="card-header-title">快速操作</h3>
        </div>
        <div class="card-body">
            <div class="d-flex gap-3">
                <a href="{% url 'alpha_trigger:performance' %}" class="btn btn-secondary">
                    <i class="bi bi-graph-up"></i> Alpha 表现
                </a>
                <a href="{% url 'alpha_trigger:invalidation_builder' %}" class="btn btn-secondary">
                    <i class="bi bi-sliders"></i> 证伪规则构建器
                </a>
                <a href="{% url 'alpha_trigger:create' %}" class="btn btn-primary">
                    <i class="bi bi-plus-lg"></i> 创建新触发器
                </a>
            </div>
        </div>
    </div>
</div>

{% endblock %}
