import FileIcon from '../../components/Icons/FileIcon'
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
import EditIcon from '../../components/Icons/EditIcon'
import ReloadIcon from '../../components/Icons/ReloadIcon'
import BinIcon from '../../components/Icons/BinIcon'

export const File = {
  name: 'file',
  label: 'File',
  prefix: 'FLE',
  icon: FileIcon,
  actions: [
    {
      name: 'info',
      label: 'Info',
      default: true,
      row: true,
      icon: InfoCircleIcon,
      url: (_id) => `/dashboard/management/files/info?fileId=${_id}`
    },
    {
      name: 'reload',
      label: 'Reload',
      icon: ReloadIcon,
      url: (_id) =>
        `/dashboard/management/files/info?fileId=${_id}&action=reload`
    },
    {
      name: 'edit',
      label: 'Edit',
      row: true,
      icon: EditIcon,
      url: (_id) => `/dashboard/management/files/info?fileId=${_id}&action=edit`
    },
    { type: 'divider' },
    {
      name: 'delete',
      label: 'Delete',
      icon: BinIcon,
      danger: true,
      url: (_id) =>
        `/dashboard/management/files/info?fileId=${_id}&action=delete`
    }
  ],
  url: (id) => `/dashboard/management/files/info?fileId=${id}`,
  columns: ['name', '_id', 'type', 'size', 'temp', 'createdAt'],
  filters: ['name', '_id', 'type', 'temp'],
  sorters: ['name', 'type', 'size', 'createdAt', 'temp'],
  group: ['type'],
  properties: [
    {
      name: '_id',
      label: 'ID',
      columnFixed: 'left',
      type: 'id',
      objectType: 'file',
      showCopy: true
    },
    {
      name: 'createdAt',
      label: 'Created At',
      type: 'dateTime',
      readOnly: true
    },
    {
      name: 'name',
      label: 'Name',
      columnFixed: 'left',
      required: true,
      type: 'text'
    },
    {
      name: 'updatedAt',
      label: 'Updated At',
      type: 'dateTime',
      readOnly: true
    },
    {
      name: 'type',
      label: 'Type',
      type: 'text',
      readOnly: true,
      required: true
    },
    {
      name: 'size',
      label: 'Size',
      type: 'number',
      readOnly: true,
      required: true,
      suffix: (objectData) => {
        const size = objectData?.size || 0
        if (size === 0) return ' B'
        if (size < 1024) return ' B'
        if (size < 1024 * 1024) return ' KB'
        if (size < 1024 * 1024 * 1024) return ' MB'
        if (size < 1024 * 1024 * 1024 * 1024) return ' GB'
        return ' TB'
      },
      value: (objectData) => {
        const size = objectData?.size || 0
        if (size === 0) return 0
        if (size < 1024) return size
        if (size < 1024 * 1024) return size / 1024
        if (size < 1024 * 1024 * 1024) return size / (1024 * 1024)
        if (size < 1024 * 1024 * 1024 * 1024) return size / (1024 * 1024 * 1024)
        return size / (1024 * 1024 * 1024 * 1024)
      }
    },
    {
      name: 'metaData',
      label: 'Meta Data',
      columnWidth: 300,
      type: 'data',
      readOnly: true,
      required: false
    }
  ]
}
