'use client';

import { Button, Container, Heading, Section } from '@/components/ui';
import { useTranslations, useLocale } from 'next-intl';
import dynamic from 'next/dynamic';
import { useAnalytics } from '../analytics/useAnalytics';
import { AnalyticsEvents } from '../analytics/analytics-events';
const HeroIllustration = dynamic(() => import('./HeroIllustration'), { ssr: false });

export default function Hero({ data }: { data?: any }) {
  const t = useTranslations('Home.hero');
  const locale = useLocale();
  const { trackEvent } = useAnalytics();

  return (
    <Section className="relative min-h-[85vh] md:h-[90vh] flex flex-col items-center justify-center overflow-hidden bg-primary py-12 md:py-0 lg:py-0">
      <Container className="relative z-10 text-center md:text-left text-white w-full order-2 md:order-none">
        <div className="max-w-5xl mx-auto md:mx-0">
          <div>
            <Heading
              level={1}
              className="text-center md:text-left mb-6 md:mb-8 md:max-w-none text-white text-3xl sm:text-4xl md:text-5xl font-extrabold"
            >
              {data?.title ? (
                <span
                  dangerouslySetInnerHTML={{
                    __html: data.title
                      .replace(/<green>/g, '<span class="text-accent italic">')
                      .replace(/<\/green>/g, '</span>'),
                  }}
                />
              ) : (
                t.rich('title', {
                  green: (chunks) => <span className="text-accent italic">{chunks}</span>,
                })
              )}
            </Heading>
          </div>
          <div>
            <p className="text-lg md:text-xl text-white leading-relaxed max-w-2xl mb-10 md:mb-12">
              {data?.subtitle || t('subtitle')}
            </p>
          </div>
          <div className="flex flex-col sm:flex-row justify-center md:justify-start gap-4 md:gap-6">
            <div>
              <Button
                href="/contact"
                variant="accent"
                size="lg"
                className="group w-full sm:w-auto h-14 md:h-16 px-8 md:px-10 text-base md:text-lg hover:scale-105 transition-transform"
                onClick={() =>
                  trackEvent(AnalyticsEvents.BUTTON_CLICK, {
                    label: data?.ctaLabel || t('cta'),
                    location: 'home_hero_primary',
                  })
                }
              >
                {data?.ctaLabel || t('cta')}
                <span className="transition-transform group-hover/btn:translate-x-1 ml-2">
                  &rarr;
                </span>
              </Button>
            </div>
            <div>
              <Button
                href={`/${locale}/${locale === 'de' ? 'produkte' : 'products'}`}
                variant="white"
                size="lg"
                className="group w-full sm:w-auto h-14 md:h-16 px-8 md:px-10 text-base md:text-lg md:bg-white md:text-primary md:hover:bg-neutral-light md:border-none hover:scale-105 transition-transform"
                onClick={() =>
                  trackEvent(AnalyticsEvents.BUTTON_CLICK, {
                    label: data?.secondaryCtaLabel || t('exploreProducts'),
                    location: 'home_hero_secondary',
                  })
                }
              >
                {data?.secondaryCtaLabel || t('exploreProducts')}
              </Button>
            </div>
          </div>
        </div>
      </Container>

      <div className="relative md:absolute inset-0 z-0 w-full h-[40vh] md:h-full order-1 md:order-none mb-[-80px] md:mb-0 mt-[80px] md:mt-0 overflow-visible pointer-events-none animate-in fade-in zoom-in-95 duration-1000 ease-out fill-mode-both">
        <HeroIllustration />
      </div>

      <div
        className="absolute bottom-6 md:bottom-10 left-1/2 -translate-x-1/2 hidden sm:block animate-in fade-in slide-in-from-bottom-4 duration-1000 ease-out fill-mode-both"
        style={{ animationDelay: '2000ms' }}
      >
        <div className="w-6 h-10 border-2 border-white/30 rounded-full flex justify-center p-1">
          <div className="w-1 h-2 bg-white rounded-full animate-bounce" />
        </div>
      </div>
    </Section>
  );
}
