import { BasicColumn, FormSchema } from '@/components/Table'
import { useI18n } from '@/hooks/web/useI18n'
import { formatToDateTime } from '@/utils/dateUtil'
import { h } from 'vue'
import { getServerList } from '@/api/wechat/server'

const { t } = useI18n()

export const columns: BasicColumn[] = [
  {
    title: t('wechat.wx.serverId'),
    dataIndex: 'serverId',
    width: 50,
  },
  {
    title: t('wechat.wx.port'),
    dataIndex: 'port',
    width: 50,
  },
  {
    title: t('wechat.wx.processId'),
    dataIndex: 'processId',
    width: 50,
  },
  {
    title: t('wechat.wx.callback'),
    dataIndex: 'callback',
    width: 50,
    resizable: true,
  },
  {
    title: t('wechat.wx.wxid'),
    dataIndex: 'wxid',
    width: 50,
    resizable: true,
  },
  {
    title: t('wechat.wx.account'),
    dataIndex: 'account',
    width: 50,
  },
  {
    title: t('wechat.wx.nickname'),
    dataIndex: 'nickname',
    width: 50,
  },
  {
    title: t('wechat.wx.tel'),
    dataIndex: 'tel',
    width: 50,
  },
  {
    title: t('wechat.wx.headBig'),
    dataIndex: 'headBig',
    width: 50,
    customRender: ({ record }) => {
      return h('img', { src: record.headBig, width: 30 })
    },
  },
  {
    title: t('common.status'),
    dataIndex: 'status',
    width: 50,
    customRender: ({ record }) => {
      return record.status == 1 ? '正常' : '已退出'
    },
  },
  {
    title: t('common.createTime'),
    dataIndex: 'createdAt',
    width: 70,
    customRender: ({ record }) => {
      return formatToDateTime(record.createdAt)
    },
  },
]

export const searchFormSchema: FormSchema[] = [
  {
    field: 'serverId',
    label: t('wechat.wx.serverId'),
    component: 'ApiSelect',
    componentProps: {
      api: getServerList,
      params: {
        page: 1,
        pageSize: 100,
      },
      resultField: 'data.data',
      labelField: 'name',
      valueField: 'id',
    },
    colProps: { span: 8 },
  },
  {
    field: 'port',
    label: t('wechat.wx.port'),
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'processId',
    label: t('wechat.wx.processId'),
    component: 'Input',
    colProps: { span: 8 },
  },
]

export const formSchema: FormSchema[] = [
  {
    field: 'serverId',
    label: t('wechat.wx.serverId'),
    component: 'ApiSelect',
    componentProps: {
      api: getServerList,
      params: {
        page: 1,
        pageSize: 100,
      },
      resultField: 'data.data',
      labelField: 'name',
      valueField: 'id',
    },
    required: true,
  },
  {
    field: 'port',
    label: t('wechat.wx.port'),
    component: 'Input',
    required: true,
  },
  {
    field: 'callback',
    label: t('wechat.wx.callback'),
    component: 'Input',
  },
]
