import { UniDriver } from '@wix/wix-ui-test-utils/unidriver';
import { baseUniDriverFactory } from '../../unidriver';
import {
  PageHeaderUniDriver,
  ButtonUniDriver,
} from '@wix/design-system/dist/testkit/unidriver';
import SubTitleUniDriver from '../PageSubTitle/PageSubTitle.uni.driver';
import { MoreActionsUniDriver } from '../MoreActions/MoreActions.uni.driver';
import { ActionControlUniDriver } from '../ActionControl/ActionControl.uni.driver';

export default (base: UniDriver, body: UniDriver) => {
  return {
    /**
     * @deprecated Use `getPrimaryActions` instead. Works with `PrimaryActions` component.
     * Returns primary action button driver
     */
    getPrimaryAction: (dataHook: string) =>
      ButtonUniDriver(base.$(`[data-hook="${dataHook}"]`), body),

    /** Returns primary actions drivers */
    getPrimaryActions: (dataHook = 'primary-actions') =>
      ActionControlUniDriver(base, body).getActionControl(dataHook),

    /** Returns secondary actions drivers */
    getSecondaryActions: (dataHook = 'secondary-actions') =>
      ActionControlUniDriver(base, body).getActionControl(dataHook),

    /** Returns more actions button driver */
    getMoreActions: (dataHook: string = 'more-actions') =>
      MoreActionsUniDriver(base, body).getMoreActions(dataHook),

    getPageHeader: () =>
      PageHeaderUniDriver(base.$(`[data-hook="collection-page-header"]`), body),

    getTotal: async () =>
      Number(await base.$('[data-hook="page-header-total-count"]').text()),

    subTitleDriver: SubTitleUniDriver(base, body),

    ...baseUniDriverFactory(base),
  };
};
