import React from 'react';

// Types
import { TypeDynamicTableMessages } from 'components/DynamicTable/types';
import { FormInstance, Rule } from 'antd/lib/form';
import { FormProps } from 'antd';
import {
  TypeCardInfoEndpointMessages,
  TypeCardInfoMessages,
  TypeEndpointDynamicTablePath,
} from '../types';
import { TypeEventJournalTableMessages } from 'pages/EventsJournalDashboard/types';
import { TypeCommonValidationMessages } from 'components/i18n';

export type TypeDynamicTable = {
  dataIndex: string;
  title: string;
  editable?: boolean;
  width?: string | number;
};
export type TypeDynamicTableProps = {
  tableName: string;
  disabled: boolean;
  columns: TypeDynamicTable[];
  originData: TypeEndpointDynamicTablePath;
  setOriginData: (item: TypeEndpointDynamicTablePath) => void;
  locales: TypeDynamicTableMessages;
  localeValidation: TypeCommonValidationMessages;
};

export type Item = {
  id: number;
  path: string;
};

export interface EditableCellProps extends React.HTMLAttributes<HTMLElement> {
  editing: boolean;
  dataIndex: string;
  title: string;
  inputType: 'number' | 'text';
  record: Item;
  index: number;
  children: React.ReactNode;
}

type TypeRules = (
  | { required: boolean; message: string }
  | { max: number; message: string }
  | (() => { validator(_: Rule, value: string): Promise<void> })
)[];

export type TypeFirewallConfiguration = {
  key: string;
  label: string;
  name: string;
  rules?: TypeRules;
  extra?: string;
  element: JSX.Element;
};

export type TypeSensorField =
  | 'authorizationKey'
  | 'ip'
  | 'description'
  | 'signatureAnalysis'
  | 'protocolsAnalysis'
  | 'port'
  | 'spanInterfaceName'
  | 'name'
  | 'group';

export type TypeSensorConfiguration = {
  [key in TypeSensorField]: JSX.Element;
};

export type GeneralFormProps = FormProps & {
  form: FormProps;
  locale: TypeCardInfoMessages;
  localeValidation: TypeCommonValidationMessages;
};

export type TypeEndpointLargeForm = {
  form: FormInstance;
  endpointId?: number;
  tableTranslations: TypeEventJournalTableMessages;
  locale: TypeCardInfoEndpointMessages;
  localeValidation: TypeCommonValidationMessages;
};

export type TypeSelectorAddNewEventSourceProps = {
  locale: {
    type: string;
    validation: string;
    placeholder: string;
  };
};
