<template>
  <div class="status-dashboard-container">
    <div class="dashboard-meta">
      <h2 class="title">
        Current Status
      </h2>
      <div class="historical-link">
        Uptime over the past 90 days. <a href="#">View historical uptime.</a>
      </div>
    </div>

    <div class="status-banner operational">
      <svg
        class="octicon octicon-check"
        viewBox="0 0 24 24"
        width="24"
        height="24"
        aria-hidden="true"
        fill="currentColor"
      >
        <path d="M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2Zm0 1.5a8.5 8.5 0 1 0 0 17 8.5 8.5 0 0 0 0-17Zm4.78 6.28-5.5 5.5a.75.75 0 0 1-1.06 0l-2.5-2.5a.751.751 0 0 1 .018-1.08.75.75 0 0 1 1.042.02L11 13.44l4.97-4.97a.75.75 0 0 1 1.06 1.06Z" />
      </svg>
      All Systems Operational
    </div>

    <div class="services-grid">
      <ServiceCard
        v-for="service in mockServices"
        :key="service.id"
        :name="service.name"
        :status="service.status"
        :uptime-percentage="service.uptimePercentage"
        :uptime-history="service.history"
      />
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import ServiceCard from '~/components/ServiceCard.vue'

definePageMeta({
  layout: 'default'
})

const sharedHistory = (() => {
  const history = []
  const now = new Date()
  for (let i = 89; i >= 0; i--) {
    const dayDate = new Date(now.getTime() - i * 24 * 60 * 60 * 1000)
    history.push({
      date: dayDate.toISOString().split('T')[0],
      status: 'normal',
      incident: 'No incidents'
    })
  }
  return history
})()

const serviceNames = [
  'Website', 'Account', 'Connection Test', 'Super Mario Maker',
  'Mario Tennis: Ultra Smash', 'Wii Sports Club', 'Splatoon Global Testfire',
  'Splatoon', 'Friends', 'ぷよぷよテトリス', 'Wii U Chat',
  'Sonic & All-Stars Racing Transformed', 'Minecraft: Wii U Edition', 'Fast Racing Neo'
]

// only here until i actually implement health checks, its 6:30am and i havent slept..
const mockServices = ref(
  serviceNames.map((name, index) => ({
    id: index + 1,
    name,
    status: 'Normal',
    uptimePercentage: 100.00,
    history: sharedHistory
  }))
)
</script>

<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Archivo+Black&display=swap');

.status-dashboard-container {
  max-width: 900px;
  margin: 40px auto;
  padding: 0 20px;
}

.dashboard-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 24px;
}

.title {
  font-family: 'Archivo Black', sans-serif;
  font-weight: 400;
  font-size: 1.5rem;
  color: #f0f6fc;
  margin: 0;
}

.historical-link {
  font-size: 0.85rem;
  color: #8b949e;
}

.historical-link a {
  color: #f0883e;
  text-decoration: none;
}

.historical-link a:hover {
  text-decoration: underline;
}

.status-banner {
  margin-bottom: 32px;
  padding: 16px 24px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.status-banner.operational {
  background-color: #238636;
  color: #ffffff;
  border: 1px solid #2ea44f;
}

.octicon-check {
  flex-shrink: 0;
}

.services-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

@media (max-width: 768px) {
  .services-grid {
    grid-template-columns: 1fr;
  }
  .dashboard-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}
</style>
