/* @vitest-environment jsdom */

import { fireEvent, render, screen } from '@testing-library/react';
import { expect, test, vi } from 'vitest';

import {
  PlatformDraftGenerationPointNoticeDialog,
} from './PlatformDraftGenerationPointNoticeDialog';

test('renders the insufficient-points notice with the shared blocking copy', () => {
  const onClose = vi.fn();

  render(
    <PlatformDraftGenerationPointNoticeDialog
      notice={{
        kind: 'insufficient-points',
        requiredPoints: 30,
        currentPoints: 12,
      }}
      onClose={onClose}
    />,
  );

  expect(screen.getByRole('dialog', { name: '泥点不足' })).toBeTruthy();
  expect(screen.getByText('本次需要 30 泥点，当前 12 泥点。')).toBeTruthy();
  expect(
    screen.getByText('当前表单不会丢失，关闭后可继续编辑或补足泥点再继续。'),
  ).toBeTruthy();

  fireEvent.click(screen.getByRole('button', { name: '知道了' }));
  expect(onClose).toHaveBeenCalledTimes(1);
});

test('renders the balance-load-failed notice without the amber icon override', () => {
  render(
    <PlatformDraftGenerationPointNoticeDialog
      notice={{ kind: 'balance-load-failed' }}
      onClose={() => {}}
    />,
  );

  const dialog = screen.getByRole('dialog', { name: '读取泥点余额失败' });

  expect(screen.getByText('请稍后重试。')).toBeTruthy();
  expect(
    screen.getByText('当前表单不会丢失，关闭后可继续编辑，稍后再试。'),
  ).toBeTruthy();
  expect(dialog.innerHTML).not.toContain('bg-amber-100/80');
});
