<script setup>
const props = defineProps({
  todayTotal: {
    type: Number,
    default: 0
  },
  loading: {
    type: Boolean,
    default: false
  },
  compact: {
    type: Boolean,
    default: false
  }
})

const formatCurrency = (value) => {
  return new Intl.NumberFormat('de-DE', {
    style: 'currency',
    currency: 'EUR'
  }).format(value)
}

const currentDate = computed(() => {
  return new Date().toLocaleDateString('de-DE', {
    weekday: 'long',
    year: 'numeric',
    month: 'long',
    day: 'numeric'
  })
})
</script>

<template>
  <div class="today-card" :class="{ 'compact': compact }">
    <div class="card-header">
      <div class="header-icon">
        <UIcon name="i-heroicons-calendar-days" />
      </div>
      <div class="header-text">
        <h3 class="card-title">Today's Revenue</h3>
        <p v-if="!compact" class="card-date">{{ currentDate }}</p>
      </div>
    </div>

    <div class="card-body">
      <div v-if="loading" class="loading">
        <UIcon name="i-heroicons-arrow-path" class="animate-spin" />
        <span v-if="!compact">Loading...</span>
      </div>
      <div v-else class="amount-display">
        <span class="amount">{{ formatCurrency(todayTotal) }}</span>
      </div>
    </div>

    <div v-if="!compact" class="card-footer">
      <UIcon name="i-heroicons-information-circle" />
      <span>Total LineTotalAmt for all organizations today</span>
    </div>
  </div>
</template>

<style scoped>
.today-card {
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
  overflow: hidden;
  transition: box-shadow 0.3s ease;
  border: 2px solid #3b82f6;
}

.today-card:hover {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 2px 4px rgba(0, 0, 0, 0.06);
}

/* Compact mode styles */
.today-card.compact {
  border-radius: 8px;
  min-width: 200px;
  max-width: 250px;
}

.today-card.compact .card-header {
  padding: 0.75rem 1rem;
  gap: 0.5rem;
}

.today-card.compact .header-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
}

.today-card.compact .header-icon svg {
  width: 1.25rem;
  height: 1.25rem;
}

.today-card.compact .card-title {
  font-size: 0.875rem;
  margin: 0;
}

.today-card.compact .card-body {
  padding: 0.75rem 1rem;
}

.today-card.compact .amount {
  font-size: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  color: white;
}

.header-icon {
  width: 3rem;
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  backdrop-filter: blur(10px);
}

.header-icon svg {
  width: 2rem;
  height: 2rem;
}

.header-text {
  flex: 1;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.25rem 0;
  color: white;
}

.card-date {
  font-size: 0.875rem;
  margin: 0;
  opacity: 0.9;
}

.card-body {
  padding: 2rem 1.5rem;
  background: #f9fafb;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  color: #6b7280;
  font-size: 1rem;
}

.loading svg {
  width: 1.5rem;
  height: 1.5rem;
}

.amount-display {
  text-align: center;
}

.amount {
  font-size: 2.5rem;
  font-weight: 700;
  color: #1e40af;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  display: inline-block;
}

.card-footer {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  background: white;
  border-top: 1px solid #e5e7eb;
  font-size: 0.875rem;
  color: #6b7280;
}

.card-footer svg {
  width: 1rem;
  height: 1rem;
  color: #3b82f6;
  flex-shrink: 0;
}

@media (max-width: 768px) {
  .amount {
    font-size: 2rem;
  }

  .card-header {
    padding: 1rem;
  }

  .card-body {
    padding: 1.5rem 1rem;
  }

  .today-card.compact .amount {
    font-size: 1.25rem;
  }
}
</style>
