{% 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-primary"><i class="bi bi-box-seam me-2"></i>采后品质与物流中枢</h3>
        <span class="text-muted">动力学货架期推演与经济价值评估</span>
    </div>

    <div class="row g-4">
        <div class="col-md-4">
            <div class="card border-0 shadow-sm rounded-4 h-100">
                <div class="card-body">
                    <form method="POST" enctype="multipart/form-data" action="{% url 'post_harvest_logistics' %}">
                        {% csrf_token %}
                        <div class="mb-4">
                            <label class="form-label fw-bold">果实品相采样图像</label>
                            <input class="form-control" type="file" name="image" accept="image/*" required>
                        </div>
                        <div class="mb-4">
                            <label class="form-label fw-bold">预估存储/运输温度 (°C)</label>
                            <input type="range" class="form-range" name="storage_temp" min="0" max="35" step="1" id="tempRange" value="15" oninput="document.getElementById('tempOutput').innerText = this.value + ' °C'">
                            <div class="text-center fw-bold text-primary fs-5" id="tempOutput">15 °C</div>
                        </div>
                        <button type="submit" class="btn btn-primary w-100 rounded-pill py-2 shadow-sm">
                            推演货架期
                        </button>
                    </form>
                </div>
            </div>
        </div>

        <div class="col-md-8">
            <div class="card border-0 shadow-sm rounded-4 h-100">
                <div class="card-body p-4">
                    {% if logistics_result %}
                        <h4 class="fw-bold mb-4">经济价值与物流建议</h4>
                        <div class="row text-center mb-4">
                            <div class="col-md-4">
                                <p class="text-muted mb-1">当前外观定级</p>
                                <h3 class="fw-bold">{{ logistics_result.grade }}</h3>
                            </div>
                            <div class="col-md-4 border-start border-end">
                                <p class="text-muted mb-1">目标环境温度</p>
                                <h3 class="fw-bold text-info">{{ logistics_result.target_temp }}°C</h3>
                            </div>
                            <div class="col-md-4">
                                <p class="text-muted mb-1">预计剩余货架期</p>
                                <h3 class="fw-bold text-warning">{{ logistics_result.shelf_life_hours }} <span class="fs-6">小时</span></h3>
                            </div>
                        </div>
                        
                        <div class="alert alert-primary border-0 shadow-sm">
                            <h6 class="fw-bold"><i class="bi bi-truck me-2"></i>物流调度决策建议</h6>
                            <p class="mb-0">{{ logistics_result.advice }}</p>
                        </div>
                    {% else %}
                        <div class="text-center text-muted py-5 mt-4">
                            <i class="bi bi-bar-chart-steps display-1 mb-3 text-secondary" style="opacity: 0.2;"></i>
                            <h5>经济价值损失预警模型</h5>
                            <p>结合外观特征与 Arrhenius 动力学模型，量化评估农产品流通价值。</p>
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}