{% extends 'base.html' %}

{% block title %}调整库存 - {{ book.title }}{% endblock %}

{% block head %}
<link rel="stylesheet" href="{{ url_for('static', filename='css/inventory-adjust.css') }}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
{% endblock %}

{% block content %}
<div class="container mt-5">
    <div class="disney-inventory-card">
        <div class="disney-decoration top-left"></div>
        <div class="disney-decoration top-right"></div>
        <div class="disney-decoration bottom-left"></div>
        <div class="disney-decoration bottom-right"></div>

        <div class="card-header-disney">
            <div class="mickey-ears"></div>
            <h4>调整图书库存</h4>
        </div>

        <div class="card-body-disney">
            <div class="row mb-4">
                <div class="col-md-4 book-cover-container">
                    {% if book.cover_url %}
                    <img src="{{ book.cover_url }}" alt="{{ book.title }}" class="img-fluid book-cover">
                    {% else %}
                    <img src="{{ url_for('static', filename='images/book-placeholder.jpg') }}" alt="默认封面" class="img-fluid book-cover">
                    {% endif %}
                    <div class="disney-sparkles"></div>
                </div>
                <div class="col-md-8 book-details">
                    <h3 class="book-title">{{ book.title }}</h3>
                    <div class="book-info">
                        <p><span class="disney-icon author-icon"></span> <strong>作者:</strong> {{ book.author }}</p>
                        <p><span class="disney-icon publisher-icon"></span> <strong>出版社:</strong> {{ book.publisher }}</p>
                        <p><span class="disney-icon isbn-icon"></span> <strong>ISBN:</strong> {{ book.isbn }}</p>
                        <p><span class="disney-icon inventory-icon"></span> <strong>当前库存:</strong>
                            <span class="stock-badge {{ 'high-stock' if book.stock > 5 else 'low-stock' if book.stock > 0 else 'out-stock' }}">
                                {{ book.stock }}
                            </span>
                        </p>
                    </div>
                </div>
            </div>

            <div class="form-container">
                <form method="POST" action="{{ url_for('inventory.adjust_inventory', book_id=book.id) }}">
                    <div class="mb-4 form-group">
                        <label for="change_type" class="form-label disney-label">
                            <span class="disney-icon type-icon"></span> 调整类型
                        </label>
                        <select class="form-select disney-select" id="change_type" name="change_type" required>
                            <option value="in">入库（增加库存）</option>
                            <option value="out">出库（减少库存）</option>
                        </select>
                    </div>

                    <div class="mb-4 form-group">
                        <label for="change_amount" class="form-label disney-label">
                            <span class="disney-icon amount-icon"></span> 调整数量
                        </label>
                        <input type="number" class="form-control disney-input" id="change_amount" name="change_amount" min="1" value="1" required>
                        <div class="form-text stock-hint" id="stock-hint">当前库存: {{ book.stock }}</div>
                    </div>

                    <div class="mb-4 form-group">
                        <label for="remark" class="form-label disney-label">
                            <span class="disney-icon remark-icon"></span> 备注
                        </label>
                        <textarea class="form-control disney-textarea" id="remark" name="remark" rows="3" placeholder="填写库存调整原因，如:新书入库、丢失、损坏等"></textarea>
                    </div>

                    <div class="button-group">
                        <a href="{{ url_for('inventory.inventory_list') }}" class="btn disney-cancel-btn">
                            取消
                        </a>
                        <button type="submit" class="btn disney-confirm-btn">
                            确认调整
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}

{% block scripts %}
<script>
    // 将当前库存数量传递给JavaScript
    const CURRENT_STOCK = {{ book.stock }};
</script>
<script src="{{ url_for('static', filename='js/inventory-adjust.js') }}"></script>
{% endblock %}
