'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="graphite-black" rounded="none" p={3} overflow="hidden">
        <Stack gap={4}>
          <Box display="flex" alignItems="center" gap={3} mb={2}>
            <Box h="12" w="12" rounded="none" border borderWidth="1px" borderColor="primary-accent/50" bg="panel-gray" display="flex" alignItems="center" justifyContent="center" className="relative">
              <Text size="2xl">🏆</Text>
              <Box position="absolute" top="-1px" left="-1px" w="2" h="2" borderTop borderLeft borderColor="primary-accent" />
            </Box>
            <Box>
              <Text size="base" weight="bold" color="text-white" block className="uppercase tracking-widest">Super GT</Text>
              <Text size="xs" color="text-gray-500" block font="mono">ROUND 8/12</Text>
            </Box>
          </Box>

          <Box>
            <Text size="xs" weight="bold" color="text-gray-500" mb={3} block className="uppercase tracking-widest">Next Race</Text>
            <Box position="relative" display="flex" alignItems="center" gap={3} bg="panel-gray/40" rounded="none" p={3} border borderColor="border-gray/50">
              <Box h="8" w="8" bg="graphite-black" rounded="none" border borderColor="primary-accent/20" display="flex" alignItems="center" justifyContent="center">
                <Text size="base">🏁</Text>
              </Box>
              <Box flexGrow={1}>
                <Box h="2" w="28" bg="white/10" rounded="none" mb={2} />
                <Box h="1.5" w="20" bg="white/5" rounded="none" />
              </Box>
              <Box w="1.5" h="1.5" bg="primary-accent" rounded="full" className="animate-pulse" />
            </Box>
          </Box>

          <Box>
            <Text size="xs" weight="bold" color="text-gray-500" mb={3} block className="uppercase tracking-widest">Latest Result</Text>
            <Box bg="panel-gray/40" rounded="none" p={3} border borderColor="border-gray/50">
              <Box display="flex" alignItems="center" gap={3} py={2} borderBottom borderColor="border-gray/30">
                <Box h="1.5" w="6" bg="white/10" rounded="none" />
                <Box h="1.5" flexGrow={1} bg="white/10" rounded="none" />
                <Box h="1.5" w="10" bg="white/10" rounded="none" />
              </Box>
              <Box display="flex" alignItems="center" gap={3} py={2}>
                <Box h="1.5" w="6" bg="white/5" rounded="none" />
                <Box h="1.5" flexGrow={1} bg="white/5" rounded="none" />
                <Box h="1.5" w="10" bg="success-green/20" rounded="none" />
              </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="graphite-black" rounded="none" 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="none" border borderWidth="1px" borderColor="primary-accent/50" bg="panel-gray" display="flex" alignItems="center" justifyContent="center" className="relative">
                <Text size={{ base: 'base', sm: 'xl', md: '2xl', lg: '3xl' }}>🏆</Text>
                <Box position="absolute" top="-1px" left="-1px" w="2" h="2" borderTop borderLeft borderColor="primary-accent" />
              </Box>
              <Box>
                <Heading level={2} fontSize={{ base: 'sm', sm: 'base', md: 'lg', lg: 'xl' }} weight="bold" color="text-white" mb={0.5} className="uppercase tracking-widest">Super GT Championship</Heading>
                <Text 
                  // eslint-disable-next-line gridpilot-rules/component-classification
                  style={{ fontSize: '9px' }} 
                  color="text-gray-500"
                  font="mono"
                  className="uppercase tracking-widest"
                >
                  SEASON 3 • ROUND 8/12
                </Text>
              </Box>
            </Box>
          </Box>

          <Box as={motion.div} variants={itemVariants}>
            <Text size={{ base: 'xs', sm: 'sm' }} weight="bold" color="text-gray-500" mb={{ base: 1.5, sm: 2, md: 3 }} block className="uppercase tracking-[0.2em]">Upcoming Races</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="panel-gray/40"
                  rounded="none"
                  p={{ base: 1.5, sm: 2, md: 3, lg: 4 }}
                  border
                  borderColor="border-gray/50"
                  whileHover={shouldReduceMotion ? {} : {
                    x: 4,
                    borderColor: '#198CFF50',
                    transition: { duration: 0.15 }
                  }}
                >
                  <Box h={{ base: 6, sm: 7, md: 8, lg: 10 }} w={{ base: 6, sm: 7, md: 8, lg: 10 }} bg="graphite-black" rounded="none" border borderColor="primary-accent/20" display="flex" alignItems="center" justifyContent="center">
                    <Text size={{ base: 'sm', sm: 'base', md: 'lg', lg: 'xl' }}>🏁</Text>
                  </Box>
                  <Box flexGrow={1}>
                    <Box h="1.5" w={i === 1 ? "32" : "24"} bg="white/10" rounded="none" mb={{ base: 1, sm: 1.5, md: 2 }} />
                    <Box h="1" w="16" bg="white/5" rounded="none" />
                  </Box>
                  {i === 1 && (
                    <Box
                      as={motion.div}
                      position="absolute"
                      right="4"
                      animate={shouldReduceMotion ? {} : {
                        opacity: [1, 0.4, 1]
                      }}
                      transition={{ duration: 2, repeat: Infinity }}
                    >
                      <Box w="1.5" h="1.5" bg="primary-accent" rounded="full" />
                    </Box>
                  )}
                </Box>
              ))}
            </Stack>
          </Box>

          <Box as={motion.div} variants={itemVariants}>
            <Text size={{ base: 'xs', sm: 'sm' }} weight="bold" color="text-gray-500" mb={{ base: 1.5, sm: 2, md: 3 }} block className="uppercase tracking-[0.2em]">Recent Results</Text>
            <Box bg="panel-gray/20" rounded="none" p={{ base: 1.5, sm: 2, md: 3, lg: 4 }} border borderColor="border-gray/50">
              <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-gray/30">
                <Box h="1" w="6" bg="white/10" rounded="none" />
                <Box h="1" flexGrow={1} bg="white/10" rounded="none" />
                <Box h="1" w="10" bg="white/10" rounded="none" />
              </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="1" w="6" bg="white/5" rounded="none" />
                  <Box h="1" flexGrow={1} bg="white/5" rounded="none" />
                  <Box h="1" w="10" bg={i === 1 ? "success-green/20" : "white/5"} rounded="none" />
                </Box>
              ))}
            </Box>
          </Box>
        </Stack>
      </Box>
    </Box>
  );
}
