import { Cloud, Edit, Send, Settings, Smartphone, Trash2 } from 'lucide-vue-next'
import type { ColumnDef } from '@tanstack/vue-table'

import { h } from 'vue'

import type { SmsConfig } from '@/pages/admin/sms-settings/data/schema'

import Badge from '@/components/ui/badge/Badge.vue'
import Button from '@/components/ui/button/Button.vue'

interface ColumnOptions {
  onToggleStatus: (row: SmsConfig) => void
  onEdit: (row: SmsConfig) => void
  onDelete: (row: SmsConfig) => void
  onTest: (row: SmsConfig) => void
}

export function getColumns(options: ColumnOptions, t: (key: string) => string): ColumnDef<SmsConfig>[] {
  return [
    {
      accessorKey: 'name',
      header: () => '配置名称',
      cell: ({ row }) => {
        return h('div', { class: 'flex items-center gap-2' }, [
          h(Smartphone, { class: 'h-4 w-4 text-muted-foreground' }),
          h('span', { class: 'font-medium' }, row.original.name),
        ])
      },
    },
    {
      accessorKey: 'type',
      header: () => '类型',
      cell: ({ row }) => {
        const typeLabels: Record<string, string> = {
          aliyun: '阿里云',
          tencent: '腾讯云',
          other: '其他',
        }
        const typeIcons: Record<string, any> = {
          aliyun: Cloud,
          tencent: Cloud,
          other: Settings,
        }
        return h('div', { class: 'flex items-center gap-2' }, [
          h(typeIcons[row.original.type] || Settings, { class: 'h-4 w-4 text-muted-foreground' }),
          h('span', { class: 'text-sm' }, typeLabels[row.original.type] || row.original.type),
        ])
      },
    },
    {
      accessorKey: 'status',
      header: () => '状态',
      cell: ({ row }) => {
        const statusLabels: Record<string, string> = {
          active: '启用',
          inactive: '禁用',
        }
        const statusClasses: Record<string, string> = {
          active: 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400 cursor-pointer',
          inactive: 'bg-gray-100 text-gray-700 dark:bg-gray-900/30 dark:text-gray-400 cursor-pointer',
        }
        return h(Badge, {
          class: statusClasses[row.original.status],
          onClick: () => options.onToggleStatus(row.original),
        }, () => statusLabels[row.original.status])
      },
    },
    {
      accessorKey: 'remark',
      header: () => '备注',
      cell: ({ row }) => {
        return h('span', { class: 'text-sm text-muted-foreground' }, row.original.remark || '-')
      },
    },
    {
      accessorKey: 'created_at',
      header: () => '创建时间',
      cell: ({ row }) => {
        return h('span', { class: 'text-sm text-muted-foreground' }, new Date(row.original.created_at).toLocaleString('zh-CN'))
      },
    },
    {
      id: 'actions',
      header: () => '操作',
      cell: ({ row }) => {
        return h('div', { class: 'flex items-center justify-end gap-1' }, [
          h(Button, {
            variant: 'ghost',
            size: 'sm',
            title: '测试发送',
            onClick: () => options.onTest(row.original),
          }, () => [
            h(Send, { class: 'h-4 w-4 text-blue-500' }),
          ]),
          h(Button, {
            variant: 'ghost',
            size: 'sm',
            onClick: () => options.onEdit(row.original),
          }, () => [
            h(Edit, { class: 'h-4 w-4' }),
          ]),
          h(Button, {
            variant: 'ghost',
            size: 'sm',
            onClick: () => options.onDelete(row.original),
          }, () => [
            h(Trash2, { class: 'h-4 w-4 text-destructive' }),
          ]),
        ])
      },
    },
  ]
}
