import { createElement, lazy } from 'react'

const StockLocationInfo = lazy(
  () => import('../../components/Dashboard/Inventory/StockLocations/StockLocationInfo')
)
import StockLocationIcon from '../../components/Icons/StockLocationIcon'
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 StockLocation = {
  name: 'stockLocation',
  label: 'Stock Location',
  labelPlural: 'Stock Locations',
  url: '/dashboard/inventory/stocklocations',
  prefix: 'SLN',
  icon: StockLocationIcon,
  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(StockLocationInfo)
    }
  ],
  filters: ['name','createdAt','updatedAt','_reference'],
  sorters: ['name','createdAt','updatedAt'],
  columns: ['_reference', 'name', 'address', 'createdAt', 'updatedAt'],
  properties: [
    {
      name: '_id',
      label: 'ID',
      type: 'id',
      objectType: 'stockLocation',
      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: 'stockLocation',
      showCopy: true,
      readOnly: true,
      columnWidth: 180
    },
    {
      name: 'updatedAt',
      label: 'Updated At',
      type: 'dateTime',
      readOnly: true,
      columnWidth: 175
    },
    {
      name: 'name',
      label: 'Name',
      type: 'text',
      required: true,
      columnWidth: 220
    },
    {
      name: 'address',
      label: 'Address',
      type: 'address',
      readOnly: false,
      required: true,
      columnWidth: 250
    }
  ],
  stats: [
    {
      name: 'total.count',
      label: 'Locations',
      type: 'number',
      color: 'default'
    }
  ]
}
