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'

export const sceneColumns: ColumnsType<ProjectScene> = [
  {
    title: '序列',
    dataIndex: 'id',
    key: 'id'
  },
  {
    title: '名称',
    dataIndex: 'name',
    key: 'name'
  },
  {
    title: '创建人',
    dataIndex: 'phone',
    key: 'phone'
  },
  {
    key: 'num',
    dataIndex: 'num',
    title: '场景码'
  },
  {
    title: '类型',
    dataIndex: 'type',
    key: 'type',
    customRender: ({ record }) =>
      record.type === BinType ? binTypeDesc : SceneTypeDesc[record.type]
  },
  {
    title: '状态',
    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)
    }
  },
  {
    title: '拍摄时间',
    dataIndex: 'createTime',
    key: 'createTime'
  },
  {
    title: '操作',
    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.filter(column =>
  ['name', 'num', 'createTime'].includes(column.key as string)
)
