import { h } from 'vue'
import SceneActions from './actions.vue'
import {
  SceneTypeDesc,
  BinType,
  binTypeDesc,
  BimStatusDesc,
  BimStatus,
  sceneStatusDesc,
  SceneStatus
} from '@/store'

import type { ProjectScene } from '@/store'
import type { ColumnsType } from 'ant-design-vue/es/table'
import { ui18n } from '@/lang'

export const sceneColumns: ColumnsType<ProjectScene> = [
  // {
  //   title: '序列',
  //   dataIndex: 'id',
  //   key: 'id',
  //   customRender: ({ index }) => index + 1
  // },
  {
    title: ui18n.t('scene.nameLabel'),
    dataIndex: 'name',
    width: '300px',
    key: 'name'
  },
  {
    title: ui18n.t('scene.phoneLabel'),
    dataIndex: 'phone',
    key: 'phone'
  },
  {
    key: 'num',
    dataIndex: 'num',
    title: ui18n.t('scene.numLabel')
  },
  {
    title: ui18n.t('scene.shootCountLabel'),
    dataIndex: 'shootCount',
    width: '100px',
    key: 'shootCount'
  },
  {
    title: ui18n.t('scene.typeLabel'),
    dataIndex: 'type',
    key: 'type',
    customRender: ({ record }) =>
      record.type === BinType ? binTypeDesc : SceneTypeDesc[record.type]
  },
  {
    title: ui18n.t('scene.statusLabel'),
    dataIndex: 'status',
    key: 'status',
    customRender: ({ record }) => {
      const props =
        record.type === BinType
          ? {
              desc: BimStatusDesc[record.status],
              done: record.status === BimStatus.done
            }
          : {
              desc: sceneStatusDesc[record.status],
              done: record.status === SceneStatus.SUCCESS
            }

      const style = {
        color: props.done ? '#04CE75' : '#323233',
        fontSize: '14px'
      }
      return h('span', { style }, props.desc)
    }
  },
  {
    width: '100px',
    title: ui18n.t('scene.createTimeLabel'),
    dataIndex: 'createTime',
    key: 'createTime'
  },
  {
    width: '300px',
    title: ui18n.t('sys.oper'),
    dataIndex: 'action',
    key: 'action',
    customRender: ({ record }) => h(SceneActions, { scene: record })
  }
]

export const projectSceneColumns = sceneColumns.filter(
  ({ key }) => !['num'].includes(key as string)
)
export const selectSceneColumns = [
  {
    ...sceneColumns[0],
    maxWidth: 180,
    // eslint-disable-next-line @typescript-eslint/ban-ts-comment
    // @ts-ignore
    customRender({ record }) {
      const style = {
        maxWidth: '180px'
      }
      return h('p', { style }, record.name)
    }
  },
  ...sceneColumns.filter(column =>
    ['num', 'createTime', 'shootCount'].includes(column.key as string)
  )
]
