import { useRef } from 'react';
import { useParallax } from '@/hooks/useScrollProgress';
import { Stack } from '@/ui/Stack';
import { Button } from '@/ui/Button';
import { Container } from '@/ui/Container';
import { Heading } from '@/ui/Heading';
import { Text } from '@/ui/Text';
import { Glow } from '@/ui/Glow';

const discordUrl = process.env.NEXT_PUBLIC_DISCORD_URL || '#';

export function LandingHero() {
  const sectionRef = useRef<HTMLElement>(null);
  const bgParallax = useParallax(sectionRef, 0.2);

  return (
    <Stack 
      as="section" 
      ref={sectionRef} 
      position="relative" 
      overflow="hidden" 
      bg="graphite-black" 
      pt={{ base: 24, md: 32, lg: 40 }}
      pb={{ base: 16, md: 24, lg: 32 }}
      className="border-b border-border-gray"
    >
      {/* Background image layer with parallax */}
      <Stack
        position="absolute"
        inset="0"
        backgroundImage="url(/images/header.jpeg)"
        backgroundSize="cover"
        backgroundPosition="center"
        opacity={0.2}
        transform={`translateY(${bgParallax * 0.5}px)`}
      />
      
      {/* Robust gradient overlay */}
      <Stack 
        position="absolute" 
        inset="0" 
        bg="linear-gradient(to bottom, #0C0D0F 0%, transparent 50%, #0C0D0F 100%)"
      />
      
      <Stack 
        position="absolute" 
        inset="0" 
        bg="radial-gradient(circle at center, transparent 0%, #0C0D0F 100%)"
        opacity={0.8}
      />
      
      <Glow color="primary" size="xl" position="center" opacity={0.15} />
      
      <Container size="lg" position="relative" zIndex={10}>
        <Stack gap={{ base: 8, md: 12 }}>
          <Stack gap={6} maxWidth="3xl">
            <Stack borderLeft borderStyle="solid" borderColor="primary-accent" pl={4} mb={2} bg="primary-accent/5" py={1}>
              <Text size="xs" weight="bold" color="text-primary-accent" uppercase letterSpacing="0.3em">
                Precision Racing Infrastructure
              </Text>
            </Stack>
            <Heading
              level={1}
              fontSize={{ base: '4xl', sm: '5xl', md: '6xl', lg: '8xl' }}
              weight="bold"
              color="text-white"
              lineHeight="0.95"
              letterSpacing="tighter"
            >
              MODERN MOTORSPORT INFRASTRUCTURE.
            </Heading>
            <Text size={{ base: 'lg', md: 'xl' }} color="text-gray-400" weight="normal" leading="relaxed" maxWidth="2xl" borderLeft borderStyle="solid" borderColor="border-gray" pl={6} opacity={0.3}>
              GridPilot gives your league racing a real home. Results, standings, teams, and career progression — engineered for precision and control.
            </Text>
          </Stack>

          <Stack display="flex" flexDirection={{ base: 'column', sm: 'row' }} gap={4}>
            <Button
              as="a"
              href={discordUrl}
              variant="primary"
              size="lg"
              px={12}
              letterSpacing="0.2em"
              fontSize="xs"
              h="14"
            >
              Join the Grid
            </Button>
            <Button
              variant="secondary"
              size="lg"
              px={12}
              borderColor="border-gray"
              hoverBorderColor="primary-accent/50"
              letterSpacing="0.2em"
              fontSize="xs"
              h="14"
              bg="transparent"
            >
              Explore Leagues
            </Button>
          </Stack>

          {/* Problem list - more professional */}
          <Stack 
            display="grid" 
            gridCols={{ base: 1, sm: 2, lg: 4 }} 
            gap={8} 
            mt={12}
            borderTop
            borderStyle="solid"
            borderColor="border-gray"
            opacity={0.2}
            pt={12}
          >
            {[
              { label: 'IDENTITY', text: 'Your racing career in one place', color: 'primary' },
              { label: 'AUTOMATION', text: 'No more manual session setup', color: 'aqua' },
              { label: 'PRECISION', text: 'Real-time results and standings', color: 'amber' },
              { label: 'COMMUNITY', text: 'Built for teams and leagues', color: 'green' }
            ].map((item) => (
              <Stack key={item.label} gap={3} group cursor="default">
                <Stack display="flex" alignItems="center" gap={3}>
                  <Stack w="1" h="3" bg={item.color === 'primary' ? 'primary-accent' : item.color === 'aqua' ? 'telemetry-aqua' : item.color === 'amber' ? 'warning-amber' : 'success-green'} />
                  <Text size="xs" weight="bold" color="text-gray-500" uppercase letterSpacing="0.2em" groupHoverTextColor="white" transition>
                    {item.label}
                  </Text>
                </Stack>
                <Text size="sm" color="text-gray-500" groupHoverTextColor="gray-300" transition leading="relaxed">
                  {item.text}
                </Text>
              </Stack>
            ))}
          </Stack>
        </Stack>
      </Container>
    </Stack>
  );
}
