import { h } from 'vue';
import { NTag, NImage } from 'naive-ui';

export const columns = [
  {
    type: 'selection',
    width: 50,
    fixed: 'left',
  },
  {
    title: 'ID',
    key: 'id',
    fixed: 'left',
    width: 50,
  },
  {
    title: '广告标题',
    key: 'title',
    width: 250,
    render(record) {
      return h(
        'a',
        {
          href: record.url,
          target: '_blank',
        },
        record.title,
      );
    },
  },
  {
    title: '广告封面',
    key: 'cover',
    width: 100,
    render(record) {
      return h(NImage, {
        width: 35,
        src: record.cover,
        shape: 'square',
        fit: 'fill',
      });
    },
  },
  {
    title: '广告类型',
    key: 'type',
    width: 100,
    render(record) {
      let typeText = '';
      switch (record.type) {
        case 1:
          typeText = '图片';
          break;
        case 2:
          typeText = '文字';
          break;
        case 3:
          typeText = '视频';
          break;
        default:
          break;
      }
      return h('span', typeText || '-');
    },
  },
  {
    title: '广告状态',
    key: 'status',
    width: 100,
    render(record) {
      return h(
        NTag,
        {
          type: record.status == 1 ? 'success' : 'error',
        },
        {
          default: () => (record.status == 1 ? '正常' : '停用'),
        },
      );
    },
  },
  {
    title: '广告尺寸',
    key: 'size',
    width: 100,
    render(record) {
      return record.width + 'x' + record.height;
    },
  },
  {
    title: '投放时间',
    key: 'time',
    width: 180,
    render(record) {
      return record.startTime + '-' + record.endTime;
    },
  },
  {
    title: '点击量',
    key: 'click',
    width: 100,
  },
  {
    title: '排序',
    key: 'sort',
    width: 100,
  },
  {
    title: '创建人',
    key: 'createUser',
    width: 100,
  },
  {
    title: '创建时间',
    key: 'createTime',
    width: 180,
  },
];
