import { TextField } from '@dvn/core/doldurma/src/fields/text';
import { ModifierTrimmer } from '@dvn/core/doldurma/src/interceptors/modifiers/ModifierTrimmer';
import { ValidatorEmail } from '@dvn/core/doldurma/src/interceptors/validators/ValidatorEmail';
import { ValidatorLength } from '@dvn/core/doldurma/src/interceptors/validators/ValidatorLength';
import { ValidatorRegex } from '@dvn/core/doldurma/src/interceptors/validators/ValidatorRegex';
import { ValidatorURL } from '@dvn/core/doldurma/src/interceptors/validators/ValidatorURL';
import { FormViewConfig } from '@dvn/core/models/form-view-config';
import { AppViewType } from '@dvn/core/models/view-config';
import { CreateWhiteLabelFormHandler } from '../../handlers/CreateWhiteLabelFormHandler';
import { dataConfigs } from '../data-configs';
import { spaces } from '../spaces';
export const ID = 'form-view-whitelabel-create';
export const whiteLabelDomainRegex = '(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\\.)+[a-z0-9][a-z0-9-]{0,61}[a-z0-9]';
export const viewConfig = FormViewConfig.decode({
  _id: ID,
  base: 'mentornity',
  title: 'Create White Label',
  space: spaces['mentornity'],
  table: dataConfigs['whiteLabels'],
  type: AppViewType.FormView,
  handler: new CreateWhiteLabelFormHandler(),
  ui: {
    fields: [
      {
        field: new TextField('title', 'Title').addInterceptor('onBlur', new ValidatorLength(2, 100))
          .addInterceptor('onSubmit', new ModifierTrimmer())
          .require(),
      },
      {
        field: new TextField('description', 'Description').require(),
      },
      {
        field: new TextField('domain', 'Domain', 'without http or https')
          .addInterceptor('onBlur', new ValidatorRegex(whiteLabelDomainRegex, 'Not a valid domain.'))
          .addInterceptor('onSubmit', new ModifierTrimmer())
          .require(),
      },
      {
        field: new TextField('senderEmail', 'Sender Email')
          .setInputType('email')
          .addInterceptor('onBlur', new ValidatorEmail())
          .require(),
      },
      {
        field: new TextField('supportEmail', 'Support Email')
          .setInputType('email')
          .addInterceptor('onBlur', new ValidatorEmail())
          .require(),
      },
      {
        field: new TextField('mailIconUrl', 'Mail Icon URL', 'with http or https')
          .setInputType('url')
          .addInterceptor('onBlur', new ValidatorURL())
          .require(),
      },
      {
        field: new TextField('faviconUrl', 'Favicon URL')
          .setInputType('url')
          .addInterceptor('onBlur', new ValidatorURL())
          .setValue('')
      },
      {
        field: new TextField('landingPageUrl', 'Landing Page URL')
          .setInputType('url')
          .addInterceptor('onBlur', new ValidatorURL())
          .setValue('')
      },
      {
        field: new TextField('appBarLogoUrl', 'AppBarLogo URL')
          .setInputType('url')
          .addInterceptor('onBlur', new ValidatorURL())
          .setValue('')
      },
      {
        field: new TextField('facebookUrl', 'Facebook URL')
          .setInputType('url')
          .addInterceptor('onBlur', new ValidatorURL())
          .setValue('')
      },
      {
        field: new TextField('twitterUrl', 'Twitter URL')
          .setInputType('url')
          .addInterceptor('onBlur', new ValidatorURL())
          .setValue('')
      },
      {
        field: new TextField('linkedInUrl', 'LinkedIn URL')
          .setInputType('url')
          .addInterceptor('onBlur', new ValidatorURL())
          .setValue('')
      },
      {
        field: new TextField('webSiteUrl', 'WebSite URL')
          .setInputType('url')
          .addInterceptor('onBlur', new ValidatorURL())
          .setValue('')
      },
    ],
  }
});
