import { createElement, lazy } from 'react'

const DocumentTemplateInfo = lazy(
  () =>
    import('../../components/Dashboard/Management/DocumentTemplates/DocumentTemplateInfo')
)
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 DesignIcon from '../../components/Icons/DesignIcon'
import DocumentTemplateIcon from '../../components/Icons/DocumentTemplateIcon'

export const DocumentTemplate = {
  name: 'documentTemplate',
  label: 'Document Template',
  labelPlural: 'Document Templates',
  url: '/dashboard/management/documenttemplates',
  prefix: 'DTP',
  icon: DocumentTemplateIcon,
  actions: [
    {
      name: 'design',
      label: 'Design',
      row: true,
      icon: DesignIcon,
      url: (_id) =>
        `/dashboard/management/documenttemplates/design?documentTemplateId=${_id}`
    },
    {
      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(DocumentTemplateInfo)
    }
  ],
  columns: [
    '_reference',
    'name',
    'active',
    'global',
    'objectType',
    'tags',
    'parent',
    'documentSize',
    'createdAt',
    'updatedAt'
  ],
  filters: [
    'name',
    'tags',
    'active',
    'global',
    'parent',
    'documentSize',
    'objectType',
    'createdAt',
    'updatedAt',
    '_reference'
  ],
  group: ['documentSize', 'tags'],
  sorters: [
    'name',
    'parent',
    'documentSize',
    'createdAt',
    'updatedAt',
    'active',
    'global',
    'objectType'
  ],
  properties: [
    {
      name: '_id',
      label: 'ID',
      type: 'id',
      objectType: 'documentTemplate',
      showCopy: true,
      columnWidth: 140
    },
    {
      name: 'createdAt',
      label: 'Created At',
      type: 'dateTime',
      readOnly: true,
      columnWidth: 175
    },
    {
      name: '_reference',
      label: 'Reference',
      type: 'reference',
      columnFixed: 'left',
      objectType: 'documentTemplate',
      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: 'objectType',
      label: 'Object Type',
      required: true,
      type: 'objectType',
      columnWidth: 150,
      empty: (documentTemplate) => {
        return documentTemplate.global
      }
    },
    {
      name: 'active',
      label: 'Active',
      required: true,
      type: 'bool',
      columnWidth: 125
    },
    {
      name: 'tags',
      label: 'Tags',
      required: false,
      type: 'tags',
      columnWidth: 200
    },
    {
      name: 'global',
      label: 'Global',
      required: true,
      type: 'bool',
      columnWidth: 150
    },
    {
      name: 'documentSize',
      label: 'Document Size',
      required: true,
      type: 'object',
      objectType: 'documentSize',
      showHyperlink: true,
      columnWidth: 200
    },
    {
      name: 'parent',
      label: 'Parent',
      required: false,
      type: 'object',
      masterFilter: { global: true, active: true },
      objectType: 'documentTemplate',
      showHyperlink: true,
      columnWidth: 200,
      empty: (documentTemplate) => {
        return documentTemplate.global
      }
    },
    {
      name: 'documentPrinters',
      label: 'Document Printers',
      required: false,
      type: 'objectList',
      objectType: 'documentPrinter'
    },
    {
      name: 'content',
      label: 'Content',
      required: false,
      type: 'codeBlock',
      language: 'fcTemplateLang'
    },
    {
      name: 'testObject',
      label: 'Test Object',
      required: false,
      type: 'codeBlock',
      language: 'json'
    }
  ]
}
