import ProductIcon from '../../components/Icons/ProductIcon'
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
import ReloadIcon from '../../components/Icons/ReloadIcon'
import EditIcon from '../../components/Icons/EditIcon'

export const Product = {
  name: 'product',
  label: 'Product',
  prefix: 'PRD',
  icon: ProductIcon,
  actions: [
    {
      name: 'info',
      label: 'Info',
      default: true,
      row: true,
      icon: InfoCircleIcon,
      url: (_id) => `/dashboard/management/products/info?productId=${_id}`
    },
    {
      name: 'reload',
      label: 'Reload',
      icon: ReloadIcon,
      url: (_id) =>
        `/dashboard/management/products/info?productId=${_id}&action=reload`
    },
    {
      name: 'edit',
      label: 'Edit',
      row: true,
      icon: EditIcon,
      url: (_id) =>
        `/dashboard/management/products/info?productId=${_id}&action=edit`
    }
  ],
  columns: [
    '_id',
    'name',
    'tags',
    'vendor',
    'vendor._id',
    'price',
    'createdAt',
    'updatedAt'
  ],
  filters: ['_id', 'name', 'type', 'color', 'cost', 'vendor', 'vendor._id'],
  sorters: ['name', 'createdAt', 'type', 'vendor', 'cost', 'updatedAt'],
  properties: [
    {
      name: '_id',
      label: 'ID',
      type: 'id',
      objectType: 'product',
      showCopy: true,
      readOnly: true
    },
    {
      name: 'createdAt',
      label: 'Created At',
      type: 'dateTime',
      readOnly: true
    },
    {
      name: 'name',
      label: 'Name',
      required: true,
      type: 'text'
    },
    {
      name: 'updatedAt',
      label: 'Updated At',
      type: 'dateTime',
      readOnly: true
    },
    {
      name: 'vendor',
      label: 'Vendor',
      required: true,
      type: 'object',
      objectType: 'vendor'
    },
    {
      name: 'vendor._id',
      label: 'Vendor ID',
      readOnly: true,
      type: 'id',
      showHyperlink: true,
      objectType: 'vendor'
    },
    {
      name: 'version',
      label: 'Version',
      type: 'text'
    },
    {
      name: 'tags',
      label: 'Tags',
      type: 'tags'
    },
    {
      name: 'priceMode',
      label: 'Price Mode',
      type: 'priceMode'
    },
    {
      name: 'margin',
      label: 'Margin',
      type: 'number',
      disabled: (objectData) => {
        return objectData.priceMode == 'amount'
      },
      suffix: '%',
      min: 0,
      max: 100,
      step: 0.01
    },
    {
      name: 'amount',
      label: 'Amount',
      disabled: (objectData) => {
        return objectData.priceMode == 'margin'
      },
      type: 'number',
      prefix: '£',
      min: 0,
      step: 0.1
    }
  ]
}
