import { render, screen, fireEvent } from '@testing-library/react';
import { ThemeProvider } from '../../theme';
import NotificationRow from './NotificationRow';
import type { AppNotification } from '@/services/notifications/types';

const base: AppNotification = {
  id: 1,
  type: 'booking_confirmed',
  title: 'رزرو شما تایید شد',
  body: 'ویزیت شما ثبت شد',
  isRead: false,
  createdAt: '2026-07-01T10:00:00Z',
  data: { kind: 'booking', bookingId: 5001 },
};

function renderRow(overrides: Partial<AppNotification>) {
  const onOpen = jest.fn();
  render(
    <ThemeProvider>
      <NotificationRow notification={{ ...base, ...overrides }} timeLabel="۱۰:۰۰" onOpen={onOpen} />
    </ThemeProvider>,
  );
  return onOpen;
}

describe('<NotificationRow/> component', () => {
  it('emphasises an unread notification with a dot', () => {
    renderRow({ isRead: false });
    expect(screen.getByTestId('notification-row')).toHaveAttribute('data-unread', 'true');
    expect(screen.getByTestId('notification-unread-dot')).toBeInTheDocument();
  });

  it('shows no unread dot once read', () => {
    renderRow({ isRead: true });
    expect(screen.getByTestId('notification-row')).toHaveAttribute('data-unread', 'false');
    expect(screen.queryByTestId('notification-unread-dot')).not.toBeInTheDocument();
  });

  it('renders the server-provided title and body', () => {
    renderRow({});
    expect(screen.getByText('رزرو شما تایید شد')).toBeInTheDocument();
    expect(screen.getByText('ویزیت شما ثبت شد')).toBeInTheDocument();
  });

  it('calls onOpen when clicked', () => {
    const onOpen = renderRow({});
    fireEvent.click(screen.getByTestId('notification-row'));
    expect(onOpen).toHaveBeenCalledTimes(1);
  });
});
