import React, { ReactNode } from 'react';
import { SpecVersionsLoader } from '../../components/SpecVersionsLoader';
import { SpecVersionsProvider } from '../../hooks/useSpecVersions';
import { AuthSplashScreen } from '../auth/AuthSplashScreen';

// Element Web's pattern: a homeserver `/_matrix/client/versions` probe failure
// degrades silently to an empty versions list — feature-detection consumers
// (`useMutualRooms`, `useReportRoomSupported`, `useMediaAuthentication`) all
// treat empty as "not supported" and fall back to legacy behaviour. Surfacing
// a blocking error modal here would just make a transient outage feel like a
// dead client.
export function SpecVersions({ baseUrl, children }: { baseUrl: string; children: ReactNode }) {
  return (
    <SpecVersionsLoader baseUrl={baseUrl} fallback={() => <AuthSplashScreen />}>
      {(versions) => <SpecVersionsProvider value={versions}>{children}</SpecVersionsProvider>}
    </SpecVersionsLoader>
  );
}
