import { FieldDataSourceTypeEnum, FieldRuleEnum, FieldTypeEnum } from '@lib/shared/enums/formDesignEnum';

import type { FormCreateField, FormCreateFieldRule } from './types';

export const inputDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.INPUT,
  name: 'crmFormDesign.input',
  icon: 'iconicon_single_line_text',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  showRules: [FieldRuleEnum.REQUIRED, FieldRuleEnum.UNIQUE],
};

export const textareaDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.TEXTAREA,
  icon: 'iconicon_multiline',
  name: 'crmFormDesign.textarea',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  showRules: [FieldRuleEnum.REQUIRED],
};

export const inputNumberDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.INPUT_NUMBER,
  icon: 'iconicon_hashtag_key',
  name: 'crmFormDesign.inputNumber',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  numberFormat: 'number',
  decimalPlaces: false,
  precision: 0,
  showThousandsSeparator: false,
  showRules: [FieldRuleEnum.REQUIRED],
};

export const dateTimeDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.DATE_TIME,
  icon: 'iconicon_calendar1',
  name: 'crmFormDesign.dateTime',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  datetype: 'datetime',
  showRules: [FieldRuleEnum.REQUIRED],
};

export const radioDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.RADIO,
  icon: 'iconicon_radio',
  name: 'crmFormDesign.radio',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  options: [],
  readable: true,
  editable: true,
  rules: [],
  showRules: [FieldRuleEnum.REQUIRED, FieldRuleEnum.UNIQUE],
  direction: 'vertical',
};

export const checkboxDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.CHECKBOX,
  icon: 'icona-icon_collectbeifen12',
  name: 'crmFormDesign.checkbox',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  options: [],
  readable: true,
  editable: true,
  rules: [],
  direction: 'vertical',
  showRules: [FieldRuleEnum.REQUIRED],
};

export const selectDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.SELECT,
  icon: 'iconicon_pull_down_single_choice',
  name: 'crmFormDesign.select',
  fieldWidth: 1,
  showLabel: true,
  options: [],
  description: '',
  readable: true,
  editable: true,
  rules: [],
  multiple: false,
  showRules: [FieldRuleEnum.REQUIRED, FieldRuleEnum.UNIQUE],
};

export const memberDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.MEMBER,
  icon: 'iconicon_member_single_choice',
  name: 'crmFormDesign.memberSelect',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  defaultValue: [],
  multiple: false,
  showRules: [FieldRuleEnum.REQUIRED, FieldRuleEnum.UNIQUE],
};

export const departmentDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.DEPARTMENT,
  icon: 'iconicon_department_single_choice',
  name: 'crmFormDesign.departmentSelect',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  defaultValue: [],
  multiple: false,
  showRules: [FieldRuleEnum.REQUIRED, FieldRuleEnum.UNIQUE],
};

export const dividerDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.DIVIDER,
  icon: 'iconicon_dividing_line',
  name: 'crmFormDesign.divider',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  dividerClass: 'divider--normal',
  dividerColor: '#edf0f1',
  titleColor: '#323535',
};

export const tagInputDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.MULTIPLE_INPUT,
  icon: 'iconicon_books',
  name: 'common.tag',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  defaultValue: [],
  showRules: [FieldRuleEnum.REQUIRED],
};

export const basicFields: FormCreateField[] = [
  inputDefaultFieldConfig,
  textareaDefaultFieldConfig,
  inputNumberDefaultFieldConfig,
  dateTimeDefaultFieldConfig,
  radioDefaultFieldConfig,
  checkboxDefaultFieldConfig,
  selectDefaultFieldConfig,
  memberDefaultFieldConfig,
  departmentDefaultFieldConfig,
  dividerDefaultFieldConfig,
  tagInputDefaultFieldConfig,
];

export const pictureDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.PICTURE,
  icon: 'iconicon_picture',
  name: 'crmFormDesign.picture',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  uploadLimit: 10,
  uploadSizeLimit: 20,
  pictureShowType: 'card',
  uploadLimitEnable: false,
  uploadSizeLimitEnable: false,
  showRules: [FieldRuleEnum.REQUIRED],
};

export const locationDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.LOCATION,
  icon: 'iconicon_map',
  name: 'crmFormDesign.location',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  locationType: 'PCD',
  showRules: [FieldRuleEnum.REQUIRED],
};

export const phoneDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.PHONE,
  icon: 'iconicon_phone',
  name: 'crmFormDesign.phone',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  showRules: [FieldRuleEnum.REQUIRED, FieldRuleEnum.UNIQUE],
};

export const dataSourceDefaultFieldConfig: FormCreateField = {
  id: '',
  type: FieldTypeEnum.DATA_SOURCE,
  icon: 'iconicon_select_data',
  name: 'crmFormDesign.dataSource',
  fieldWidth: 1,
  showLabel: true,
  description: '',
  readable: true,
  editable: true,
  rules: [],
  multiple: false,
  defaultValue: [],
  dataSourceSelectedRows: [],
  dataSourceType: FieldDataSourceTypeEnum.CUSTOMER,
  showRules: [FieldRuleEnum.REQUIRED, FieldRuleEnum.UNIQUE],
};

export const advancedFields: FormCreateField[] = [
  pictureDefaultFieldConfig,
  locationDefaultFieldConfig,
  phoneDefaultFieldConfig,
  dataSourceDefaultFieldConfig,
];

export const rules: FormCreateFieldRule[] = [
  {
    key: FieldRuleEnum.REQUIRED,
    required: true,
    message: 'common.notNull',
    label: 'crmFormDesign.required',
  },
  {
    key: FieldRuleEnum.UNIQUE,
    message: 'common.valueExists',
    label: 'crmFormDesign.onlyOne',
  },
];
