// @flow
import { useMemo } from 'react';

export type DisableAutofillProps = {|
  autoComplete?: string,
  'data-lpignore'?: string,
|};
export const useDisableAutofill = (
  autocomplete: string | typeof undefined,
): DisableAutofillProps =>
  useMemo(
    () => ({
      // LastPass
      'data-lpignore': autocomplete === 'off' ? 'true' : undefined,
      /**
       * Generic browser autofill. This is not honoured by many modern browsers,
       * but we add it in here just in case it works anyway.
       */
      autoComplete: autocomplete,
    }),
    [autocomplete],
  );
