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

interface Domain { id: number; name: string; type: 'primary' | 'addon' | 'subdomain'; document_root: string }
interface Props { service: Service; domains: Domain[] }

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/domains`">
    <VCard elevation="0">
      <VCardTitle class="d-flex align-center gap-2">
        <VIcon icon="tabler-world" color="primary" />
        Domains
      </VCardTitle>
      <VCardText>
        <VTable v-if="domains.length > 0" hover>
          <thead>
            <tr>
              <th class="font-weight-bold">Domain</th>
              <th class="font-weight-bold">Type</th>
              <th class="font-weight-bold">Document Root</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="domain in domains" :key="domain.id">
              <td class="font-weight-medium">{{ domain.name }}</td>
              <td>
                <VChip :color="domain.type === 'primary' ? 'primary' : 'secondary'" size="small" class="text-capitalize">
                  {{ domain.type }}
                </VChip>
              </td>
              <td><code>{{ domain.document_root }}</code></td>
            </tr>
          </tbody>
        </VTable>
        <div v-else class="text-center pa-8 text-medium-emphasis">
          <VIcon icon="tabler-world-off" size="48" class="mb-2" />
          <div class="text-body-1 mb-2">No domains configured</div>
          <div class="text-body-2">Domain management requires Enhance API configuration.</div>
        </div>
      </VCardText>
    </VCard>
  </ServiceTabLayout>
</template>
