import { DataTransferField } from '@dvn/core/doldurma/src/fields/query-include/data-transfer-field';
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 formViewOrganisationAdminAdd from './form-view-organisation-admin-add';
import * as formViewOrganisationAdminRemove from './form-view-organisation-admin-remove';
export const ID = 'table-list-view-organisation-admins';
export const organisationTableListViewUIConfig = TableListViewConfig.decode({
  header: {
    actions: [{
        ui: {
          name: 'add-admin',
          buttonType: 'button',
          label: 'Add New'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: ViewPlacement.Dialog,
          viewId: formViewOrganisationAdminAdd.ID,
          params: {
            conversionConfig: {
              'organisationId': 'organisationId',
              'organisationDomain': 'organisationDomain',
            }
          }
        }
      }],
  },
  leanedHorizontally: false,
  main: {
    actions: [
      {
        ui: {
          name: 'remove-admins',
          buttonType: 'icon-button',
          iconName: 'uil uil-trash-alt',
          tint: 'danger',
          view: 'flat'
        },
        data: {
          type: 'navigation',
          direction: 'forward',
          placement: ViewPlacement.Dialog,
          viewId: formViewOrganisationAdminRemove.ID,
          params: {
            conversionConfig: {
              'item': 'admin',
              'organisationDomain': 'organisationDomain',
            }
          }
        }
      },
    ],
    fields: [
      { fieldId: 'imageUrl' },
      { fieldId: 'firstName' },
      { fieldId: 'lastName' },
      { fieldId: 'email' },
    ],
    columns: {
      firstName: {
        width: 150,
      },
      imageUrl: {
        width: 50,
      },
      lastName: {
        width: 150,
      },
    },
  },
});
export const viewConfig = TableListViewConfig.decode({
  _id: ID,
  type: AppViewType.ListViewTable,
  base: 'mentornity',
  title: 'Admins',
  space: spaces['mentornity'],
  table: dataConfigs['users'],
  query: {
    fields: [
      new DataTransferField('imageUrl'),
      new DataTransferField('firstName'),
      new DataTransferField('lastName'),
      new DataTransferField('email'),
    ],
    filter: {
      comparison: Comparison.Eq,
      id: '_roles',
      value: 'admin@+$organisationDomain',
    },
    sort: [{ id: 'firstName', order: 1 }]
  },
  ui: organisationTableListViewUIConfig,
  params: {
    organisationDomain: {
      required: true,
    },
    organisationId: {
      required: true,
    },
  },
});
