<!DOCTYPE html>
<html lang="en"><head>
<meta charset="UTF-8">
<title>Test Print — <?=e($shopName)?></title>
<style>
<?php
$maxW = match($paperWidth) {
    '58mm' => '220px',
    'a4'   => '700px',
    default => '302px',
};
?>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:'Courier New',monospace;font-size:12px;max-width:<?=$maxW?>;
     margin:0 auto;padding:12px;background:#fff;color:#000}
.center{text-align:center}.bold{font-weight:bold}
.line{border-top:1px dashed #000;margin:6px 0}
.row{display:flex;justify-content:space-between}
.big{font-size:16px;font-weight:900;letter-spacing:.05em}
@media print{body{margin:0}
  .no-print{display:none}
  @page{size:<?=$paperWidth?>;margin:0}}
</style>
</head><body>

<div class="center bold big" style="margin-bottom:4px"><?=e($shopName)?></div>
<?php if($shopAddress):?><div class="center" style="font-size:10px"><?=e($shopAddress)?></div><?php endif;?>
<?php if($shopPhone):?><div class="center" style="font-size:10px">Tel: <?=e($shopPhone)?></div><?php endif;?>

<div class="line"></div>
<div class="center bold" style="font-size:14px;letter-spacing:.1em">*** TEST PRINT ***</div>
<div class="line"></div>

<div class="row"><span>Date:</span><span><?=date('d M Y')?></span></div>
<div class="row"><span>Time:</span><span><?=date('H:i:s')?></span></div>
<div class="row"><span>Paper Width:</span><span><?=$paperWidth?></span></div>
<div class="row"><span>Printed By:</span><span><?=Auth::name()?></span></div>

<div class="line"></div>
<div class="center" style="font-size:11px">Sample Receipt</div>
<div class="line"></div>

<div class="row"><span>Item 1 x1</span><span>Rs. 100.00</span></div>
<div class="row"><span>Item 2 x2</span><span>Rs. 200.00</span></div>
<div class="row"><span>Item 3 x3</span><span>Rs. 300.00</span></div>

<div class="line"></div>
<div class="row bold"><span>TOTAL</span><span>Rs. 600.00</span></div>
<div class="row"><span>Cash</span><span>Rs. 1,000.00</span></div>
<div class="row bold"><span>Change</span><span>Rs. 400.00</span></div>
<div class="line"></div>

<div class="center" style="font-size:10px;margin-top:6px">
  Printer is working correctly!<br>
  MJPOS By MJ Systems
</div>

<div class="center no-print" style="margin-top:20px">
  <button onclick="window.print()" style="padding:8px 20px;font-size:14px;cursor:pointer;
    background:#3b82f6;color:#fff;border:none;border-radius:8px;font-weight:700">
    Print This Page
  </button>
  <button onclick="window.close()" style="padding:8px 20px;font-size:14px;cursor:pointer;
    background:#f1f5f9;border:1px solid #ccc;border-radius:8px;margin-left:8px">
    Close
  </button>
</div>

<script>
// Auto-print
window.onload = function() {
  <?php if(setting('print_auto_enabled','1')==='1'):?>
  setTimeout(function(){ window.print(); }, 500);
  <?php if($autoClose==='1'):?>
  window.print();
  setTimeout(function(){ window.close(); }, 1200);
  <?php endif;?>
  <?php endif;?>
};
</script>
</body></html>