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

export function AppliedFiltersTagListUniDriver(
  base: UniDriver,
  body: UniDriver,
) {
  const tagList = TagListUniDriver(
    base.$('[data-hook="active-filter-tags"]'),
    body,
  );

  const getAppliedFilterTag = (filterName: string, id?: string) =>
    TagUniDriver(
      base.$(`[data-hook="${filterName}${id ? `-${id}` : ''}"]`),
      body,
    );

  const appliedFilterTagExists = (filterName: string, id?: string) =>
    getAppliedFilterTag(filterName, id).exists();

  const getAppliedFilterTagText = (filterName: string, id?: string) =>
    getAppliedFilterTag(filterName, id).getLabel();

  const removeAppliedFilterTag = (filterName: string, id?: string) =>
    getAppliedFilterTag(filterName, id).removeTag();

  return {
    ...tagList,
    getAppliedFilterTagText,
    removeAppliedFilterTag,
    appliedFilterTagExists,
    getAppliedFilterTag,
  };
}
