<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Print Barcode - {{ product.name }}</title>
    <!-- Basic print styles for thermal label printer -->
    <style>
        body {
            margin: 0;
            padding: 0;
            background-color: #f8f9fa;
            font-family: 'Inter', system-ui, sans-serif;
        }
        
        .label-container {
            /* Standard barcode label size ~ 2x1 inches */
            width: 50mm;
            height: 25mm;
            background: white;
            padding: 2mm;
            box-sizing: border-box;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            text-align: center;
            margin: 20px auto;
            border: 1px dashed #ccc; /* Border just for screen preview */
            box-shadow: 0 4px 6px rgba(0,0,0,0.1);
        }

        .product-name {
            font-size: 8px;
            font-weight: bold;
            margin-bottom: 2px;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            width: 100%;
        }

        .barcode-svg-wrap svg {
            width: 100%;
            height: 12mm; /* Constrain SVG height */
        }
        
        .product-price {
            font-size: 8px;
            font-weight: bold;
            margin-top: 1px;
        }

        .print-controls {
            text-align: center;
            margin-bottom: 20px;
        }

        .btn-print {
            background-color: #0d6efd;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            font-weight: bold;
            cursor: pointer;
            box-shadow: 0 2px 4px rgba(0,0,0,0.2);
        }
        
        .btn-close {
            background-color: #6c757d;
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 5px;
            font-weight: bold;
            cursor: pointer;
            text-decoration: none;
        }

        /* Hide controls when printing */
        @media print {
            body { background: white; margin: 0; }
            .print-controls { display: none !important; }
            .label-container { 
                margin: 0;
                border: none; 
                box-shadow: none; 
                width: 50mm; 
                height: 25mm; 
                page-break-after: always;
            }
            /* Set print page size exactly to label size if possible */
            @page {
                size: 50mm 25mm;
                margin: 0;
            }
        }
    </style>
</head>
<body>

    <div class="print-controls mt-4">
        <a href="{% url 'inventory:product_detail' product.id %}" class="btn-close">Cancel</a>
        <button class="btn-print" onclick="window.print()">Print Label</button>
    </div>

    <!-- The exact physical constraint box for thermal printers -->
    <div class="label-container" id="labelBox">
        <div class="product-name">{{ product.name|truncatechars:25 }}</div>
        
        <div class="barcode-svg-wrap">
            {{ barcode_svg|safe }}
        </div>
        
        <div class="product-price">{{ request.company.settings.currency_symbol|default:'₦' }}{{ product.price }}</div>
    </div>

</body>
</html>
