<template>
  <table class="ticket-table" cellpadding="0" cellspacing="0">
    <tr>
      <td class="ticket-content">
        <div class="header">
          <div class="hospital-name">RSUD DR. SAIFUL ANWAR</div>
          <div class="hospital-address">Jl. Jaksa Agung Suprapto No.2, Malang</div>
          <div class="ticket-title">Tiket Antrean</div>
        </div>
        
        <div class="no-antrian">{{ noAntrianDisplay }}</div>
        
        <div class="klinik-name">{{ ruangInfo || klinik }}</div>
        
        <div class="qr-code-section">
          <div class="qr-code">
            <img :src="qrCodeImage" alt="QR Code" />
          </div>
          <div class="barcode-number">{{ barcode }}</div>
        </div>
        
        <div class="info-section">
          <div class="info-row">
            <div class="info-label-wrapper">
              <span class="info-label-text">Tanggal</span><span class="info-colon">:</span>
            </div>
            <span class="info-value">{{ tanggal }}</span>
          </div>
          
          <div class="info-row">
            <div class="info-label-wrapper">
              <span class="info-label-text">Waktu</span><span class="info-colon">:</span>
            </div>
            <span class="info-value">{{ waktu }}</span>
          </div>
          
          <div class="info-row">
            <div class="info-label-wrapper">
              <span class="info-label-text">Shift</span><span class="info-colon">:</span>
            </div>
            <span class="info-value">{{ shift }}</span>
          </div>
          
          <div class="info-row">
            <div class="info-label-wrapper">
              <span class="info-label-text">Pembayaran</span><span class="info-colon">:</span>
            </div>
            <span class="info-value">{{ pembayaran }}</span>
          </div>
          
          <div v-if="namaDokter" class="info-row">
            <div class="info-label-wrapper">
              <span class="info-label-text">Dokter</span><span class="info-colon">:</span>
            </div>
            <span class="info-value">{{ namaDokter }}</span>
          </div>
        </div>
        
        <div class="footer">
          <div class="footer-text">Tunjukkan tiket ini saat check-in</div>
          <div class="footer-text">QR Code digunakan untuk check-in pasien</div>
          <div class="footer-text">Terima kasih</div>
        </div>
      </td>
    </tr>
  </table>
</template>

<script setup lang="ts">
import type { ThermalPrintData } from '@/composables/useThermalPrint';

interface Props {
  data: ThermalPrintData;
  qrCodeImage: string;
  noAntrianDisplay: string;
  ruangInfo: string;
}

const props = defineProps<Props>();

const {
  barcode,
  klinik,
  shift,
  pembayaran,
  tanggal,
  waktu,
  namaDokter
} = props.data;
</script>

<style scoped>
.ticket-table {
  width: 100%;
  border-collapse: collapse;
  border: 2px dashed #000;
  margin: 0;
  background: white;
}

.ticket-table td {
  padding: 0;
  border: none;
}

.ticket-content {
  padding: 2mm 4mm 4mm 4mm;
  text-align: center;
}

.header {
  margin-bottom: 2mm;
  border-bottom: 2px solid #000;
  padding-bottom: 1mm;
  margin-top: 0;
}

.hospital-name {
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 0.5mm;
  text-transform: uppercase;
  letter-spacing: 1px;
  line-height: 1.0;
}

.hospital-address {
  font-size: 10px;
  font-weight: bold;
  margin-bottom: 0.5mm;
  line-height: 1.0;
}

.ticket-title {
  font-size: 12px;
  font-weight: bold;
  margin-top: 1mm;
  text-transform: uppercase;
  line-height: 1.0;
}

.qr-code-section {
  margin-top: 0;
  margin-bottom: 0.5mm;
  text-align: center;
}

.qr-code {
  width: 30mm;
  height: 30mm;
  margin: 0 auto;
  border: none;
  padding: 0.5mm;
  background: white;
}

.qr-code img {
  width: 100%;
  height: 100%;
  display: block;
}

.barcode-number {
  font-size: 10px;
  font-weight: bold;
  margin-top: -0.5mm;
  word-break: break-all;
  line-height: 1.0;
}

.info-section {
  margin-top: 2mm;
  text-align: left;
  border-top: 1px dashed #000;
  padding-top: 1mm;
  padding-left: 3mm;
  padding-right: 3mm;
}

.info-row {
  margin-bottom: 0.8mm;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0;
  line-height: 1.0;
}

.info-label-text {
  font-weight: bold;
  font-size: 10px;
  text-align: left;
  text-transform: uppercase;
  word-break: keep-all;
  line-height: 1.0;
}

.info-colon {
  font-weight: bold;
  font-size: 10px;
  margin-left: auto;
  padding-right: 2mm;
  line-height: 1.0;
}

.info-label-wrapper {
  display: flex;
  width: 22mm;
  flex-shrink: 0;
  align-items: flex-start;
  gap: 1mm;
}

.info-value {
  font-size: 10px;
  font-weight: bold;
  text-align: right;
  word-break: break-word;
  line-height: 1.0;
}

.no-antrian {
  font-size: 28px;
  font-weight: bold;
  margin: 0.3mm 0;
  letter-spacing: 2px;
  text-transform: uppercase;
  line-height: 1.0;
}

.klinik-name {
  font-size: 12px;
  font-weight: bold;
  margin-top: 0.3mm;
  margin-bottom: 2mm;
  padding-bottom: 0;
  text-transform: uppercase;
  overflow: visible;
  line-height: 1.0;
}

.footer {
  margin-top: 2mm;
  padding-top: 1mm;
  padding-bottom: 0;
  margin-bottom: 6mm;
  border-top: 2px solid #000;
  font-size: 9px;
  font-weight: bold;
  text-align: center;
  line-height: 1.0;
}

.footer-text {
  margin-bottom: 0.5mm;
  font-weight: bold;
  line-height: 1.0;
}

.footer-text:last-child {
  margin-bottom: 0;
}
</style>
