<?php include 'v/header.php'; ?>
<div class="item-list">
    <?php foreach ($items as $item): ?>
        <div class="item-card">
            <div class="item-image">
                <a href="#" class="image-link" data-full-image="/assets/img/<?= htmlspecialchars($item['img']) ?>">
                    <img src="/assets/img/<?= htmlspecialchars($item['img']) ?>" alt="<?= htmlspecialchars($item['name']) ?>">
                </a>
            </div>
            <div class="item-info">
                <div class="item-title">
                    <a href="index.php?id=<?php echo $item['id']; ?>"><?php echo $item['name']; ?></a>
                </div>
                <div class="item-price">¥<?= htmlspecialchars($item['price']) ?></div>
            </div>
                <button class="add-to-cart"
                        data-item-id="<?= htmlspecialchars($item['id']) ?>" 
                        data-item-name="<?= htmlspecialchars($item['name']) ?>" 
                        data-item-price="<?= htmlspecialchars($item['price']) ?>">
                    添加
                </button>
        </div>
    <?php endforeach; ?>
</div>

<!-- Image Modal -->
<div id="image-modal" class="modal">
    <span class="image-modal-close">&times;</span>
    <img class="modal-content" id="full-image">
    <div id="caption"></div>
</div>

<!-- Cart Modal -->
<div id="cart-modal" class="cart-modal">
    <span class="cart-modal-close">&times;</span>
    <div class="cart-modal-content">
        <div class="cart-modal-header">
            <h2>Item Name</h2>
        </div>
        <div class="cart-modal-body">
            <!-- Hidden input for itemId -->
            <input type="hidden" id="item-id" value="">
            <div class="quantity-selector">
                <button id="quantity-minus">-</button>
                <input type="text" id="item-quantity" value="1" readonly>
                <button id="quantity-plus">+</button>
            </div>
            <div class="price-info">
            单价:¥<span id="item-price">0.00</span>&nbsp&nbsp<b>总价:¥<span id="total-price">0.00</span></b>
            </div>
        </div>
        <div class="cart-modal-footer">
            <button id="confirm-add" class="add-to-cart-confirm">确定添加</button>
        </div>
    </div>
</div>
<?php require 'footer.php'; ?>