import React from 'react';
import { render, screen } from '@testing-library/react';
import { renderHook } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { describe, expect, it } from 'vitest';
import * as Root from './index';
import * as Assistant from './assistant';
import * as Blocks from './blocks';
import * as Brand from './brand';
import * as Hooks from './hooks';
import * as Layout from './layout';
import * as Media from './media';
import * as Pages from './pages';
import * as UI from './ui';

describe('public API smoke tests', () => {
  it('keeps all documented subpath entrypoints importable', () => {
    expect(UI.Button).toBeDefined();
    expect(Brand.XerticaProvider).toBeTypeOf('function');
    expect(Layout.Header).toBeTypeOf('function');
    expect(Assistant.XerticaAssistant).toBeTypeOf('function');
    expect(Blocks.FeatureCard).toBeTypeOf('function');
    expect(Media.AudioPlayer).toBeTypeOf('function');
    expect(Pages.TemplateContent).toBeTypeOf('function');
    expect(UI.CalendarDayButton).toBeTypeOf('function');
    expect(Hooks.useOptionalLayout).toBeTypeOf('function');
    expect(Hooks.useMobile).toBeTypeOf('function');
    expect(Hooks.useAuth).toBeTypeOf('function');
    expect(Hooks.AuthProvider).toBeTypeOf('function');
    expect(Root.TemplateContent).toBe(Pages.TemplateContent);
    expect(Root.XerticaProvider).toBe(Brand.XerticaProvider);
  });

  it('renders representative components from the public subpaths', () => {
    const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
    render(
      <QueryClientProvider client={queryClient}>
        <Brand.XerticaProvider>
          <UI.Button>Action</UI.Button>
          <Layout.Header title="Header smoke" />
          <Assistant.MarkdownMessage content="**Assistant** smoke" />
          <Media.AudioPlayer title="Audio smoke" enableAutoFloat={false} />
        </Brand.XerticaProvider>
      </QueryClientProvider>
    );

    expect(screen.getByRole('button', { name: 'Action' })).toBeInTheDocument();
    expect(screen.getByText('Header smoke')).toBeInTheDocument();
    expect(screen.getByText('Assistant')).toBeInTheDocument();
    expect(screen.getByText('Audio smoke')).toBeInTheDocument();
  });

  it('exposes optional hooks that can be called without root providers', () => {
    const { result } = renderHook(() => Hooks.useOptionalLayout());

    expect(result.current).toBeNull();
  });
});
