import IqlInput from './IqlInput';
import { POPOVER_PLACEMENT } from '../../components/Popover';

type Props = {
  suggestionMapper?: (suggestion: object) => {}
};
declare var ruik: { AutocompleteEditor: any, Utils: any };
export class AutocompleteEditor extends IqlInput<Props> {
  constructor(props) {
    super(props);

    this.inputComponent = global.ruik.AutocompleteEditor;
    this.inputComponentOptions = {
      helpLink: null,
      applyOnSubmit: false,
      withApplyButton: false,
      includeDelimiters: true,
      delimiters: {
        left: [global.ruik.Utils.KEYCODES.AROBAS],
        right: [
          global.ruik.Utils.KEYCODES.NBSP,
          global.ruik.Utils.KEYCODES.SPACE,
          global.ruik.Utils.KEYCODES.LINE_FEED
        ]
      },
      popper: {
        placement: POPOVER_PLACEMENT.BOTTOM_START,
        modifiers: { preventOverflow: { enabled: false } }
      }
    };

    if (props.suggestionMapper)
      this.inputComponentOptions['suggestionMapper'] = props.suggestionMapper;
  }
}

export default AutocompleteEditor;
