import { createElement, lazy } from 'react'

const NoteTypeInfo = lazy(
  () => import('../../components/Dashboard/Management/NoteTypes/NoteTypeInfo')
)
import NoteTypeIcon from '../../components/Icons/NoteTypeIcon'
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 NoteType = {
  name: 'noteType',
  label: 'Note Type',
  labelPlural: 'Note Types',
  url: '/dashboard/management/notetypes',
  prefix: 'NTY',
  icon: NoteTypeIcon,
  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(NoteTypeInfo)
    }
  ],
  columns: ['_reference', 'name', 'color', 'active', 'createdAt', 'updatedAt'],
  filters: [
    'name',
    '_id',
    'color',
    'active',
    'createdAt',
    'updatedAt',
    '_reference'
  ],
  sorters: ['name', 'color', 'active', 'createdAt', 'updatedAt'],
  properties: [
    {
      name: '_id',
      label: 'ID',
      type: 'id',
      objectType: 'noteType',
      showCopy: true,
      columnWidth: 140
    },
    {
      name: 'createdAt',
      label: 'Created At',
      type: 'dateTime',
      readOnly: true,
      columnWidth: 175
    },
    {
      name: '_reference',
      label: 'Reference',
      type: 'reference',
      columnFixed: 'left',
      objectType: 'noteType',
      showCopy: true,
      readOnly: true,
      columnWidth: 180
    },
    {
      name: 'name',
      label: 'Name',
      required: true,
      type: 'text',
      columnWidth: 200,
      columnFixed: 'left'
    },
    {
      name: 'updatedAt',
      label: 'Updated At',
      type: 'dateTime',
      readOnly: true,
      columnWidth: 175
    },
    {
      name: 'color',
      label: 'Color',
      required: false,
      type: 'color',
      columnWidth: 120
    },
    {
      name: 'active',
      label: 'Active',
      required: true,
      type: 'bool',
      columnWidth: 125
    }
  ]
}
