import { TotalsSummarySection } from '@/manager/modules/ui/totals-summary/components/TotalsSummarySection';
import { ITotalsSummary } from '@/manager/modules/ui/totals-summary/types/totals-summary-types';
import { expectSingleLocatorToHaveText } from '@/manager/shared/utils/expect-utils';
import { formatCurrency } from '@/shared/utils/format-utils';
import { expect } from '@playwright/test';

export async function expectTotalsSummarySectionToDisplayCorrectData(
  section: TotalsSummarySection,
  data: ITotalsSummary,
  currency: string
): Promise<void> {
  await expectSingleLocatorToHaveText(section.totalExclVatValue, formatCurrency(data.totalExclVat, currency));

  if (data.totalDiscount) {
    await expectSingleLocatorToHaveText(section.discountValue, `-${formatCurrency(data.totalDiscount, currency)}`);
  } else {
    await expect(section.discountValue).toBeHidden();
  }

  await expectSingleLocatorToHaveText(section.vatValue, formatCurrency(data.totalVat, currency));
  await expectSingleLocatorToHaveText(section.totalInclVatValue, formatCurrency(data.totalInclVat, currency));
}
