import { T as TextField } from './index-d9d18e9c.js';
import { r as registerInterceptor, I as InterceptorConfig, a as InterceptorHandler } from './InterceptorHandler-6474bcf4.js';
import { D as DataModel } from './data-model-bb5789f5.js';
import { B as BaseField } from './BaseField-d94c5b14.js';
import { R as ReferenceField } from './FieldModelGenerator-755e3a85.js';
import { D as DateField, a as DateDataType } from './date-b270be76.js';
import { S as SingleChoiceField, a as SingleChoiceFieldOption } from './index-a95fa2f4.js';
import { T as TableConfig } from './table-config-9f3dee34.js';
import { M as MembershipConfig } from './membership-config-1607e716.js';
import { D as DvnAppViewConfig } from './view-config-2a7feb02.js';
import { a as AttachmentField } from './attachment-8831acff.js';
import { s as spaces } from './spaces-8bb938bc.js';
import './index-c43f1f2e.js';

class RawDataField extends BaseField {
  constructor(id, title, description, dataType = 'json') {
    super(id, 'rawData');
    this.dataType = 'json';
    this.id = id;
    this.title = title;
    this.description = description;
    this.dataType = dataType;
  }
  showPreview() {
    this.preview = true;
    return this;
  }
  getDisplayValue(value) {
    return value;
  }
  setDataType(dataType) {
    this.dataType = dataType;
    return this;
  }
}
RawDataField.type = 'rawData';

class RelationReferenceField extends BaseField {
  constructor(id, title, titleField, imageField, relationCollection, nameInRelationCollection, otherCollection, nameOfOtherCollectionInRelationCollection, fields, otherCollectionFields) {
    super(id, 'relation-reference');
    this.title = title;
    this.titleField = titleField;
    this.imageField = imageField;
    this.relationCollection = relationCollection;
    this.nameInRelationCollection = nameInRelationCollection;
    this.otherCollection = otherCollection;
    this.nameOfOtherCollectionInRelationCollection = nameOfOtherCollectionInRelationCollection;
    this.fields = fields;
    this.otherCollectionFields = otherCollectionFields;
  }
  showPreview() {
    this.preview = true;
    return this;
  }
  getDisplayValue(value) {
    return value;
  }
}
RelationReferenceField.type = 'relation-reference';

const dataConfigs = {
  'auth': DataModel.decode({
    _id: 'auth',
    _created: new Date(),
    _updated: new Date(),
    base: 'mentornity',
    fields: [
      new DateField('createdAt', 'Created At')
        .setDataType(DateDataType.Unix)
        .setDateFormat('DD MMM YYYY HH:mm'),
      new RawDataField('google', 'Google'),
      new RawDataField('microsoft', 'Microsoft'),
      new RawDataField('zoom', 'Zoom'),
    ],
    name: 'auth',
    space: spaces['mentornity'],
  }),
  'formResponses': DataModel.decode({
    _id: 'formResponses',
    _created: new Date(),
    _updated: new Date(),
    base: 'mentornity',
    fields: [
      new DateField('createdAt', 'Created At')
        .setDataType(DateDataType.Unix)
        .setDateFormat('DD MMM YYYY HH:mm'),
      new RawDataField('data', 'Data'),
      new TextField('type', 'type'),
    ],
    name: 'formResponses',
    space: spaces['mentornity'],
  }),
  'configs': DataModel.decode({
    _id: 'configs',
    _created: new Date(),
    _updated: new Date(),
    base: 'mentornity',
    fields: [
      new DateField('createdAt', 'Created At').setDataType(DateDataType.Unix).setDateFormat('DD MMM YYYY'),
    ],
    name: 'configs',
    space: spaces['mentornity'],
  }),
  'organisations': DataModel.decode({
    _id: 'organisations',
    _created: new Date(),
    _updated: new Date(),
    base: 'mentornity',
    fields: [
      new RawDataField('_id', 'ID'),
      new DateField('createdAt', 'Created At')
        .setDataType(DateDataType.Unix)
        .setDateFormat('DD MMM YYYY'),
      new AttachmentField('coverUrl', ''),
      new AttachmentField('logoUrl', ''),
      new TextField('domain', 'Domain'),
      new TextField('title', 'Title'),
      new TextField('description', 'Description'),
      new TextField('webSiteUrl', 'Web Site').setInputType('url'),
      new TextField('facebookUrl', 'Facebook').setInputType('url'),
      new TextField('twitterUrl', 'Twitter').setInputType('url'),
      new TextField('linkedInUrl', 'LinkedIn').setInputType('url'),
      new SingleChoiceField('status', 'Status', [
        new SingleChoiceFieldOption('Trial', 'trial', 'warning'),
        new SingleChoiceFieldOption('Free', 'free', 'danger'),
        new SingleChoiceFieldOption('Paying', 'paying', 'primary'),
        new SingleChoiceFieldOption('Archived', 'archived', 'neutral'),
        new SingleChoiceFieldOption('Template', 'template', 'neutral'),
        new SingleChoiceFieldOption('Test', 'test', 'secondary'),
      ]),
      new SingleChoiceField('model', 'Model', [
        new SingleChoiceFieldOption('Structured Paired', 'structured-paired'),
        new SingleChoiceFieldOption('Structured Selective', 'structured-selective'),
        new SingleChoiceFieldOption('Freestyle Paired', 'freestyle-paired'),
        new SingleChoiceFieldOption('Freestyle Selective', 'freestyle-selective'),
        new SingleChoiceFieldOption('Pool', 'pool'),
        new SingleChoiceFieldOption('Group Pool', 'group-pool'),
        new SingleChoiceFieldOption('Group Paired', 'group-paired'),
        new SingleChoiceFieldOption('Startup Pool', 'startup-pool'),
        new SingleChoiceFieldOption('Startup Paired', 'startup-paired'),
        new SingleChoiceFieldOption('Structured Paired-Coaching', 'structured-paired-coaching'),
        new SingleChoiceFieldOption('Structured Selective-Coaching', 'structured-selective-coaching'),
      ]),
      {
        type: 'reverse-reference',
        id: 'summary',
        otherCollection: 'organisationSummaries',
        nameInOtherCollection: 'organisation',
        isSingle: true,
        fields: [{ id: 'metrics' }]
      }
    ],
    name: 'organisations',
    space: spaces['mentornity'],
  }),
  'scheduledjobs': DataModel.decode({
    _id: 'scheduledjobs',
    _created: new Date(),
    _updated: new Date(),
    base: 'mentornity',
    fields: [
      new TextField('name', 'Name'),
      new DateField('scheduledAt', 'Scheduled At').setDateFormat('DD MMM YYYY HH:mm'),
      new DateField('createdAt', 'Created At')
        .setDataType(DateDataType.Unix)
        .setDateFormat('DD MMM YYYY HH:mm'),
      new SingleChoiceField('status', 'Status', [
        new SingleChoiceFieldOption('Ready', 'ready', 'neutral'),
        new SingleChoiceFieldOption('Executing', 'executing', 'primary'),
        new SingleChoiceFieldOption('Done', 'done', 'secondary'),
        new SingleChoiceFieldOption('Failed', 'failed', 'danger'),
        new SingleChoiceFieldOption('Crashed', 'crashed', 'danger'),
        new SingleChoiceFieldOption('Canceled', 'crashed', 'warning'),
      ]),
      new RawDataField('metadata', 'Metadata'),
      new RawDataField('output', 'Output'),
      new RawDataField('parameters', 'Parameters'),
    ],
    name: 'scheduledjobs',
    space: spaces['mentornity'],
  }),
  'sessions': MembershipConfig.decode({
    _id: 'sessions',
    _created: new Date(),
    _updated: new Date(),
    agreements: [],
    base: 'mentornity',
    fields: [
      new DateField('createdAt', 'Initiated')
        .setDataType(DateDataType.Unix)
        .setDateFormat('DD MMM HH:mm'),
      new DateField('updatedAt', 'Last activity')
        .setDataType(DateDataType.Unix)
        .setDateFormat('DD MMM HH:mm'),
      new TextField('failureReason', 'Failure Reason'),
      new SingleChoiceField('status', 'Status', [
        new SingleChoiceFieldOption('Successful', 'successful', 'secondary'),
        new SingleChoiceFieldOption('Failed', 'failed', 'danger'),
        new SingleChoiceFieldOption('Logged Out', 'loggedOut', 'neutral'),
      ]),
      new ReferenceField('user', 'User', 'firstName', 'imageUrl', 'users', [
        new AttachmentField('imageUrl', ''),
        new TextField('firstName', 'First Name'),
      ]),
      new SingleChoiceField('client', 'Application', [
        new SingleChoiceFieldOption('Web Admin', 'web-admin'),
        new SingleChoiceFieldOption('Web Client', 'web-client'),
        new SingleChoiceFieldOption('Web Console', 'web-console'),
      ]),
    ],
    name: 'sessions',
    space: spaces['mentornity'],
  }),
  'users': MembershipConfig.decode({
    _id: 'users',
    _created: new Date(),
    _updated: new Date(),
    agreements: [],
    base: 'mentornity',
    fields: [
      new DateField('createdAt', 'Date')
        .setDataType(DateDataType.Unix)
        .setDateFormat('DD MMM YYYY'),
      new AttachmentField('imageUrl', '').setShape('circle'),
      new TextField('email', 'Email'),
      new TextField('firstName', 'First Name'),
      new TextField('lastName', 'Last Name'),
      new SingleChoiceField('status', 'Status', [
        new SingleChoiceFieldOption('Active', 'active', 'secondary'),
        new SingleChoiceFieldOption('Invited', 'invited', 'warning'),
        new SingleChoiceFieldOption('Passive', 'notInvited', 'danger'),
      ]),
      new RelationReferenceField('memberships', 'Programs', 'title', 'logoUrl', 'memberships', 'user', 'organisations', 'organisation', [
        new TextField('status', '')
      ], [
        new TextField('logoUrl', ''),
        new TextField('title', ''),
      ]),
      {
        type: 'reverse-reference',
        id: 'lastSession',
        otherCollection: 'sessions',
        nameInOtherCollection: 'user',
        isSingle: true,
        fields: [{ id: 'updatedAt' }, { id: 'createdAt' }],
        limit: 1,
        sort: {
          order: -1,
          id: 'updatedAt'
        }
      },
    ],
    name: 'users',
    space: spaces['mentornity'],
  }),
  'whiteLabels': DataModel.decode({
    _id: 'whiteLabels',
    _created: new Date(),
    _updated: new Date(),
    base: 'mentornity',
    fields: [
      new DateField('createdAt', 'Created At').setDataType(DateDataType.Unix).setDateFormat('DD MMM YYYY'),
      new DateField('updatedAt', 'Created At').setDataType(DateDataType.Unix).setDateFormat('DD MMM YYYY'),
      new TextField('domain', 'Domain').require(),
      new TextField('title', 'Title').require(),
      new TextField('description', 'Description').require(),
      new TextField('senderEmail', '').require(),
      new TextField('supportEmail', '').require(),
      new TextField('mailIconUrl', '').require(),
      new TextField('landingPageUrl', ''),
      new TextField('facebookUrl', ''),
      new TextField('twitterUrl', ''),
      new TextField('linkedInUrl', ''),
      new TextField('webSiteUrl', ''),
      new TextField('faviconUrl', ''),
      new TextField('appBarLogoUrl', ''),
    ],
    name: 'whiteLabels',
    space: spaces['mentornity'],
  }),
};

class ValidatorRegex extends InterceptorConfig {
  constructor(regex, message) {
    super('validatorAlphanumericChar');
    this.regexFlags = 'gm';
    this.regex = regex;
    this.message = message;
  }
}
ValidatorRegex.id = 'validatorAlphanumericChar';
class ValidatorRegexHandler extends InterceptorHandler {
  constructor(config) {
    super();
    this.config = config;
  }
  run(context, _, field, value) {
    if (typeof value === 'string' || value instanceof String) {
      if (!new RegExp(this.config.regex, this.config.regexFlags).test(value)) {
        const errorMessage = this.config.message || context.strings.interceptors.validatorRegex.message;
        return {
          error: errorMessage.replace('{title}', field.errorTitle || field.title),
          value,
        };
      }
    }
    return { value };
  }
}
registerInterceptor(ValidatorRegex.id, (config) => new ValidatorRegexHandler(config));

class DvnDataAdapter {
  constructor(labelFieldId, valueFieldId) {
    this.labelFieldId = labelFieldId;
    this.labelFieldIds = labelFieldId.split('+');
    this.valueFieldId = valueFieldId;
  }
  label(item) {
    if (this.labelFieldIds.length > 0) {
      return this.labelFieldIds.map(fieldId => item[fieldId]).join(' ');
    }
    return item[this.labelFieldId];
  }
  value(item) {
    return item[this.valueFieldId];
  }
}

class TableListViewConfig extends DvnAppViewConfig {
  static decode(json) {
    const model = Object.assign(Object.create(TableListViewConfig.prototype), json);
    model.table = TableConfig.decode(model.table);
    return model;
  }
}

export { DvnDataAdapter as D, RelationReferenceField as R, TableListViewConfig as T, ValidatorRegex as V, dataConfigs as d };
