import { UniDriver } from '@wix/wix-ui-test-utils/unidriver';
import { baseUniDriverFactory } from '../../unidriver';
import {
  AddItemUniDriver,
  TextUniDriver,
} from '@wix/design-system/dist/testkit/unidriver';

export function CustomFieldsDisabledHintUniDriver(
  base: UniDriver,
  body: UniDriver,
  { dataHook }: { dataHook: string },
) {
  const buttonBase = () => base.$(`[data-hook="${dataHook}"]`);

  return {
    ...baseUniDriverFactory(base),
    ...AddItemUniDriver(buttonBase(), body),
    isDisabled: async () => {
      return (
        (await buttonBase().$('button').exists()) &&
        (await buttonBase().$('button')._prop('disabled')) === true
      );
    },
    getHintText: () =>
      TextUniDriver(
        base.$(`[data-hook="${dataHook}-disabled-hint"]`),
        body,
      ).getText(),
  };
}
