'use client';

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

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

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

  if (isMobile) {
    return (
      <Stack position="relative" fullWidth fullHeight bg="graphite-black" rounded="none" p={3} overflow="hidden">
        <Stack gap={4}>
          <Stack display="flex" alignItems="center" gap={3} mb={2}>
            <Stack 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>
              <Stack position="absolute" top="-1px" left="-1px" w="2" h="2" borderTop borderLeft borderColor="primary-accent" />
            </Stack>
            <Stack>
              <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>
            </Stack>
          </Stack>

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

          <Stack>
            <Text size="xs" weight="bold" color="text-gray-500" mb={3} block className="uppercase tracking-widest">Latest Result</Text>
            <Stack bg="panel-gray/40" rounded="none" p={3} border borderColor="border-gray/50">
              <Stack display="flex" alignItems="center" gap={3} py={2} borderBottom borderColor="border-gray/30">
                <Stack h="1.5" w="6" bg="white/10" rounded="none" />
                <Stack h="1.5" flexGrow={1} bg="white/10" rounded="none" />
                <Stack h="1.5" w="10" bg="white/10" rounded="none" />
              </Stack>
              <Stack display="flex" alignItems="center" gap={3} py={2}>
                <Stack h="1.5" w="6" bg="white/5" rounded="none" />
                <Stack h="1.5" flexGrow={1} bg="white/5" rounded="none" />
                <Stack h="1.5" w="10" bg="success-green/20" rounded="none" />
              </Stack>
            </Stack>
          </Stack>
        </Stack>
      </Stack>
    );
  }

  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 (
    <Stack position="relative" fullWidth fullHeight bg="graphite-black" rounded="none" p={{ base: 1.5, sm: 3, md: 5, lg: 8 }} overflow="hidden">
      <Stack
        as={motion.div}
        variants={containerVariants}
        initial="hidden"
        animate="visible"
      >
        <Stack gap={{ base: 1.5, sm: 3, md: 4, lg: 6 }}>
          <Stack as={motion.div} variants={itemVariants}>
            <Stack display="flex" alignItems="center" gap={{ base: 1.5, sm: 2, md: 3, lg: 4 }} mb={{ base: 1, sm: 1.5, md: 2 }}>
              <Stack 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>
                <Stack position="absolute" top="-1px" left="-1px" w="2" h="2" borderTop borderLeft borderColor="primary-accent" />
              </Stack>
              <Stack>
                <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>
              </Stack>
            </Stack>
          </Stack>

          <Stack 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) => (
                <Stack
                  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 }
                  }}
                >
                  <Stack 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>
                  </Stack>
                  <Stack flexGrow={1}>
                    <Stack h="1.5" w={i === 1 ? "32" : "24"} bg="white/10" rounded="none" mb={{ base: 1, sm: 1.5, md: 2 }} />
                    <Stack h="1" w="16" bg="white/5" rounded="none" />
                  </Stack>
                  {i === 1 && (
                    <Stack
                      as={motion.div}
                      position="absolute"
                      right="4"
                      animate={shouldReduceMotion ? {} : {
                        opacity: [1, 0.4, 1]
                      }}
                      transition={{ duration: 2, repeat: Infinity }}
                    >
                      <Stack w="1.5" h="1.5" bg="primary-accent" rounded="full" />
                    </Stack>
                  )}
                </Stack>
              ))}
            </Stack>
          </Stack>

          <Stack 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>
            <Stack bg="panel-gray/20" rounded="none" p={{ base: 1.5, sm: 2, md: 3, lg: 4 }} border borderColor="border-gray/50">
              <Stack 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">
                <Stack h="1" w="6" bg="white/10" rounded="none" />
                <Stack h="1" flexGrow={1} bg="white/10" rounded="none" />
                <Stack h="1" w="10" bg="white/10" rounded="none" />
              </Stack>
              {[1, 2].map((i) => (
                <Stack key={i} display="flex" alignItems="center" gap={{ base: 1.5, sm: 2, md: 3 }} py={{ base: 1, sm: 1.5, md: 2 }}>
                  <Stack h="1" w="6" bg="white/5" rounded="none" />
                  <Stack h="1" flexGrow={1} bg="white/5" rounded="none" />
                  <Stack h="1" w="10" bg={i === 1 ? "success-green/20" : "white/5"} rounded="none" />
                </Stack>
              ))}
            </Stack>
          </Stack>
        </Stack>
      </Stack>
    </Stack>
  );
}
