import { DataTable } from '@/manager/modules/ui/data-table/components/DataTable';
import { expectMultiLocatorToHaveText, expectSingleLocatorToHaveText } from '@/manager/shared/utils/expect-utils';
import { getChipContentHost } from '@/manager/shared/utils/host-utils';
import { isString } from 'lodash';

export async function expectDataTableChipsColumnToHaveText(
  table: DataTable,
  columnId: string,
  text: string | string[] | undefined
): Promise<void> {
  const column = table.getColumn(columnId);

  for (const cell of await column.all()) {
    await expectMultiLocatorToHaveText(getChipContentHost(cell), isString(text) ? [text] : text);
  }
}

export async function expectDataTableTextColumnToHaveText(
  table: DataTable,
  columnId: string,
  text: string | undefined
): Promise<void> {
  const column = table.getColumn(columnId);

  for (const cell of await column.all()) {
    await expectSingleLocatorToHaveText(cell, text);
  }
}

export async function expectDataTableColumnToContainText(
  table: DataTable,
  columnId: string,
  text: string | string[] | undefined
): Promise<void> {
  const column = table.getColumn(columnId);
  const expectedValue = text == null ? undefined : RegExp(isString(text) ? text : text.join('|'));

  for (const cell of await column.all()) {
    await expectSingleLocatorToHaveText(cell, expectedValue);
  }
}
