import { DvnDataAdapter } from '@dvn/core/adapters/DvnDataAdapter';
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 { DataTransferField } from '@dvn/core/doldurma/src/fields/query-include/data-transfer-field';
import { SingleChoiceField, SingleChoiceFieldOption } from '@dvn/core/doldurma/src/fields/single-choice';
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 { userDataProvider } from '../data-provider-configs';
import { spaces } from '../spaces';
import * as detailViewScheduledJobSendEmail from './detail-view-scheduled-job-send-email';
export const ID = 'table-list-view-scheduled-job-sync-events-google';
export const config = (dataApi) => TableListViewConfig.decode({
  _id: ID,
  type: AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Sync Google Events Jobs',
  space: spaces['mentornity'],
  table: dataConfigs['scheduledjobs'],
  query: {
    fields: [
      new TextField('name', 'Name'),
      new TextField('status', 'Status'),
      new DateField('scheduledAt', 'Created At'),
      new DateField('createdAt', 'Created At'),
      new DataTransferField('parameters'),
      new DataTransferField('metadata'),
    ],
    filter: {
      filters: [
        {
          comparison: Comparison.Eq,
          id: 'name',
          value: 'CreateEventInGoogle',
        },
      ],
      operator: 'or'
    },
    sort: [{ id: 'createdAt', order: -1 }]
  },
  ui: 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: detailViewScheduledJobSendEmail.ID,
            params: {
              conversionConfig: {
                'item._id': 'itemId',
              }
            }
          }
        }],
      fields: [
        {
          fieldId: 'createdAt',
          fieldDisplay: new DateField('createdAt', 'Date').setDateFormat('DD MMM YYYY').setDataType(DateDataType.Unix),
        },
        {
          fieldId: 'createdAt',
          fieldDisplay: new DateField('createdAt', 'Hour').setDateFormat('HH:mm').setDataType(DateDataType.Unix),
        },
        {
          fieldId: 'parameters.googleEvent.summary',
          fieldDisplay: new NestedField('parameters.googleEvent.summary', new TextField('summary', 'Summary')),
        },
        {
          fieldId: 'parameters.googleEvent.start.dateTime',
          fieldDisplay: new NestedField('parameters.googleEvent.start.dateTime', new DateField('meetingStart', 'Meeting Start').setDateFormat('DD MMM HH:mm')),
        },
        {
          fieldId: 'parameters.googleEvent.end.dateTime',
          fieldDisplay: new NestedField('parameters.googleEvent.end.dateTime', new DateField('meetingEnd', 'Meeting End').setDateFormat('DD MMM HH:mm')),
        },
        {
          fieldId: 'status',
        },
      ],
      columns: {
        createdAt: {
          width: 120,
        },
        'parameters.googleEvent.start.dateTime': {
          width: 150,
        },
        'parameters.googleEvent.end.dateTime': {
          width: 150,
        },
        status: {
          width: 100,
        },
      },
    },
    quickSearch: {
      fields: [
        {
          field: new SingleChoiceField('parameters.userId', 'Search user', undefined, 'Search and select admins.', 'select').setDataProvider(userDataProvider(dataApi))
            .setDataAdapter(new DvnDataAdapter('firstName+lastName', '_id')),
        },
        {
          field: new SingleChoiceField('status', 'Status', [
            new SingleChoiceFieldOption('Done', 'done'),
            new SingleChoiceFieldOption('Failed', 'failed'),
          ]),
        }
      ],
      ui: {
        'parameters.userId': {
          width: '256px',
        }
      },
      requireFilters: false,
    },
  }),
});
