<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <div class="success-wrapper">
    <div class="logo-section-contact">
      <div class="logo-group-contact">
        <v-img
          src="/JatimLogo.png"
          width="50"
          height="50"
          class="logo-img-contact"
          contain
        />
        <v-img
          src="/rssalogo.png"
          width="50"
          height="50"
          class="logo-img-contact"
          contain
        />
        <v-img
          src="/BerakhlakLogo.png"
          width="50"
          height="50"
          class="logo-img-contact"
          contain
        />
        <v-img
          src="karslogo.png"
          width="50"
          height="50"
          class="logo-img-contact"
          contain
        />
      </div>
    </div>
    <div class="success-container">
      <div class="success-icon-container">
        <div class="success-icon-bg">
          <v-icon icon="mdi-check-circle" size="100" class="success-icon" />
        </div>
      </div>

      <div class="success-content">
        <h2 class="success-title">Pembayaran Berhasil</h2>

        <div class="success-message">
          <p class="message-line">Silahkan Menunggu Bukti Pembayaran</p>
        </div>

        <!-- Payment Details Summary -->
        <div class="payment-summary" v-if="paymentStore.patientInfo">
          <div class="summary-card">
            <div class="summary-row">
              <span class="summary-label">Nomor RM:</span>
              <span class="summary-value">{{
                paymentStore.qrData.display_norm || "-"
              }}</span>
            </div>

            <div class="summary-row">
              <span class="summary-label">No. Billing:</span>
              <span class="summary-value">{{
                paymentStore.qrData.display_nobill || "-"
              }}</span>
            </div>

            <div class="summary-row">
              <span class="summary-label">Pasien:</span>
              <span class="summary-value">{{
                paymentStore.patientInfo.name
              }}</span>
            </div>

            <div class="summary-row">
              <span class="summary-label">Nominal:</span>
              <span class="summary-value amount">{{
                formatCurrency(paymentStore.patientInfo.amount)
              }}</span>
            </div>

            <div class="summary-row">
              <span class="summary-label">Status:</span>
              <v-chip color="success" variant="flat" size="small">
                <v-icon size="14" class="mr-1">mdi-check</v-icon>
                Berhasil
              </v-chip>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { usePaymentStore } from "~/stores/payment";

const paymentStore = usePaymentStore();

const formatCurrency = (amountString) => {
  const cleanString = amountString.replace(/\./g, "").replace(",", ".");
  const amount = parseFloat(cleanString);

  if (isNaN(amount)) {
    return "Invalid Amount";
  }

  return new Intl.NumberFormat("id-ID", {
    style: "currency",
    currency: "IDR",
    minimumFractionDigits: 0,
  }).format(amount);
};
</script>

<style scoped>
.success-wrapper {
  position: relative;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.logo-section-contact {
  position: absolute;
  top: 20px;
  left: 0;
  right: 0;
  display: flex;
  background: rgb(255, 255, 255);
  border-radius: 24px;
  padding: 1rem 1rem;
  margin: 0 auto;
  width: fit-content;
  justify-content: center;
  z-index: 10;
}

.logo-group-contact {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.success-container {
  background: rgb(255, 255, 255);
  border-radius: 24px;
  padding: 3rem 2rem;
  text-align: center;
  width: 100%;
  max-width: 600px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
}

/* Success Icon Animation */
.success-icon-container {
  display: inline-block;
  margin-bottom: 2rem;
}

.success-icon-bg {
  display: inline-block;
  animation: successPulse 2s ease-in-out infinite;
}

.success-icon {
  color: #4caf50 !important;
  filter: drop-shadow(0 4px 20px rgba(76, 175, 80, 0.3));
}

@keyframes successPulse {
  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.9;
  }
}

/* Success Content */
.success-content {
  position: relative;
}

.success-title {
  font-size: 2rem;
  font-weight: 800;
  color: #1a1a1a;
  background: linear-gradient(135deg, #4caf50 0%, #2e7d32 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 1rem;
  line-height: 1.3;
}

.success-message {
  color: #666;
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.6;
  margin-bottom: 2rem;
}

.message-line {
  margin: 0.25rem 0;
}

/* Payment Summary */
.payment-summary {
  margin-top: 2rem;
}

.summary-card {
  background: rgba(76, 175, 80, 0.06);
  border-radius: 16px;
  padding: 1.5rem;
  border: 1px solid rgba(76, 175, 80, 0.2);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.summary-row:last-child {
  border-bottom: none;
}

.summary-label {
  color: #666;
  font-weight: 600;
  font-size: 0.95rem;
}

.summary-value {
  color: #1a1a1a;
  font-weight: 700;
  font-size: 1rem;
  text-align: right;
}

.summary-value.amount {
  color: #4caf50;
  font-size: 1.1rem;
}

/* Portrait Tablet */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
  .success-wrapper {
    padding: 2rem;
  }
  .logo-section-contact {
    padding: 20px 12px;
    margin-top: 40px;
    margin-bottom: 40px;
  }

  .logo-img-contact {
    width: 80px !important;
    height: 80px !important;
  }
  .success-container {
    max-width: 700px;
    padding: 3.5rem 2.5rem;
  }

  .success-icon {
    font-size: 120px !important;
  }

  .success-title {
    font-size: 2.25rem;
  }

  .success-message {
    font-size: 1.2rem;
  }
}

/* Landscape Tablet */
@media (min-width: 768px) and (orientation: landscape) {
  .success-container {
    max-width: 650px;
  }

  .logo-section-contact {
    display: none;
  }

}
</style>
