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

interface DnsRecord { id: number; type: string; name: string; content: string; ttl: number; priority: number | null }
interface Props { service: Service; records: DnsRecord[] }

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/dns`">
    <VCard elevation="0">
      <VCardTitle class="d-flex align-center gap-2">
        <VIcon icon="tabler-dns" color="primary" />
        DNS Zone Editor
      </VCardTitle>
      <VCardText>
        <VTable v-if="records.length > 0" hover>
          <thead>
            <tr>
              <th class="font-weight-bold">Type</th>
              <th class="font-weight-bold">Name</th>
              <th class="font-weight-bold">Content</th>
              <th class="font-weight-bold">TTL</th>
              <th class="font-weight-bold">Priority</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="record in records" :key="record.id">
              <td><VChip size="small" variant="tonal">{{ record.type }}</VChip></td>
              <td class="font-weight-medium">{{ record.name }}</td>
              <td><code>{{ record.content }}</code></td>
              <td>{{ record.ttl }}</td>
              <td>{{ record.priority ?? '--' }}</td>
            </tr>
          </tbody>
        </VTable>
        <div v-else class="text-center pa-8 text-medium-emphasis">
          <VIcon icon="tabler-dns" size="48" class="mb-2" />
          <div class="text-body-1 mb-2">No DNS records</div>
          <div class="text-body-2">DNS management requires Enhance API configuration.</div>
        </div>
      </VCardText>
    </VCard>
  </ServiceTabLayout>
</template>
