<script setup lang="ts">
import { Bell, Clock } from 'lucide-vue-next'

export interface ActiveReminder {
  id: string
  content: string
  triggerAt: string
  triggerType: 'time' | 'context'
}

const props = defineProps<{
  reminder: ActiveReminder | null
  visible: boolean
}>()

const emit = defineEmits<{
  (e: 'snooze', id: string, minutes: number): void
  (e: 'dismiss', id: string): void
}>()

function handleSnooze() {
  if (props.reminder) {
    emit('snooze', props.reminder.id, 15)
  }
}

function handleDismiss() {
  if (props.reminder) {
    emit('dismiss', props.reminder.id)
  }
}

function formatTime(dateStr: string) {
  const date = new Date(dateStr)
  return date.toLocaleTimeString('zh-CN', {
    hour: '2-digit',
    minute: '2-digit',
  })
}
</script>

<template>
  <Transition name="slide-up">
    <div v-if="visible && reminder" class="reminder-toast">
      <div class="toast-icon">
        <Bell :size="20" />
      </div>

      <div class="toast-content">
        <div class="toast-header">
          <span class="toast-label">REMINDER</span>
          <span class="toast-time">
            <Clock :size="10" />
            {{ formatTime(reminder.triggerAt) }}
          </span>
        </div>
        <div class="toast-message">{{ reminder.content }}</div>
      </div>

      <div class="toast-actions">
        <button class="toast-btn snooze" @click="handleSnooze">
          稍后
        </button>
        <button class="toast-btn dismiss" @click="handleDismiss">
          知道了
        </button>
      </div>
    </div>
  </Transition>
</template>

<style scoped>
.reminder-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 16px 18px;
  min-width: 320px;
  max-width: 420px;
  background: linear-gradient(135deg, rgba(13, 21, 37, 0.98) 0%, rgba(10, 15, 26, 0.96) 100%);
  border: 1px solid rgba(249, 168, 37, 0.3);
  border-radius: var(--radius-lg);
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.5),
    0 0 20px rgba(249, 168, 37, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.reminder-toast::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, rgba(249, 168, 37, 0.6), rgba(249, 168, 37, 0.8), rgba(249, 168, 37, 0.6), transparent);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.toast-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: rgba(249, 168, 37, 0.15);
  color: var(--accent-amber);
  flex-shrink: 0;
  animation: pulse-glow-amber 2s ease-in-out infinite;
}

@keyframes pulse-glow-amber {
  0%, 100% {
    box-shadow: 0 0 8px rgba(249, 168, 37, 0.3);
  }
  50% {
    box-shadow: 0 0 16px rgba(249, 168, 37, 0.5);
  }
}

.toast-content {
  flex: 1;
  min-width: 0;
}

.toast-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}

.toast-label {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--accent-amber);
}

.toast-time {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
}

.toast-message {
  font-family: var(--font-body);
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-primary);
}

.toast-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.toast-btn {
  padding: 8px 14px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  border-radius: var(--radius-sm);
  border: 1px solid;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.toast-btn.snooze {
  background: rgba(0, 245, 212, 0.08);
  border-color: rgba(0, 245, 212, 0.25);
  color: var(--accent-cyan);
}

.toast-btn.snooze:hover {
  background: rgba(0, 245, 212, 0.15);
  border-color: rgba(0, 245, 212, 0.4);
  box-shadow: 0 0 12px rgba(0, 245, 212, 0.2);
}

.toast-btn.dismiss {
  background: rgba(249, 168, 37, 0.1);
  border-color: rgba(249, 168, 37, 0.3);
  color: var(--accent-amber);
}

.toast-btn.dismiss:hover {
  background: rgba(249, 168, 37, 0.2);
  border-color: rgba(249, 168, 37, 0.5);
  box-shadow: 0 0 12px rgba(249, 168, 37, 0.25);
}

/* Slide-up animation */
.slide-up-enter-active {
  transition: all 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.slide-up-leave-active {
  transition: all 0.25s ease-in;
}

.slide-up-enter-from {
  opacity: 0;
  transform: translateY(40px) scale(0.95);
}

.slide-up-leave-to {
  opacity: 0;
  transform: translateY(20px) scale(0.98);
}
</style>
