<script lang="ts" setup>
import { computed } from 'vue'
import ServiceTabLayout from '@/Components/Panel/ServiceTabLayout.vue'
import type { Service } from '@/types'

interface EmailAccount { id: number; address: string; quota_used: number; quota_limit: number }
interface Props { service: Service; emailAccounts: EmailAccount[] }

const props = defineProps<Props>()
const tabs = computed(() => [
  { label: 'Dashboard', icon: 'tabler-dashboard', to: `/services/${props.service.id}/hosting-panel` },
  { label: 'Files', icon: 'tabler-folder', to: `/services/${props.service.id}/hosting-panel/files` },
  { label: 'Databases', icon: 'tabler-database', to: `/services/${props.service.id}/hosting-panel/databases` },
  { label: 'Email', icon: 'tabler-mail', to: `/services/${props.service.id}/hosting-panel/email` },
  { label: 'Domains', icon: 'tabler-world', to: `/services/${props.service.id}/hosting-panel/domains` },
  { label: 'DNS', icon: 'tabler-dns', to: `/services/${props.service.id}/hosting-panel/dns` },
  { label: 'SSL', icon: 'tabler-lock', to: `/services/${props.service.id}/hosting-panel/ssl` },
  { label: 'PHP', icon: 'tabler-brand-php', to: `/services/${props.service.id}/hosting-panel/php` },
  { label: 'Cron', icon: 'tabler-clock', to: `/services/${props.service.id}/hosting-panel/cron` },
  { label: 'Settings', icon: 'tabler-settings', to: `/services/${props.service.id}/hosting-panel/settings` },
])
</script>

<template>
  <ServiceTabLayout :service="service" :tabs="tabs" :current-tab="`/services/${service.id}/hosting-panel/email`">
    <VCard elevation="0">
      <VCardTitle class="d-flex align-center gap-2">
        <VIcon icon="tabler-mail" color="primary" />
        Email Accounts
      </VCardTitle>
      <VCardText>
        <VTable v-if="emailAccounts.length > 0" hover>
          <thead>
            <tr>
              <th class="font-weight-bold">Address</th>
              <th class="font-weight-bold">Quota Used</th>
              <th class="font-weight-bold">Quota Limit</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="account in emailAccounts" :key="account.id">
              <td class="font-weight-medium">{{ account.address }}</td>
              <td>{{ (account.quota_used / 1024 / 1024).toFixed(1) }} MB</td>
              <td>{{ account.quota_limit ? `${(account.quota_limit / 1024 / 1024).toFixed(0)} MB` : 'Unlimited' }}</td>
            </tr>
          </tbody>
        </VTable>
        <div v-else class="text-center pa-8 text-medium-emphasis">
          <VIcon icon="tabler-mail-off" size="48" class="mb-2" />
          <div class="text-body-1 mb-2">No email accounts</div>
          <div class="text-body-2">Email management requires Enhance API configuration.</div>
        </div>
      </VCardText>
    </VCard>
  </ServiceTabLayout>
</template>
