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

interface CronJob { id: number; schedule: string; command: string; is_active: boolean }
interface Props { service: Service; cronJobs: CronJob[] }

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/cron`">
    <VCard elevation="0">
      <VCardTitle class="d-flex align-center gap-2">
        <VIcon icon="tabler-clock" color="primary" />
        Cron Jobs
      </VCardTitle>
      <VCardText>
        <VTable v-if="cronJobs.length > 0" hover>
          <thead>
            <tr>
              <th class="font-weight-bold">Schedule</th>
              <th class="font-weight-bold">Command</th>
              <th class="font-weight-bold">Status</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="job in cronJobs" :key="job.id">
              <td><code>{{ job.schedule }}</code></td>
              <td><code>{{ job.command }}</code></td>
              <td>
                <VChip :color="job.is_active ? 'success' : 'secondary'" size="small">
                  {{ job.is_active ? 'Active' : 'Inactive' }}
                </VChip>
              </td>
            </tr>
          </tbody>
        </VTable>
        <div v-else class="text-center pa-8 text-medium-emphasis">
          <VIcon icon="tabler-clock-off" size="48" class="mb-2" />
          <div class="text-body-1 mb-2">No cron jobs</div>
          <div class="text-body-2">Cron job management requires Enhance API configuration.</div>
        </div>
      </VCardText>
    </VCard>
  </ServiceTabLayout>
</template>
