import { createElement, lazy } from 'react'

const VendorInfo = lazy(
  () => import('../../components/Dashboard/Management/Vendors/VendorInfo')
)
import VendorIcon from '../../components/Icons/VendorIcon'
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
import EditIcon from '../../components/Icons/EditIcon'
import CheckIcon from '../../components/Icons/CheckIcon'
import XMarkIcon from '../../components/Icons/XMarkIcon'
import BinIcon from '../../components/Icons/BinIcon'

export const Vendor = {
  name: 'vendor',
  label: 'Vendor',
  labelPlural: 'Vendors',
  url: '/dashboard/management/vendors',
  prefix: 'VEN',
  icon: VendorIcon,
  actions: [
    {
      name: 'info',
      type: 'page',
      pageName: 'info',
      label: 'Info',
      default: true,
      row: true,
      icon: InfoCircleIcon
    },
    {
      name: 'edit',
      type: 'page',
      pageName: 'info',
      label: 'Edit',
      row: true,
      icon: EditIcon,
      visible: (objectData) => {
        return !(objectData?._isEditing && objectData?._isEditing == true)
      }
    },
    {
      name: 'cancelEdit',
      label: 'Cancel Edits',
      type: 'page',
      pageName: 'info',
      icon: XMarkIcon,
      visible: (objectData) => {
        return objectData?._isEditing && objectData?._isEditing == true
      }
    },
    {
      name: 'finishEdit',
      label: 'Save Edits',
      type: 'page',
      pageName: 'info',
      icon: CheckIcon,
      visible: (objectData) => {
        return objectData?._isEditing && objectData?._isEditing == true
      }
    },
    { type: 'divider' },
    {
      name: 'delete',
      type: 'page',
      pageName: 'info',
      label: 'Delete',
      icon: BinIcon,
      danger: true
    }
  ],
  pages: [
    {
      name: 'info',
      content: () => createElement(VendorInfo)
    }
  ],
  columns: [
    '_reference',
    'name',
    'country',
    'email',
    'website',
    'active',
    'createdAt',
    'updatedAt'
  ],
  filters: [
    'country',
    'active',
    'createdAt',
    'updatedAt',
    'name',
    '_reference'
  ],
  sorters: [
    'name',
    'country',
    'email',
    'active',
    'createdAt',
    'updatedAt',
    '_id'
  ],
  group: ['country'],
  properties: [
    {
      name: '_id',
      label: 'ID',
      columnFixed: 'left',
      type: 'id',
      objectType: 'vendor',
      showCopy: true,
      columnWidth: 140
    },
    {
      name: 'createdAt',
      label: 'Created At',
      type: 'dateTime',
      readOnly: true,
      columnWidth: 175
    },
    {
      name: '_reference',
      label: 'Reference',
      type: 'reference',
      columnFixed: 'left',
      objectType: 'vendor',
      showCopy: true,
      readOnly: true,
      columnWidth: 180
    },
    {
      name: 'name',
      label: 'Name',
      columnFixed: 'left',
      required: true,
      type: 'text',
      columnWidth: 200
    },
    {
      name: 'updatedAt',
      label: 'Updated At',
      type: 'dateTime',
      readOnly: true,
      columnWidth: 175
    },
    {
      name: 'contact',
      label: 'Contact',
      type: 'text',
      readOnly: false,
      required: false,
      columnWidth: 150
    },
    {
      name: 'active',
      label: 'Active',
      type: 'bool',
      readOnly: false,
      required: true,
      columnWidth: 125
    },
    {
      name: 'country',
      label: 'Country',
      type: 'country',
      readOnly: false,
      required: true,
      columnWidth: 150
    },
    {
      name: 'email',
      label: 'Email',
      columnWidth: 300,
      type: 'email',
      readOnly: false,
      required: false
    },
    {
      name: 'phone',
      label: 'Phone',
      type: 'phone',
      readOnly: false,
      required: false,
      columnWidth: 140
    },
    {
      name: 'website',
      label: 'Website',
      columnWidth: 300,
      type: 'url',
      readOnly: false,
      required: false
    },
    {
      name: 'address',
      label: 'Address',
      type: 'address',
      readOnly: false,
      required: false,
      columnWidth: 250
    }
  ]
}
