/**
 * Centralized Section Exports
 * All sections export from here with theme variant support
 * Includes all 34 section components (excluding index.tsx and .modern variants)
 */

'use client';

import React from 'react';
import { getThemedComponent } from '../../lib/component-registry';
import { useTheme } from '../../contexts/ThemeContext';

// Import base components (these are the defaults/classic theme)
import { HeroHome as BaseHeroHome } from './hero-home';
import { ServicesHome as BaseServicesHome } from './services-home';
import { AboutHome as BaseAboutHome } from './about-home';
import { TestimonialsHome as BaseTestimonialsHome } from './testimonials-home';
import { TestimonialsGrid as BaseTestimonialsGrid } from './testimonials-grid';
import { FAQHome as BaseFAQHome } from './faq-home';
import { BlogSection as BaseBlogSection } from './blog-section';
import ContactSectionBase from './contact-section';
import { FooterHome as BaseFooterHome } from './footer-home';
import { HeaderNavigation as BaseHeaderNavigation } from './header-navigation';
import { GenericHeaderComponent as BaseGenericHeaderComponent } from './generic-header-component';
import { StatisticsSection as BaseStatisticsSection } from './statistics-section';
import { ValuesSection as BaseValuesSection } from './values-section';
import { TeamGrid as BaseTeamGrid } from './team-grid';
import { LocationGrid as BaseLocationGrid } from './location-grid';
import { LocationDetailsSection as BaseLocationDetailsSection } from './location-details-section';
import { ServicesGrid as BaseServicesGrid } from './services-grid';
import { SocialMediaGrid as BaseSocialMediaGrid } from './social-media-grid';
import { JobGallery as BaseJobGallery } from './job-gallery';
import { BlogHome as BaseBlogHome } from './blog-home';
import { BlogGallery as BaseBlogGallery } from './blog-gallery';
import { BlogPostSection as BaseBlogPostSection } from './blog-post';
import { ContactHome as BaseContactHome } from './contact-home';
import { FAQGrid as BaseFAQGrid } from './faq-grid';
import { FAQHero as BaseFAQHero } from './hero-faq';
import { GenericTextHero as BaseGenericTextHero } from './hero-generic-text';
import { LocationDetailHero as BaseLocationDetailHero } from './hero-location-detail';
import { ServiceDetailHero as BaseServiceDetailHero } from './hero-service-detail';
import { SocialMediaHero as BaseSocialMediaHero } from './hero-social-media';
import { TestimonialsHero as BaseTestimonialsHero } from './hero-testimonials';
import { HomeHeroComponent as BaseHomeHeroComponent } from './home-hero-component';
import { JobDetailHero as BaseJobDetailHero } from './hero-job-detail';
import { JobDetailSection as BaseJobDetailSection } from './job-detail-section';
import { PolicyDocumentSection as BasePolicyDocumentSection } from './policy-document-section';

// Import variant files to trigger their registration
// Aman theme variants
import './hero-home.aman';
import './header-navigation.aman';
import './about-home.aman';
import './services-home.aman';
import './services-grid.aman';
import './testimonials-home.aman';
import './testimonials-grid.aman';
import './contact-section.aman';
import './team-grid.aman';
import './footer-home.aman';
import './hero-service-detail.aman';
import './values-section.aman';
import './statistics-section.aman';
import './location-grid.aman';
import './location-details-section.aman';
import './social-media-grid.aman';
import './blog-home.aman';
import './blog-gallery.aman';
import './blog-post.aman';
import './blog-section.aman';
import './faq-home.aman';
import './faq-grid.aman';
import './hero-faq.aman';
import './hero-generic-text.aman';
import './hero-location-detail.aman';
import './hero-social-media.aman';
import './hero-testimonials.aman';
import './job-gallery.aman';
import './hero-job-detail.aman';
import './job-detail-section.aman';

// Barelux theme variants
import './hero-home.barelux';
import './header-navigation.barelux';
import './services-home.barelux';
import './about-home.barelux';
import './testimonials-home.barelux';
import './blog-section.barelux';
import './blog-gallery.barelux';
import './social-media-grid.barelux';
import './contact-section.barelux';
import './footer-home.barelux';

/**
 * Create a themed component wrapper that checks for variants
 * Falls back to base component if no variant exists
 * Uses type erasure to store components with different prop requirements
 * Type casts are used internally to allow components with required props
 */
function createThemedExport<P extends Record<string, unknown>>(
  componentName: string,
  // The base component is cast internally - the actual component type is preserved at usage sites
  BaseComponent: React.ComponentType<P>
) {
  return function ThemedComponent(props: P) {
    const { theme } = useTheme();
    
    try {
      // Try to get themed variant from registry
      const Component = getThemedComponent(componentName, theme);
      // Type erasure: components are stored without prop type information
      // but are type-checked where they're actually used
      return React.createElement(Component as React.ComponentType<P>, props);
    } catch {
      // No variant registered, use base component
      return React.createElement(BaseComponent, props);
    }
  };
}

// All components wrapped with themed export (falls back to base if no variant)
export const HeroHome = createThemedExport('hero-home', BaseHeroHome);
export const ServicesHome = createThemedExport('services-home', BaseServicesHome as unknown as React.ComponentType<Record<string, unknown>>);
export const AboutHome = createThemedExport('about-home', BaseAboutHome);
export const TestimonialsHome = createThemedExport('testimonials-home', BaseTestimonialsHome as unknown as React.ComponentType<Record<string, unknown>>);
export const TestimonialsGrid = createThemedExport('testimonials-grid', BaseTestimonialsGrid);
export const FAQHome = createThemedExport('faq-home', BaseFAQHome as unknown as React.ComponentType<Record<string, unknown>>);
export const BlogSection = createThemedExport('blog-section', BaseBlogSection as unknown as React.ComponentType<Record<string, unknown>>);
export const ContactSection = createThemedExport('contact-section', ContactSectionBase);
export const FooterHome = createThemedExport('footer-home', BaseFooterHome as unknown as React.ComponentType<Record<string, unknown>>);
export const HeaderNavigation = createThemedExport('header-navigation', BaseHeaderNavigation);
export const GenericHeaderComponent = createThemedExport('generic-header-component', BaseGenericHeaderComponent as unknown as React.ComponentType<Record<string, unknown>>);
export const StatisticsSection = createThemedExport('statistics-section', BaseStatisticsSection);
export const ValuesSection = createThemedExport('values-section', BaseValuesSection);
export const TeamGrid = createThemedExport('team-grid', BaseTeamGrid);
export const LocationGrid = createThemedExport('location-grid', BaseLocationGrid);
export const LocationDetailsSection = createThemedExport('location-details-section', BaseLocationDetailsSection);
export const ServicesGrid = createThemedExport('services-grid', BaseServicesGrid);
export const SocialMediaGrid = createThemedExport('social-media-grid', BaseSocialMediaGrid);
export const JobGallery = createThemedExport('job-gallery', BaseJobGallery);
export const BlogHome = createThemedExport('blog-home', BaseBlogHome);
export const BlogGallery = createThemedExport('blog-gallery', BaseBlogGallery);
export const BlogPostSection = createThemedExport('blog-post', BaseBlogPostSection);
export const ContactHome = createThemedExport('contact-home', BaseContactHome);
export const FAQGrid = createThemedExport('faq-grid', BaseFAQGrid);
export const FAQHero = createThemedExport('hero-faq', BaseFAQHero);

// Re-export component variants (these files contain multiple variants, not a single component)
export * from './blog-cards';
export * from './feature-tab';
export * from './feature-text';
export const GenericTextHero = createThemedExport('hero-generic-text', BaseGenericTextHero);
export const LocationDetailHero = createThemedExport('hero-location-detail', BaseLocationDetailHero);
export const ServiceDetailHero = createThemedExport('hero-service-detail', BaseServiceDetailHero);
export const JobDetailHero = createThemedExport('hero-job-detail', BaseJobDetailHero);
export const JobDetailSection = createThemedExport('job-detail-section', BaseJobDetailSection);
export const PolicyDocumentSection = BasePolicyDocumentSection;
export const SocialMediaHero = createThemedExport('hero-social-media', BaseSocialMediaHero);
export const TestimonialsHero = createThemedExport('hero-testimonials', BaseTestimonialsHero);
export const HomeHeroComponent = createThemedExport('home-hero-component', BaseHomeHeroComponent as unknown as React.ComponentType<Record<string, unknown>>);

// Re-export application form (client component, no theme variants)
export { JobApplicationForm } from './job-application-form';

// Re-export types
export type { Theme } from '../../themes';
