import { UniDriver } from '@wix/wix-ui-test-utils/unidriver';
import { InputAreaUniDriver } from '@wix/design-system/dist/testkit/unidriver';
import { InputAreaUniDriver as InputAreaUniDriverFactory } from '@wix/design-system/dist/types/InputArea/InputArea.uni.driver';
import { UniDriverFactory } from '../../../uniDriverFactory';
import { baseUniDriverFactory } from '../../../../unidriver';

export function ObjectEditUniDriver(base: UniDriver, body: UniDriver) {
  const inputArea = (
    InputAreaUniDriver as UniDriverFactory<InputAreaUniDriverFactory>
  )(base, body);

  return {
    ...baseUniDriverFactory(base),
    getValue: () => inputArea.getValue(),
    typeValue: (value: string) => inputArea.enterText(value),
    keyDown: (
      key: string,
      opts?: { shiftKey?: boolean; ctrlKey?: boolean; metaKey?: boolean },
    ) => inputArea.trigger('keyDown', { key, ...opts }),
    blur: () => inputArea.trigger('blur', {}),
  };
}
