import { DateField } from '@dvn/core/doldurma/src/fields/date';
import { DateDataType } from '@dvn/core/doldurma/src/fields/date/date';
import { NestedField } from '@dvn/core/doldurma/src/fields/nested/nested';
import { TextField } from '@dvn/core/doldurma/src/fields/text';
import { ViewPlacement } from '@dvn/core/models/app-config';
import { Comparison } from '@dvn/core/models/filter';
import { TableListViewConfig } from '@dvn/core/models/table-list-view-config';
import { AppViewType } from '@dvn/core/models/view-config';
import { dataConfigs } from '../data-configs';
import { spaces } from '../spaces';
import * as detailViewFormResponse from './detail-view-form-response';
export const ID = 'table-list-view-form-response-contact';
export const formTableListViewUIConfig = TableListViewConfig.decode({
  main: {
    actions: [{
        ui: {
          name: 'expand',
          buttonType: 'icon-button',
          iconName: 'uil uil-expand-alt',
          view: 'flat'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: ViewPlacement.SideModal,
          viewId: detailViewFormResponse.ID,
          params: {
            conversionConfig: {
              'item._id': 'itemId',
            }
          }
        }
      }],
    fields: [
      {
        fieldId: 'createdAt',
        fieldDisplay: new DateField('createdAt', 'Date').setDateFormat('DD MMM HH:mm').setDataType(DateDataType.Unix),
      },
      {
        fieldId: 'data.phone',
        fieldDisplay: new NestedField('data.phone', new TextField('phone', 'Phone')),
      },
      {
        fieldId: 'data.email',
        fieldDisplay: new NestedField('data.email', new TextField('email', 'Email')),
      },
      {
        fieldId: 'data.fullName',
        fieldDisplay: new NestedField('data.fullName', new TextField('name', 'Name')),
      },
      {
        fieldId: 'data.message',
        fieldDisplay: new NestedField('data.message', new TextField('message', 'Message')),
      },
    ],
    columns: {
      createdAt: {
        width: 120,
      },
      'data.phone': {
        width: 140,
      },
      'data.email': {
        width: 200,
      },
      'data.fullName': {
        width: 180,
      },
      'data.message': {
        weight: 1,
        width: 200,
      },
    },
  },
  quickSearch: {
    fields: [
      { field: new TextField('data.name', 'Name') },
      { field: new TextField('data.email', 'Email') },
      { field: new TextField('data.message', 'Message') },
    ]
  },
});
export const viewConfig = TableListViewConfig.decode({
  _id: ID,
  type: AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Contact Forms',
  space: spaces['mentornity'],
  table: dataConfigs['formResponses'],
  query: {
    fields: [
      new DateField('createdAt', 'Created At'),
      new TextField('data', 'Data'),
      new TextField('type', 'type'),
    ],
    filter: {
      filters: [
        {
          comparison: Comparison.Eq,
          id: 'type',
          value: 'contact',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: formTableListViewUIConfig,
});
