import { TAB_GENERAL } from '../constants';
import { emailRegExp } from '@/modules/@common/constants/validation';

export const validationScheme = [
  {
    fieldName: 'firstName',
    tabId: TAB_GENERAL,
    validation: (value) => {
      if (!value) {
        return 'Field cannot be empty';
      }

      return '';
    },
  },
  {
    fieldName: 'lastName',
    tabId: TAB_GENERAL,
    validation: (value) => {
      if (!value) {
        return 'Field cannot be empty';
      }

      return '';
    },
  },
  {
    fieldName: 'email',
    tabId: TAB_GENERAL,
    validation: (value) => {
      const trimmedValue = value?.trim();
      let errorMessage = '';

      if (!trimmedValue) {
        errorMessage = 'Field cannot be empty';
      } else if (!emailRegExp.test(trimmedValue)) {
        errorMessage = 'Invalid email';
      }

      return errorMessage;
    },
  },
  {
    fieldName: 'timezone',
    tabId: TAB_GENERAL,
    validation: (value) => {
      if (!value) {
        return 'Field cannot be empty';
      }

      return '';
    },
  },
  {
    fieldName: 'role',
    tabId: TAB_GENERAL,
    validation: (value) => {
      if (!value) {
        return 'Field cannot be empty';
      }

      return '';
    },
  },
  {
    fieldName: 'account',
    tabId: TAB_GENERAL,
    validation: (value) => {
      if (!value) {
        return 'Field cannot be empty';
      }

      return '';
    },
  },
  {
    fieldName: 'contentOwner',
    tabId: TAB_GENERAL,
    validation: (value) => {
      if (!value) {
        return 'Field cannot be empty';
      }

      return '';
    },
  },
  {
    fieldName: 'publisherIds',
    tabId: TAB_GENERAL,
    validation: (value, allProps) => {
      if (!allProps.allSites && !value?.length) {
        return 'Field cannot be empty';
      }

      return '';
    },
  },
];
