import { Picture, PictureFilled } from '@element-plus/icons-vue'
import {
  ElButton,
  ElCard,
  ElIcon,
  ElImage,
  ElPopconfirm,
  ElPopover,
} from 'element-plus'

import dayjs from '#/plugins/dayjs'

const _renderWordImg = (scope: any, reference: () => any) => {
  return scope.row.wordVoList.length > 0 ? (
    <ElPopover
      effect="dark"
      placement="top-start"
      popper-class="wordImgPopover"
      visible-arrow={false}
      width="auto"
    >
      {{
        default: () => (
          <div class="image-grid">
            {scope.row.wordList.map((item: any) => {
              return (
                <ElCard class="box-card">
                  <div class="img">
                    {item.wordImg ? (
                      <ElImage fit="contain" src={item.wordImg}>
                        {{
                          error: () => (
                            <div class="image-slot">
                              <ElIcon>
                                <PictureFilled />
                              </ElIcon>
                            </div>
                          ),
                        }}
                      </ElImage>
                    ) : (
                      <div class="image-slot">
                        <ElIcon>
                          <Picture />
                        </ElIcon>
                      </div>
                    )}
                  </div>
                  <div class="footer">
                    <div>{item.spell}</div>
                    <div>
                      {item.meaningVo.typeAbbr} {item.meaningVo.simpleDesc}
                    </div>
                  </div>
                </ElCard>
              )
            })}
          </div>
        ),
        reference,
      }}
    </ElPopover>
  ) : (
    reference()
  )
}

const createColumns = (event: { [key: string]: any }): TableColumn[] => [
  {
    label: '序号',
    render: (h, scope) => scope.$index + 1,
  },
  {
    label: '创建时间',
    prop: 'createTime',
    'show-overflow-tooltip': true,
    render: (h, scope) =>
      dayjs(scope.row.createTime).format('YYYY/MM/DD HH:mm'),
  },
  {
    label: '已有单词列表',
    prop: 'stageVo.wordList',
    render: (h, scope) => {
      return (
        <span>
          {scope.row.wordVoList.map((item: any, index: number) => {
            return (
              <span
                key={item.wordId}
                style={{
                  // cursor: 'pointer',
                  color: scope.row.wordVoList.length < 4 ? '#4f87f5' : '',
                }}
                // onClick={() => {
                //     router.push(
                //         `/word-mgr/word-detail/${item.wordId}?meaningId=${item.meaningVo.id}`
                //     );
                // }}
              >
                <span
                  style={
                    {
                      // color: item.meaningVo.levelSentenceCount ===0 ? '#dd4051' : '',
                      // textDecoration:item.wordImg?'none':'underline'
                    }
                  }
                >
                  {item.spell}
                  {index === scope.row.wordVoList.length - 1 ? '' : ','}
                </span>
              </span>
            )
          })}
        </span>
      )
    },
  },
  {
    label: '操作',
    width: 240,
    fixed: 'right',
    render: (h, scope) => {
      return (
        <div>
          <ElButton
            onClick={() => event.handleClick(scope.row, 0)}
            type="primary"
          >
            编辑
          </ElButton>
          <ElPopconfirm
            onConfirm={() => event.handleClick(scope.row, 1)}
            persistent
            title="删除后无法恢复，确定吗？"
            width="220"
          >
            {{
              reference: () => <ElButton type="danger">删除</ElButton>,
            }}
          </ElPopconfirm>
        </div>
      )
    },
  },
]

export default createColumns
