import { BasicColumn, FormSchema, render } from '@jdlinker/ui';

export const columns: BasicColumn[] = [
  {
    title: '序号',
    dataIndex: '',
    key: 'rowIndex',
    width: 60,
    align: 'center',
    customRender: function ({ index }) {
      return parseInt(String(index)) + 1;
    }
  },
  {
    title: '文件图标',
    dataIndex: 'downloadUrl',
    customRender: ({ record, text }) => {
      return render.renderImg(record.suffix, text);
    },
    width: 120
  },
  {
    title: '文件名',
    dataIndex: 'originalFilename'
  },
  {
    title: '文件路径',
    dataIndex: 'objectName'
  },
  {
    title: '文件大小',
    dataIndex: 'fileSize',
    width: 120,
    customRender: ({ text }) => {
      const unitArr = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
      const srcSize = Number.parseFloat(text);
      const index = Math.floor(Math.log(srcSize) / Math.log(1024));
      const size = srcSize / 1024 ** index;
      return `${size.toFixed(2)} ${unitArr[index]}`;
    }
  },
  {
    title: '文件类型',
    dataIndex: 'suffix',
    width: 100,
    customRender: ({ text }) => {
      return render.renderTag(text, 'gray');
    }
  },
  {
    title: '上传时间',
    dataIndex: 'createTime',
    width: 180
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    label: '文件名称',
    field: 'originalFilename',
    component: 'JInput'
  }
];
