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

{% block title %}跨模态诊疗室 - 紫睛灵{% endblock %}

{% block content %}
<div class="container-fluid py-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h3 class="fw-bold mb-0 text-success"><i class="bi bi-shield-plus me-2"></i>跨模态诊疗室</h3>
        <span class="text-muted">视觉特征与环境温湿度联合推演</span>
    </div>

    <div class="row g-4">
        <div class="col-md-5">
            <div class="card border-0 shadow-sm rounded-4 h-100">
                <div class="card-header bg-white border-bottom-0 pt-4 pb-0">
                    <h5 class="fw-bold"><i class="bi bi-cloud-upload text-primary me-2"></i>数据采集</h5>
                </div>
                <div class="card-body">
                    <form method="POST" enctype="multipart/form-data" action="{% url 'cross_modal_hub' %}">
                        {% csrf_token %}
                        
                        <div class="mb-4">
                            <label class="form-label fw-bold">1. 采集作物局部图像</label>
                            <input class="form-control" type="file" name="image" accept="image/*" required>
                            <div class="form-text">请上传包含病斑特征的高清叶片或果实照片。</div>
                        </div>

                        <div class="mb-4">
                            <label class="form-label fw-bold">2. 当前环境参数输入</label>
                            <div class="row g-3">
                                <div class="col-6">
                                    <div class="input-group">
                                        <span class="input-group-text bg-light"><i class="bi bi-thermometer-half text-danger"></i></span>
                                        <input type="number" step="0.1" class="form-control" name="temperature" placeholder="温度" value="25.0" required>
                                        <span class="input-group-text">°C</span>
                                    </div>
                                </div>
                                <div class="col-6">
                                    <div class="input-group">
                                        <span class="input-group-text bg-light"><i class="bi bi-droplet text-info"></i></span>
                                        <input type="number" step="1" class="form-control" name="humidity" placeholder="湿度" value="80" required>
                                        <span class="input-group-text">%</span>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <button type="submit" class="btn btn-success w-100 rounded-pill py-2 shadow-sm">
                            <i class="bi bi-cpu me-2"></i>开始联合诊断
                        </button>
                    </form>
                </div>
            </div>
        </div>

        <div class="col-md-7">
            <div class="card border-0 shadow-sm rounded-4 h-100 bg-light">
                <div class="card-body p-4 d-flex flex-column justify-content-center">
                    {% if result %}
                        <h4 class="fw-bold mb-4 border-bottom pb-3">紫睛灵-联合诊断报告</h4>
                        
                        <div class="row mb-4">
                            <div class="col-md-6">
                                <p class="text-muted mb-1">视觉特征识别结果</p>
                                <h5 class="fw-bold text-dark">{{ result.disease_name }} <span class="badge bg-secondary ms-2">置信度: {{ result.confidence }}%</span></h5>
                            </div>
                            <div class="col-md-6">
                                <p class="text-muted mb-1">48小时演进风险 (融合环境要素)</p>
                                <div class="d-flex align-items-center">
                                    <h5 class="fw-bold {{ result.risk_style }} mb-0 me-3">
                                        {{ result.risk_level }}
                                    </h5>

                                    <div class="progress flex-grow-1" style="height: 10px;">
                                        <div class="progress-bar {{ result.risk_style|cut:'text-'|add:'bg-'|default:'bg-danger' }}"
                                             role="progressbar"
                                             style="width: {{ result.spread_probability }}%"
                                             aria-valuenow="{{ result.spread_probability }}"
                                             aria-valuemin="0"
                                             aria-valuemax="100">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="alert border-0 shadow-sm mt-2" style="background-color: #f0fdf4; border-radius: 12px;">
                            <h6 class="fw-bold text-success mb-3">
                                <i class="bi bi-robot me-2"></i>AI 专家动态处方
                                <span class="badge bg-success bg-opacity-75 ms-2 rounded-pill fw-normal" style="font-size: 0.75rem;">LLM 知识增强</span>
                            </h6>
                            <hr class="text-success opacity-25">
                            <div class="text-dark" style="line-height: 1.8; font-size: 0.95rem;">
                                {{ result.llm_remedy|linebreaksbr }}
                            </div>
                        </div>
                    {% else %}
                        <div class="text-center text-muted py-5">
                            <i class="bi bi-clipboard2-pulse display-1 mb-3 text-secondary" style="opacity: 0.2;"></i>
                            <h5>等待数据输入</h5>
                            <p>请在左侧上传图像并输入环境参数，系统将自动生成48小时病程演进推演及智能处方。</p>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}