/**
 * React App.tsx Root Component Generator
 *
 * Generates the root App component with React Query and React Router setup
 */

import type { TemplateContext } from '@specverse/types';

/**
 * Generate App.tsx root component
 */
export default function generateApp(context: TemplateContext): string {
  const { spec } = context;

  const componentName = spec?.metadata?.component || spec?.component?.name || 'App';

  return `/**
 * ${componentName} - Root Application Component
 * Auto-generated by SpecVerse
 */

import { RouterProvider } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { router } from './router';

/**
 * React Query client configuration
 */
const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      staleTime: 1000 * 60 * 5, // 5 minutes
      retry: 1,
      refetchOnWindowFocus: false
    },
    mutations: {
      retry: 1
    }
  }
});

/**
 * Root App Component
 */
export default function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <div className="app-container">
        <RouterProvider router={router} />
      </div>
    </QueryClientProvider>
  );
}
`;
}
