'use client';

import { motion, useReducedMotion } from 'framer-motion';
import { useState, useEffect } from 'react';
import { Box } from '@/ui/Box';
import { Text } from '@/ui/Text';
import { Stack } from '@/ui/Stack';
import { Heading } from '@/ui/Heading';

export function LeagueHomeMockup() {
  const shouldReduceMotion = useReducedMotion();
  const [isMobile, setIsMobile] = useState(false);

  useEffect(() => {
    setIsMobile(window.innerWidth < 768);
  }, []);

  if (isMobile) {
    return (
      <Box position="relative" fullWidth fullHeight bg="bg-gradient-to-br from-deep-graphite via-iron-gray to-deep-graphite" rounded="lg" p={3} overflow="hidden">
        <Stack gap={4}>
          <Box display="flex" alignItems="center" gap={3} mb={2}>
            <Box h="12" w="12" rounded="lg" border borderWidth="2px" borderColor="border-primary-blue/50" bg="bg-charcoal-outline" display="flex" alignItems="center" justifyContent="center" shadow="0_0_20px_rgba(25,140,255,0.3)">
              <Text size="2xl">🏆</Text>
            </Box>
            <Box>
              <Text size="base" weight="bold" color="text-white" block>Super GT</Text>
              <Text size="xs" color="text-gray-400" block>Round 8/12</Text>
            </Box>
          </Box>

          <Box>
            <Text size="sm" weight="semibold" color="text-white" mb={3} block>Next Race</Text>
            <Box position="relative" display="flex" alignItems="center" gap={3} bg="bg-iron-gray" rounded="lg" p={3} border borderColor="border-charcoal-outline">
              <Box h="8" w="8" bg="bg-charcoal-outline" rounded border borderColor="border-primary-blue/20" display="flex" alignItems="center" justifyContent="center">
                <Text size="base">🏁</Text>
              </Box>
              <Box flexGrow={1}>
                <Box h="2.5" w="28" bg="bg-white/10" rounded="sm" mb={2} />
                <Box h="2" w="20" bg="bg-white/5" rounded="sm" />
              </Box>
              <Box w="2" h="2" bg="bg-primary-blue" rounded="full" 
                // eslint-disable-next-line gridpilot-rules/component-classification
                className="shadow-glow" 
              />
            </Box>
          </Box>

          <Box>
            <Text size="sm" weight="semibold" color="text-white" mb={3} block>Latest Result</Text>
            <Box bg="bg-iron-gray" rounded="lg" p={3} border borderColor="border-charcoal-outline">
              <Box display="flex" alignItems="center" gap={3} py={2} borderBottom borderColor="border-charcoal-outline">
                <Box h="2.5" w="6" bg="bg-white/10" rounded="sm" />
                <Box h="2.5" flexGrow={1} bg="bg-white/10" rounded="sm" />
                <Box h="2.5" w="10" bg="bg-white/10" rounded="sm" />
              </Box>
              <Box display="flex" alignItems="center" gap={3} py={2}>
                <Box h="2" w="6" bg="bg-white/5" rounded="sm" />
                <Box h="2" flexGrow={1} bg="bg-white/5" rounded="sm" />
                <Box h="2" w="10" bg="bg-performance-green/20" rounded="sm" />
              </Box>
            </Box>
          </Box>
        </Stack>
      </Box>
    );
  }

  const containerVariants = {
    hidden: { opacity: 0 },
    visible: {
      opacity: 1,
      transition: { staggerChildren: shouldReduceMotion ? 0 : 0.1 }
    }
  };

  const itemVariants = {
    hidden: { opacity: 0, y: shouldReduceMotion ? 0 : 20 },
    visible: { opacity: 1, y: 0 }
  };

  return (
    <Box position="relative" fullWidth fullHeight bg="bg-gradient-to-br from-deep-graphite via-iron-gray to-deep-graphite" rounded="lg" p={{ base: 1.5, sm: 3, md: 5, lg: 8 }} overflow="hidden">
      <Box
        as={motion.div}
        variants={containerVariants}
        initial="hidden"
        animate="visible"
      >
        <Stack gap={{ base: 1.5, sm: 3, md: 4, lg: 6 }}>
          <Box as={motion.div} variants={itemVariants}>
            <Box display="flex" alignItems="center" gap={{ base: 1.5, sm: 2, md: 3, lg: 4 }} mb={{ base: 1, sm: 1.5, md: 2 }}>
              <Box h={{ base: 8, sm: 10, md: 12, lg: 16 }} w={{ base: 8, sm: 10, md: 12, lg: 16 }} rounded="lg" border borderWidth="2px" borderColor="border-primary-blue/50" bg="bg-charcoal-outline" display="flex" alignItems="center" justifyContent="center" shadow="0_0_20px_rgba(25,140,255,0.3)">
                <Text size={{ base: 'base', sm: 'xl', md: '2xl', lg: '3xl' }}>🏆</Text>
              </Box>
              <Box>
                <Heading level={2} fontSize={{ base: 'sm', sm: 'base', md: 'lg', lg: 'xl' }} weight="bold" color="text-white" mb={0.5}>Super GT Championship</Heading>
                <Text 
                  // eslint-disable-next-line gridpilot-rules/component-classification
                  style={{ fontSize: '9px' }} 
                  color="text-gray-400"
                >
                  Season 3 • Round 8/12
                </Text>
              </Box>
            </Box>
            <Text 
              // eslint-disable-next-line gridpilot-rules/component-classification
              style={{ fontSize: '8px' }} 
              color="text-white" 
              opacity={0.5} 
              mt={{ base: 1, sm: 1.5, md: 2 }} 
              block
            >
              Your league&apos;s dedicated home page
            </Text>
          </Box>

          <Box as={motion.div} variants={itemVariants}>
            <Text size={{ base: 'xs', sm: 'sm', md: 'base' }} weight="semibold" color="text-white" mb={{ base: 1.5, sm: 2, md: 3, lg: 4 }} block>Upcoming Races</Text>
            <Text 
              // eslint-disable-next-line gridpilot-rules/component-classification
              style={{ fontSize: '8px' }} 
              color="text-white" 
              opacity={0.5} 
              mb={{ base: 1.5, sm: 2, md: 3 }} 
              block
            >
              Calendar automatically synced from iRacing
            </Text>
            <Stack gap={{ base: 1.5, sm: 2, md: 3 }}>
              {[1, 2, 3].map((i) => (
                <Box
                  key={i}
                  as={motion.div}
                  position="relative"
                  display="flex"
                  alignItems="center"
                  gap={{ base: 1.5, sm: 2, md: 3, lg: 4 }}
                  bg="bg-iron-gray"
                  rounded="lg"
                  p={{ base: 1.5, sm: 2, md: 3, lg: 4 }}
                  border
                  borderColor="border-charcoal-outline"
                  shadow="inset_0_1px_2px_rgba(0,0,0,0.2)"
                  whileHover={shouldReduceMotion ? {} : {
                    y: -2,
                    boxShadow: '0 4px 24px rgba(0,0,0,0.4), 0 0 20px rgba(25,140,255,0.3)',
                    transition: { duration: 0.15 }
                  }}
                  transition={{ type: 'spring', stiffness: 200, damping: 20 }}
                >
                  <Box h={{ base: 6, sm: 7, md: 8, lg: 10 }} w={{ base: 6, sm: 7, md: 8, lg: 10 }} bg="bg-charcoal-outline" rounded border borderColor="border-primary-blue/20" display="flex" alignItems="center" justifyContent="center">
                    <Text size={{ base: 'sm', sm: 'base', md: 'lg', lg: 'xl' }}>🏁</Text>
                  </Box>
                  <Box flexGrow={1}>
                    <Box h={{ base: 1.5, sm: 2, md: 2.5, lg: 3 }} w={{ base: 20, sm: 24, md: 28, lg: 32 }} bg="bg-white/10" rounded="sm" mb={{ base: 1, sm: 1.5, md: 2 }} />
                    <Box h={{ base: 1, sm: 1.5, md: 2, lg: 2.5 }} w={{ base: 12, sm: 16, md: 20, lg: 24 }} bg="bg-white/5" rounded="sm" font="mono" />
                  </Box>
                  {i === 1 && (
                    <Box
                      as={motion.div}
                      position="absolute"
                      right="4"
                      animate={shouldReduceMotion ? {} : {
                        scale: [1, 1.2, 1],
                        boxShadow: [
                          '0 0 20px rgba(25,140,255,0.3)',
                          '0 0 32px rgba(67,201,230,0.4)',
                          '0 0 20px rgba(25,140,255,0.3)'
                        ]
                      }}
                      transition={{ duration: 2, repeat: Infinity }}
                    >
                      <Box w={{ base: 1.5, sm: 2, md: 2.5, lg: 3 }} h={{ base: 1.5, sm: 2, md: 2.5, lg: 3 }} bg="bg-primary-blue" rounded="full" 
                        // eslint-disable-next-line gridpilot-rules/component-classification
                        className="shadow-glow" 
                      />
                    </Box>
                  )}
                </Box>
              ))}
            </Stack>
          </Box>

          <Box as={motion.div} variants={itemVariants}>
            <Text size={{ base: 'xs', sm: 'sm', md: 'base' }} weight="semibold" color="text-white" mb={{ base: 1.5, sm: 2, md: 3, lg: 4 }} block>Recent Results</Text>
            <Text 
              // eslint-disable-next-line gridpilot-rules/component-classification
              style={{ fontSize: '8px' }} 
              color="text-white" 
              opacity={0.5} 
              mb={{ base: 1.5, sm: 2, md: 3 }} 
              block
            >
              Results appear instantly after each race
            </Text>
            <Box bg="bg-iron-gray" rounded="lg" p={{ base: 1.5, sm: 2, md: 3, lg: 4 }} border borderColor="border-charcoal-outline" shadow="0_4px_24px_rgba(0,0,0,0.4)">
              <Box display="flex" alignItems="center" gap={{ base: 1.5, sm: 2, md: 3 }} mb={{ base: 1.5, sm: 2, md: 3 }} pb={{ base: 1.5, sm: 2, md: 3 }} borderBottom borderColor="border-charcoal-outline">
                <Box h={{ base: 1.5, sm: 2, md: 2.5 }} w={{ base: 5, sm: 6, md: 8 }} bg="bg-white/10" rounded="sm" font="mono" />
                <Box h={{ base: 1.5, sm: 2, md: 2.5 }} flexGrow={1} bg="bg-white/10" rounded="sm" />
                <Box h={{ base: 1.5, sm: 2, md: 2.5 }} w={{ base: 8, sm: 10, md: 12 }} bg="bg-white/10" rounded="sm" font="mono" />
              </Box>
              {[1, 2].map((i) => (
                <Box key={i} display="flex" alignItems="center" gap={{ base: 1.5, sm: 2, md: 3 }} py={{ base: 1, sm: 1.5, md: 2 }}>
                  <Box h={{ base: 1.5, sm: 2, md: 2.5 }} w={{ base: 5, sm: 6, md: 8 }} bg="bg-white/5" rounded="sm" font="mono" />
                  <Box h={{ base: 1.5, sm: 2, md: 2.5 }} flexGrow={1} bg="bg-white/5" rounded="sm" />
                  <Box h={{ base: 1.5, sm: 2, md: 2.5 }} w={{ base: 8, sm: 10, md: 12 }} bg="bg-performance-green/20" rounded="sm" textAlign="center" font="mono" color="text-performance-green" />
                </Box>
              ))}
            </Box>
          </Box>
        </Stack>
      </Box>
    </Box>
  );
}
