import { createElement, lazy } from 'react'

const TaxRecordInfo = lazy(
  () => import('../../components/Dashboard/Finance/TaxRecords/TaxRecordInfo')
)
import TaxRecordIcon from '../../components/Icons/TaxRecordIcon'
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 TaxRecord = {
  name: 'taxRecord',
  label: 'Tax Record',
  labelPlural: 'Tax Records',
  url: '/dashboard/finance/taxrecords',
  prefix: 'TXR',
  icon: TaxRecordIcon,
  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(TaxRecordInfo)
    }
  ],
  columns: [
    '_reference',
    'taxRate',
    'transactionType',
    'transaction',
    'amount',
    'taxAmount',
    'transactionDate',
    'createdAt',
    'updatedAt'
  ],
  filters: [
    'taxRate',
    'transactionType',
    'transaction',
    'transactionDate',
    'createdAt',
    'updatedAt',
    '_reference'
  ],
  sorters: [
    'transactionDate',
    'amount',
    'taxAmount',
    'createdAt',
    '_id',
    'updatedAt'
  ],
  group: ['transactionType'],
  properties: [
    {
      name: '_id',
      label: 'ID',
      columnFixed: 'left',
      type: 'id',
      objectType: 'taxRecord',
      showCopy: true,
      columnWidth: 140
    },
    {
      name: 'createdAt',
      label: 'Created At',
      type: 'dateTime',
      readOnly: true,
      columnWidth: 175
    },
    {
      name: '_reference',
      label: 'Reference',
      type: 'reference',
      columnFixed: 'left',
      objectType: 'taxRecord',
      showCopy: true,
      readOnly: true,
      columnWidth: 180
    },
    {
      name: 'taxRate',
      label: 'Tax Rate',
      required: true,
      type: 'object',
      objectType: 'taxRate',
      showHyperlink: true,
      columnWidth: 150
    },
    {
      name: 'transactionType',
      label: 'Transaction Type',
      required: true,
      type: 'select',
      columnWidth: 175,
      options: [
        { label: 'Purchase Order', value: 'purchaseOrder' },
        { label: 'Sales Order', value: 'salesOrder' },
        { label: 'Other', value: 'other' }
      ]
    },
    {
      name: 'transaction',
      label: 'Transaction',
      required: true,
      type: 'object',
      objectType: (objectData) => {
        return objectData?.transactionType || 'purchaseOrder'
      },
      showHyperlink: true,
      columnWidth: 200
    },
    {
      name: 'amount',
      label: 'Amount',
      required: true,
      type: 'currency',
      min: 0,
      step: 0.01,
      columnWidth: 125
    },
    {
      name: 'taxAmount',
      label: 'Tax Amount',
      required: true,
      type: 'currency',
      min: 0,
      step: 0.01,
      columnWidth: 125
    },
    {
      name: 'transactionDate',
      label: 'Transaction Date',
      required: true,
      type: 'date',
      columnWidth: 175,
      default: () => new Date()
    },
    {
      name: 'updatedAt',
      label: 'Updated At',
      type: 'dateTime',
      readOnly: true
    }
  ]
}
