import { describe, expect, it } from 'vitest';

import { renderPdf } from '@/lib/pdf/render';
import { ParentCompanyExpensePdf } from '@/lib/pdf/templates/parent-company-expense';

describe('parent-company expense template', () => {
  it('renders with multiple rows + totals', async () => {
    const bytes = await renderPdf(
      <ParentCompanyExpensePdf
        portName="Port Test"
        logoBuffer={null}
        rows={[
          { date: '2026-04-01', establishment: 'Shell', category: 'Fuel', amountEur: 200 },
          { date: '2026-04-03', establishment: 'BP', category: 'Fuel', amountEur: 150 },
          { date: '2026-04-05', establishment: 'Marina café', category: 'Misc', amountEur: 12.5 },
        ]}
        subtotal={362.5}
        managementFee={18.13}
        total={380.63}
        dateFrom="2026-04-01"
        dateTo="2026-04-30"
      />,
    );
    expect(bytes.subarray(0, 5).toString('utf8')).toBe('%PDF-');
  }, 30_000);

  it('renders the rate-unavailable footnote', async () => {
    const bytes = await renderPdf(
      <ParentCompanyExpensePdf
        portName="Port Test"
        logoBuffer={null}
        rows={[]}
        subtotal={0}
        managementFee={0}
        total={0}
        rateAvailable={false}
      />,
    );
    expect(bytes.subarray(0, 5).toString('utf8')).toBe('%PDF-');
  }, 30_000);
});
