import { DvnDataAdapter } from '@dvn/core/adapters/DvnDataAdapter';
import { AttachmentField } from '@dvn/core/doldurma/src/fields/attachment';
import { NestedField } from '@dvn/core/doldurma/src/fields/nested/nested';
import { DataTransferField } from '@dvn/core/doldurma/src/fields/query-include/data-transfer-field';
import { ReferenceField } from '@dvn/core/doldurma/src/fields/reference';
import { SingleChoiceField, SingleChoiceFieldOption } from '@dvn/core/doldurma/src/fields/single-choice';
import { TextField } from '@dvn/core/doldurma/src/fields/text';
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';
export const ID = 'table-list-view-session';
export const config = (dataApi) => TableListViewConfig.decode({
  _id: ID,
  type: AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'User Sessions',
  space: spaces['mentornity'],
  table: dataConfigs['sessions'],
  query: {
    fields: [
      new DataTransferField('client'),
      new DataTransferField('createdAt'),
      new DataTransferField('updatedAt'),
      new DataTransferField('failureReason'),
      new DataTransferField('status'),
      new ReferenceField('user', 'User', 'firstName', 'imageUrl', 'users', [
        new AttachmentField('imageUrl', ''),
        new TextField('email', 'Email'),
        new TextField('firstName', 'First Name'),
        new TextField('lastName', 'Last Name'),
      ], true),
    ],
    sort: [{ id: 'updatedAt', order: -1 }]
  },
  ui: TableListViewConfig.decode({
    header: {
      actions: [],
    },
    main: {
      actions: [],
      fields: [
        {
          fieldId: 'user.imageUrl',
          fieldDisplay: new NestedField('user.imageUrl', new AttachmentField('imageUrl', '').setShape('circle'))
        },
        {
          fieldId: 'user.firstName',
          fieldDisplay: new NestedField('user.firstName', new TextField('firstName', 'First Name'))
        },
        {
          fieldId: 'user.lastName',
          fieldDisplay: new NestedField('user.lastName', new TextField('lastName', 'Last Name'))
        },
        {
          fieldId: 'user.email',
          fieldDisplay: new NestedField('user.email', new TextField('email', 'Email'))
        },
        { fieldId: 'createdAt' },
        { fieldId: 'updatedAt' },
        { fieldId: 'client' },
        { fieldId: 'status' },
        { fieldId: 'failureReason' },
      ],
      columns: {
        'user.imageUrl': {
          width: 50,
        },
        'user.firstName': {
          width: 120,
        },
        'user.lastName': {
          width: 120,
        },
        'user.email': {
          width: 240,
        },
        createdAt: {
          width: 150,
        },
        updatedAt: {
          width: 150,
        },
        status: {
          width: 150,
        },
        client: {
          width: 120,
        },
        failureReason: {
          weight: 1,
          width: 240,
        },
      },
    },
    quickSearch: {
      fields: [
        {
          field: new SingleChoiceField('user._id', 'Search user', undefined, '', 'select').setDataProvider(userDataProvider(dataApi))
            .setDataAdapter(new DvnDataAdapter('firstName+lastName', '_id')),
        },
        {
          field: new SingleChoiceField('status', 'Status', [
            new SingleChoiceFieldOption('Successful', 'successful'),
            new SingleChoiceFieldOption('Failed', 'failed'),
            new SingleChoiceFieldOption('Logged Out', 'loggedOut'),
          ]),
        }
      ],
      fieldUIConfigs: [
        {
          fieldId: 'user._id',
          width: '240px',
        },
        {
          fieldId: 'status',
          width: '150px',
        },
      ],
    },
  }),
});
