import { describe, it, expect, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import type React from 'react';

const { mockUseApi } = vi.hoisted(() => ({ mockUseApi: vi.fn() }));

vi.mock('@/lib/useApi', () => ({ useApi: mockUseApi }));
vi.mock('next/link', () => ({
  default: (props: { href?: string; children: React.ReactNode }) => props.children,
}));
vi.mock('@/app/(dashboard)/medicines/RegimensTab', () => ({
  RegimensTab: ({ householdId }: { householdId: string }) => (
    <div data-testid="regimens-tab">{householdId}</div>
  ),
}));

import RegimensPage from '../../../../../src/app/(dashboard)/medicines/regimens/page';

describe('RegimensPage', () => {
  it('shows skeleton when loading', () => {
    mockUseApi.mockReturnValue({ householdId: null, isLoading: true });
    render(<RegimensPage />);
    expect(screen.getByText('Regimens')).toBeInTheDocument();
    expect(screen.queryByTestId('regimens-tab')).not.toBeInTheDocument();
  });

  it('shows household prompt when no householdId', () => {
    mockUseApi.mockReturnValue({ householdId: null, isLoading: false });
    render(<RegimensPage />);
    expect(screen.getByText(/create or join a household/)).toBeInTheDocument();
  });

  it('renders RegimensTab when householdId exists', () => {
    mockUseApi.mockReturnValue({ householdId: 'hh1', isLoading: false });
    render(<RegimensPage />);
    expect(screen.getByTestId('regimens-tab')).toHaveTextContent('hh1');
  });
});
