import { BooleanField } from '@dvn/core/doldurma/src/fields/boolean';
import { NestedField } from '@dvn/core/doldurma/src/fields/nested/nested';
import { DataTransferField } from '@dvn/core/doldurma/src/fields/query-include/data-transfer-field';
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 { damgaSpace, dataConfigs } from '../data-configs';
import * as formViewDomainCreate from './form-view-domain-create';
import * as formViewDomainUpdate from './form-view-domain-update';
import * as formViewDomainMove from './form-view-domain-move';
import * as formViewDomainDelete from './form-view-domain-delete';
export const ID = 'table-list-view-domain';
export const viewConfig = (productId) => TableListViewConfig.decode({
  _id: ID,
  type: AppViewType.ListViewTable,
  base: 'devingen-dev',
  title: 'Domains',
  space: damgaSpace,
  table: dataConfigs['damga-domains'],
  query: {
    fields: [
      new DataTransferField('_created'),
      new DataTransferField('domain'),
      new DataTransferField('target'),
    ],
    filter: {
      comparison: Comparison.EqMongoOID,
      id: 'product._id',
      value: productId,
    },
    sort: [{ id: 'domain', order: 1 }]
  },
  ui: TableListViewConfig.decode({
    header: {
      actions: [{
          ui: {
            name: 'new-domain-and-target',
            buttonType: 'button',
            label: 'Add New'
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: ViewPlacement.Dialog,
            viewId: formViewDomainCreate.ID
          }
        }],
    },
    main: {
      actions: [
        {
          ui: {
            name: 'edit',
            label: 'Edit',
            buttonType: 'icon-button',
            iconName: 'uil uil-pen',
            view: 'flat'
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: ViewPlacement.Dialog,
            viewId: formViewDomainUpdate.ID,
            params: {
              conversionConfig: {
                'item._id': 'domainId',
                'item.domain': 'domain',
                'item.target.value': 'target',
                'item.target.overrideHost': 'overrideHost',
                'item.target.useTLS': 'useTLS',
              },
            }
          }
        },
        {
          ui: {
            name: 'move',
            label: 'Move to another product',
            buttonType: 'icon-button',
            iconName: 'uil uil-exchange-alt',
            view: 'flat'
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: ViewPlacement.Dialog,
            viewId: formViewDomainMove.ID,
            params: {
              conversionConfig: {
                'item._id': 'domainId',
              },
            }
          }
        },
        {
          ui: {
            name: 'delete',
            label: 'Delete domain',
            buttonType: 'icon-button',
            iconName: 'uil uil-trash',
            view: 'flat',
            tint: 'danger',
          },
          data: {
            type: 'navigation',
            direction: 'forward',
            placement: ViewPlacement.Dialog,
            viewId: formViewDomainDelete.ID,
            params: {
              conversionConfig: {
                'item._id': 'domainId',
              },
            }
          }
        },
      ],
      fields: [
        { fieldId: 'domain' },
        {
          fieldId: 'target.value',
          fieldDisplay: new NestedField('target.value', new TextField('value', 'Target')),
        },
        {
          fieldId: 'target.overrideHost',
          fieldDisplay: new NestedField('target.overrideHost', new BooleanField('overrideHost', 'Override Host')),
        },
        {
          fieldId: 'target.useTLS',
          fieldDisplay: new NestedField('target.useTLS', new BooleanField('useTLS', 'Use TLS')),
        },
        {
          fieldId: 'domain',
          fieldDisplay: new TextField('domain', 'DNS Record'),
          componentTag: 'devingen-product-damga-domain-table-list-dns-record',
        },
      ],
      columns: {
        'target.overrideHost': {
          width: 150,
        },
        'target.useTLS': {
          width: 150,
        },
      },
    },
  }),
});
