import { createElement, lazy } from 'react'

const StockAuditInfo = lazy(
  () => import('../../components/Dashboard/Inventory/StockAudits/StockAuditInfo')
)
import StockAuditIcon from '../../components/Icons/StockAuditIcon'
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
import EditIcon from '../../components/Icons/EditIcon'
import CheckIcon from '../../components/Icons/CheckIcon'
import XMarkIcon from '../../components/Icons/XMarkIcon'

export const StockAudit = {
  name: 'stockAudit',
  label: 'Stock Audit',
  labelPlural: 'Stock Audits',
  url: '/dashboard/inventory/stockaudits',
  prefix: 'SAU',
  icon: StockAuditIcon,
  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
      }
    },
  ],
  pages: [
    {
      name: 'info',
      content: () => createElement(StockAuditInfo)
    }
  ],
  columns: ['_reference', 'state', 'createdAt', 'updatedAt'],
  filters: [
    'status',
    'type',
    'createdBy',
    'state',
    'createdAt',
    'updatedAt',
    '_reference'
  ],
  sorters: ['createdAt','updatedAt','state'],
  group: ['state'],
  properties: [
    {
      name: '_id',
      label: 'ID',
      type: 'id',
      objectType: 'stockAudit',
      showCopy: true,
      readOnly: true,
      columnWidth: 140
    },
    {
      name: 'createdAt',
      label: 'Created At',
      type: 'dateTime',
      readOnly: true,
      columnWidth: 175
    },
    {
      name: '_reference',
      label: 'Reference',
      type: 'reference',
      columnFixed: 'left',
      objectType: 'stockAudit',
      showCopy: true,
      readOnly: true,
      columnWidth: 180
    },
    {
      name: 'state',
      label: 'State',
      type: 'state',
      readOnly: true,
      columnWidth: 260
    },
    {
      name: 'updatedAt',
      label: 'Updated At',
      type: 'dateTime',
      readOnly: true,
      columnWidth: 175
    }
  ]
}
