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

export function UrlViewUniDriver(base: UniDriver, body: UniDriver) {
  const linkButton = IconButtonUniDriver(
    base.$('[data-hook="open-link-button"]'),
    body,
  );

  return {
    ...baseUniDriverFactory(base),
    getValue: () => base.text(),
    hasOpenLinkButton: () => linkButton.exists(),
    getLinkHref: () =>
      base.$('[data-hook="open-link-button"]').attr('href') as Promise<string>,
    clickOpenLink: () => linkButton.click(),
  };
}
