<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Print Label - {{ item.name }}</title>
    <style>
        @media print {
            body { margin: 0; padding: 0; }
            .no-print { display: none; }
            .print-page { page-break-after: always; }
        }
        
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
            background: #f5f5f5;
        }
        
        .label-container {
            width: 8.5in;
            margin: 0 auto;
            background: white;
            padding: 0.25in;
        }
        
        .label-pair {
            display: flex;
            gap: 0.125in;
            margin-bottom: 0.25in;
        }
        
        .label {
            width: 4in;
            height: 2.5in;
            border: 2px solid #000;
            border-radius: 8px;
            padding: 0.125in;
            display: flex;
            flex-direction: column;
            background: white;
            box-sizing: border-box;
        }
        
        .label-header {
            text-align: center;
            margin-bottom: 8px;
            border-bottom: 1px solid #ccc;
            padding-bottom: 4px;
        }
        
        .label-title {
            font-size: 14px;
            font-weight: bold;
            color: #28a745;
            margin: 0;
        }
        
        .label-subtitle {
            font-size: 10px;
            color: #666;
            margin: 2px 0 0 0;
        }
        
        .label-content {
            display: flex;
            flex: 1;
            gap: 8px;
        }
        
        .qr-section {
            flex: 0 0 80px;
            text-align: center;
        }
        
        .qr-code {
            width: 80px;
            height: 80px;
            border: 1px solid #ddd;
        }
        
        .qr-text {
            font-size: 8px;
            margin-top: 4px;
            color: #666;
        }
        
        .info-section {
            flex: 1;
            font-size: 10px;
            line-height: 1.2;
        }
        
        .item-name {
            font-weight: bold;
            font-size: 12px;
            margin-bottom: 4px;
            color: #333;
        }
        
        .owner-info {
            margin-bottom: 6px;
        }
        
        .contact-info {
            font-size: 9px;
            color: #555;
        }
        
        .return-info {
            margin-top: 6px;
            padding-top: 4px;
            border-top: 1px solid #eee;
            font-size: 9px;
            color: #666;
        }
        
        .instructions {
            background: #f8f9fa;
            padding: 15px;
            margin: 20px 0;
            border-radius: 5px;
            border-left: 4px solid #28a745;
        }
        
        .print-button {
            background: #28a745;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 16px;
            margin: 10px 5px;
        }
        
        .print-button:hover {
            background: #218838;
        }
        
        .controls {
            text-align: center;
            margin-bottom: 20px;
        }
    </style>
</head>
<body>
    <div class="controls no-print">
        <button class="print-button" onclick="window.print()">🖨️ Print Labels</button>
        <button class="print-button" onclick="window.close()" style="background: #6c757d;">Close</button>
    </div>
    
    <div class="instructions no-print">
        <h4>Printing Instructions:</h4>
        <ul>
            <li>Use standard 8.5" x 11" paper</li>
            <li>Print at 100% scale (no fit to page)</li>
            <li>Cut along the borders and fold in half</li>
            <li>Tape or attach securely to your item</li>
            <li>The QR code links to item info and return process</li>
        </ul>
    </div>

    <div class="label-container">
        <!-- Two identical labels side by side for cutting -->
        {% for i in 1..5 %}
        <div class="label-pair">
            <!-- Left Label -->
            <div class="label">
                <div class="label-header">
                    <h3 class="label-title">LOCAL LENDABLES</h3>
                    <p class="label-subtitle">Community Item Tracker</p>
                </div>
                <div class="label-content">
                    <div class="qr-section">
                        <img src="https://api.qrserver.com/v1/create-qr-code/?size=80x80&data={{ qrUrl|url_encode }}" 
                             alt="QR Code" class="qr-code">
                        <div class="qr-text">Scan to Return</div>
                    </div>
                    <div class="info-section">
                        <div class="item-name">{{ item.name }}</div>
                        <div class="owner-info">
                            <strong>Owner:</strong> {{ owner.showName ?: (owner.firstName ~ ' ' ~ owner.lastName) }}<br>
                            {% if owner.phoneNumber %}
                            <strong>Phone:</strong> {{ owner.phoneNumber }}<br>
                            {% endif %}
                            {% if owner.email %}
                            <strong>Email:</strong> {{ owner.email }}
                            {% endif %}
                        </div>
                        {% if item.pricePerDay and item.pricePerDay > 0 %}
                        <div class="contact-info">
                            <strong>Rate:</strong> ${{ item.pricePerDay }}/day
                        </div>
                        {% endif %}
                        <div class="return-info">
                            Lost this item? Scan QR code or visit:<br>
                            <strong>{{ baseUrl }}/return/{{ item.id }}</strong>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Right Label (Identical) -->
            <div class="label">
                <div class="label-header">
                    <h3 class="label-title">LOCAL LENDABLES</h3>
                    <p class="label-subtitle">Community Item Tracker</p>
                </div>
                <div class="label-content">
                    <div class="qr-section">
                        <img src="https://api.qrserver.com/v1/create-qr-code/?size=80x80&data={{ qrUrl|url_encode }}" 
                             alt="QR Code" class="qr-code">
                        <div class="qr-text">Scan to Return</div>
                    </div>
                    <div class="info-section">
                        <div class="item-name">{{ item.name }}</div>
                        <div class="owner-info">
                            <strong>Owner:</strong> {{ owner.showName ?: (owner.firstName ~ ' ' ~ owner.lastName) }}<br>
                            {% if owner.phoneNumber %}
                            <strong>Phone:</strong> {{ owner.phoneNumber }}<br>
                            {% endif %}
                            {% if owner.email %}
                            <strong>Email:</strong> {{ owner.email }}
                            {% endif %}
                        </div>
                        {% if item.pricePerDay and item.pricePerDay > 0 %}
                        <div class="contact-info">
                            <strong>Rate:</strong> ${{ item.pricePerDay }}/day
                        </div>
                        {% endif %}
                        <div class="return-info">
                            Lost this item? Scan QR code or visit:<br>
                            <strong>{{ baseUrl }}/return/{{ item.id }}</strong>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {% endfor %}
    </div>
</body>
</html>