@forelse($printItems as $item)
@php
$qty = max((int) ($item['qty'] ?? 1), 1);
$isVariant = (string) ($item['kind'] ?? 'product') === 'variant';
$displayName = trim((string) ($item['display_name'] ?? $item['product_name'] ?? ''));
$productName = trim((string) ($item['product_name'] ?? $displayName));
$variantName = trim((string) ($item['variant_name'] ?? ''));
$barcodeLabel = trim((string) ($item['barcode_label'] ?? $item['barcode_value'] ?? ''));
$barcodeValue = strtoupper(preg_replace('/\s+/', '', (string) ($item['barcode_value'] ?? '')));
if ($barcodeValue === '') {
$barcodeValue = (string) ($item['product_id'] ?? '0');
}
$barcodeDisplay = '*' . $barcodeValue . '*';
$labelClass = 'label ' . ($layoutStyle === 'compact' ? 'compact' : ($layoutStyle === 'price_top' ? 'price-top' : 'classic'));
$labelClass .= in_array($barcodeTemplate->size, ['28x19', '30x19', '30x28'], true) ? ' tiny-label' : '';
$barcodeSvg = $buildCode39Svg($barcodeValue, in_array($barcodeTemplate->size, ['58x40'], true) ? 42 : (in_array($barcodeTemplate->size, ['30x28'], true) ? 30 : 26), in_array($barcodeTemplate->size, ['58x40'], true) ? 2 : 1, in_array($barcodeTemplate->size, ['58x40'], true) ? 4 : 3);
$saleRate = (float) ($item['sale_rate'] ?? 0);
$sourceLabel = trim((string) ($item['barcode_source_label'] ?? ''));
@endphp
@for($i = 0; $i < $qty; $i++)
@if($barcodeTemplate->show_shop_name)
{{ $shopName }}
@endif
@if($layoutStyle === 'price_top' && $barcodeTemplate->show_price)
Rs. {{ number_format($saleRate, 2) }}
@endif
@if($barcodeTemplate->show_product_name)
{{ $displayName !== '' ? $displayName : $productName }}
@if($isVariant && $variantName !== '')
{{ $variantName }}
@endif
@endif
{{ $barcodeLabel !== '' ? $barcodeLabel : $barcodeValue }}
@if($sourceLabel !== '')
{{ $sourceLabel }}
@endif
@if($layoutStyle !== 'price_top' && $barcodeTemplate->show_price)
Rs. {{ number_format($saleRate, 2) }}
@endif
@endfor
@empty
{{ __('No products selected for this template.') }}
@endforelse