import { UniDriver } from '@wix/wix-ui-test-utils/unidriver';
import {
  ButtonUniDriver,
  PopoverMenuUniDriver,
} from '@wix/design-system/dist/testkit/unidriver';

export const ActionControlUniDriver = (base: UniDriver, body: UniDriver) => {
  const getActionControl = (dataHook: string) => {
    return {
      getButton: () =>
        ButtonUniDriver(base.$(`[data-hook="${dataHook}"]`), body),
      getPopover: () => {
        const popover = PopoverMenuUniDriver(
          base.$(`[data-hook="${dataHook}-popover"]`),
          body,
        );
        return {
          ...popover,
          open: () => popover.getTriggerElement(dataHook).click(),
          getTriggerElement() {
            return popover.getTriggerElement(dataHook);
          },
        };
      },
    };
  };
  return {
    getActionControl,
  };
};
