{% extends 'base.html' %}

{% block title %}Документ перемещения {{ transfer_document.document_number }}{% endblock %}

{% block content %}
<div class="container-fluid px-4 py-3">
    <!-- Breadcrumbs -->
    <nav aria-label="breadcrumb" class="mb-2">
        <ol class="breadcrumb breadcrumb-sm mb-0">
            <li class="breadcrumb-item"><a href="{% url 'inventory:transfer-list' %}">Перемещения</a></li>
            <li class="breadcrumb-item active">{{ transfer_document.document_number }}</li>
        </ol>
    </nav>

    <div class="row g-3">
        <!-- Основная информация о документе -->
        <div class="col-lg-8">
            <div class="card border-0 shadow-sm mb-3">
                <div class="card-header bg-light py-3">
                    <h5 class="mb-0">
                        <i class="bi bi-arrow-left-right me-2"></i>{{ transfer_document.document_number }}
                    </h5>
                </div>
                <div class="card-body">
                    <div class="row mb-3">
                        <div class="col-md-6">
                            <p class="text-muted small mb-1">Склад-отгрузки</p>
                            <p class="fw-semibold">{{ transfer_document.from_warehouse.name }}</p>
                        </div>
                        <div class="col-md-6">
                            <p class="text-muted small mb-1">Склад-приемки</p>
                            <p class="fw-semibold">{{ transfer_document.to_warehouse.name }}</p>
                        </div>
                    </div>

                    {% if transfer_document.notes %}
                    <div class="mb-3">
                        <p class="text-muted small mb-1">Примечания</p>
                        <p>{{ transfer_document.notes }}</p>
                    </div>
                    {% endif %}

                    <div class="row">
                        <div class="col-md-6">
                            <p class="text-muted small mb-1">Дата создания</p>
                            <p class="fw-semibold">{{ transfer_document.created_at|date:"d.m.Y H:i" }}</p>
                        </div>
                        <div class="col-md-6">
                            <p class="text-muted small mb-1">Последнее обновление</p>
                            <p class="fw-semibold">{{ transfer_document.updated_at|date:"d.m.Y H:i" }}</p>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Таблица товаров -->
            <div class="card border-0 shadow-sm">
                <div class="card-header bg-light py-3">
                    <h6 class="mb-0"><i class="bi bi-table me-2"></i>Товары в документе</h6>
                </div>
                <div class="card-body p-0">
                    <div class="table-responsive">
                        <table class="table table-sm table-hover mb-0">
                            <thead>
                                <tr class="border-bottom">
                                    <th scope="col" class="px-3 py-2">Товар</th>
                                    <th scope="col" class="px-3 py-2" style="text-align: right;">Количество</th>
                                    <th scope="col" class="px-3 py-2" style="text-align: right;">Цена партии</th>
                                    <th scope="col" class="px-3 py-2">Исходная партия</th>
                                    <th scope="col" class="px-3 py-2">Новая партия</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for item in items %}
                                <tr>
                                    <td class="px-3 py-2">
                                        <a href="{% url 'products:product-detail' item.product.id %}">{{
                                            item.product.name }}</a>
                                    </td>
                                    <td class="px-3 py-2" style="text-align: right;">{{ item.quantity }}</td>
                                    <td class="px-3 py-2" style="text-align: right;">{{ item.batch.cost_price }} ₽/ед.
                                    </td>
                                    <td class="px-3 py-2">
                                        <span class="badge bg-secondary">{{ item.batch.id }}</span>
                                    </td>
                                    <td class="px-3 py-2">
                                        {% if item.new_batch %}
                                        <span class="badge bg-success">{{ item.new_batch.id }}</span>
                                        {% else %}
                                        <span class="text-muted small">—</span>
                                        {% endif %}
                                    </td>
                                </tr>
                                {% empty %}
                                <tr>
                                    <td colspan="5" class="px-3 py-2 text-muted text-center">
                                        Товаров не найдено
                                    </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>

        <!-- Сводка справа -->
        <div class="col-lg-4">
            <!-- Статистика -->
            <div class="card border-0 shadow-sm mb-3">
                <div class="card-body">
                    <h6 class="text-muted mb-3"><i class="bi bi-info-circle me-1"></i>Статистика</h6>

                    <div class="mb-3 p-2 rounded" style="background: #f8f9fa;">
                        <div class="d-flex justify-content-between align-items-center mb-2">
                            <span class="text-muted small">Позиций:</span>
                            <span class="fw-semibold">{{ total_items }}</span>
                        </div>
                        <div class="d-flex justify-content-between align-items-center">
                            <span class="text-muted small">Всего товара:</span>
                            <span class="fw-semibold">{{ total_qty }} шт</span>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Действия -->
            <div class="card border-0 shadow-sm">
                <div class="card-body">
                    <h6 class="text-muted mb-3"><i class="bi bi-gear me-1"></i>Действия</h6>

                    <div class="d-grid gap-2">
                        <a href="{% url 'inventory:transfer-list' %}" class="btn btn-outline-secondary btn-sm">
                            <i class="bi bi-arrow-left me-1"></i>Вернуться к списку
                        </a>
                        <!--
                        <a href="{% url 'inventory:transfer-delete' transfer_document.id %}" class="btn btn-outline-danger btn-sm">
                            <i class="bi bi-trash me-1"></i>Удалить
                        </a>
                        -->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<style>
    .breadcrumb-sm {
        font-size: 0.875rem;
        padding: 0.5rem 0;
    }

    .table-hover tbody tr:hover {
        background-color: #f8f9fa;
    }
</style>
{% endblock %}