<template>
  <AppLayout>
    <div class="thankyou-page">
      <div class="thankyou-card">

        <!-- Animated checkmark -->
        <div class="thankyou-icon" :class="{ 'thankyou-icon--already': alreadyResponded }">
          <svg viewBox="0 0 52 52" class="thankyou-icon__svg">
            <circle class="thankyou-icon__circle" cx="26" cy="26" r="25" fill="none"/>
            <path
              v-if="!alreadyResponded"
              class="thankyou-icon__check"
              fill="none"
              d="M14 27 L22 35 L38 17"
            />
            <text
              v-else
              x="26" y="33"
              text-anchor="middle"
              font-size="20"
              fill="currentColor"
            >!</text>
          </svg>
        </div>

        <!-- Message -->
        <h1 class="thankyou-title">
          {{ alreadyResponded
            ? (locale === 'ar' ? 'لقد أجبت مسبقاً' : 'Already Responded')
            : (locale === 'ar' ? 'شكراً جزيلاً!' : 'Thank You!') }}
        </h1>

        <p class="thankyou-sub">
          {{ alreadyResponded
            ? (locale === 'ar'
                ? 'لقد قدّمت إجابتك على هذا الاستبيان مسبقاً. يُسمح بإجابة واحدة فقط لكل عضو.'
                : 'You have already submitted a response to this survey. Only one response per member is allowed.')
            : (locale === 'ar'
                ? 'تم تسجيل إجابتك بنجاح. إسهامك يساعد في بناء مجتمع أقوى.'
                : 'Your response has been recorded. Your contribution helps build a stronger community.') }}
        </p>

        <!-- Survey name chip -->
        <div v-if="survey?.title_en" class="thankyou-survey-chip">
          <i class="ti ti-clipboard-check"></i>
          {{ locale === 'ar' && survey.title_ar ? survey.title_ar : survey.title_en }}
        </div>

        <!-- Actions -->
        <div class="thankyou-actions">
          <Link
            :href="route('member.surveys.index')"
            class="ip-btn ip-btn--primary"
          >
            {{ locale === 'ar' ? 'العودة للاستبيانات' : 'Back to Surveys' }}
          </Link>
          <Link
            :href="route('member.dashboard')"
            class="ip-btn ip-btn--ghost"
          >
            {{ locale === 'ar' ? 'الرئيسية' : 'Dashboard' }}
          </Link>
        </div>

      </div>
    </div>
  </AppLayout>
</template>

<script setup>
import { Link } from '@inertiajs/vue3'
import AppLayout from '@/Layouts/AppLayout.vue'
import { useAuthStore } from '@/Stores/useAuthStore'

defineProps({
  survey:            { type: Object,  default: null },
  already_responded: { type: Boolean, default: false },
})

const authStore        = useAuthStore()
const locale           = computed(() => authStore.locale)
const alreadyResponded = defineProps(['already_responded']).already_responded
</script>

<style scoped>
.thankyou-page {
  min-height: 100vh;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6) var(--space-5);
}

.thankyou-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-10) var(--space-8);
  max-width: 480px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow-float);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-5);
  animation: ty-fade-up 0.4s ease both;
}

@keyframes ty-fade-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Animated checkmark ── */
.thankyou-icon {
  width: 80px;
  height: 80px;
  color: var(--color-primary);
}

.thankyou-icon--already {
  color: var(--color-warning);
}

.thankyou-icon__svg {
  width: 100%;
  height: 100%;
}

.thankyou-icon__circle {
  stroke: currentColor;
  stroke-width: 2;
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  animation: stroke-circle 0.6s cubic-bezier(0.65, 0, 0.45, 1) 0.2s forwards;
}

.thankyou-icon__check {
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: stroke-check 0.4s cubic-bezier(0.65, 0, 0.45, 1) 0.7s forwards;
}

@keyframes stroke-circle {
  to { stroke-dashoffset: 0; }
}

@keyframes stroke-check {
  to { stroke-dashoffset: 0; }
}

/* ── Text ── */
.thankyou-title {
  font-size: var(--text-2xl);
  font-weight: var(--fw-bold);
  color: var(--color-text-primary);
  line-height: 1.2;
}

.thankyou-sub {
  font-size: var(--text-sm);
  color: var(--color-text-secondary);
  line-height: 1.7;
  max-width: 360px;
}

/* ── Survey name chip ── */
.thankyou-survey-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-pill);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thankyou-survey-chip i {
  font-size: 14px;
  flex-shrink: 0;
}

/* ── Actions ── */
.thankyou-actions {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  justify-content: center;
  margin-top: var(--space-2);
}
</style>
