import { DateField } from '@dvn/core/doldurma/src/fields/date';
import { DateDataType } from '@dvn/core/doldurma/src/fields/date/date';
import { DataTransferField } from '@dvn/core/doldurma/src/fields/query-include/data-transfer-field';
import { ReferenceField } from '@dvn/core/doldurma/src/fields/reference';
import { ViewPlacement } from '@dvn/core/models/app-config';
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 formViewWhiteLabelCreate from './form-view-white-label-create';
import * as formViewWhiteLabelDelete from './form-view-white-label-delete';
import * as formViewWhiteLabelEdit from './form-view-white-label-edit';
import * as formViewWhiteLabelThemeEdit from './form-view-white-label-theme-edit';
export const ID = 'table-list-view-white-label';
export const viewConfig = TableListViewConfig.decode({
  _id: ID,
  type: AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'White Labels',
  space: spaces['mentornity'],
  table: dataConfigs['whiteLabels'],
  query: {
    fields: [
      new DataTransferField('title'),
      new DataTransferField('domain'),
      new ReferenceField('organisations', 'Organisations', 'title', 'logoUrl', 'organisations', [
        new DataTransferField('logoUrl'),
        new DataTransferField('title'),
      ]),
      new DataTransferField('createdAt'),
    ],
    sort: [{ id: 'title', order: 1 }]
  },
  ui: TableListViewConfig.decode({
    header: {
      actions: [{
          ui: {
            name: 'new-white-label',
            buttonType: 'button',
            label: 'Create New'
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: ViewPlacement.Dialog,
            viewId: formViewWhiteLabelCreate.ID,
          }
        }],
    },
    main: {
      actionsPlacement: 'left',
      actions: [
        {
          ui: {
            name: 'view-whitelabel',
            buttonType: 'icon-button',
            iconName: 'uil uil-cog',
            view: 'flat'
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: ViewPlacement.SideModal,
            viewId: formViewWhiteLabelEdit.ID,
            params: {
              conversionConfig: {
                'item._id': 'itemId',
              }
            }
          }
        },
        {
          ui: {
            name: 'edit-palette',
            buttonType: 'icon-button',
            iconName: 'uil uil-palette',
            view: 'flat'
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: ViewPlacement.SideModal,
            viewId: formViewWhiteLabelThemeEdit.ID,
            params: {
              conversionConfig: {
                'item._id': 'itemId',
              }
            }
          }
        },
        {
          ui: {
            name: 'delete-whitelabel',
            buttonType: 'icon-button',
            iconName: 'uil uil-trash-alt',
            view: 'flat',
            tint: 'danger'
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: ViewPlacement.Dialog,
            viewId: formViewWhiteLabelDelete.ID,
            params: {
              conversionConfig: {
                'item._id': 'itemId',
              }
            }
          }
        },
      ],
      fields: [
        { fieldId: 'title' },
        { fieldId: 'domain' },
        { fieldId: 'organisations', isEditable: true },
        {
          fieldId: 'createdAt',
          fieldDisplay: new DateField('createdAt', 'Date').setDateFormat('DD MMM YYYY').setDataType(DateDataType.Unix),
        },
      ],
      columns: {
        domain: {
          weight: 1,
        },
        title: {
          weight: 1,
        },
        createdAt: {
          width: 150,
        },
      },
    },
  }),
});
