import { ReactElement } from 'react';

import { Center, Flex, Text, Wrap, WrapItem } from '@chakra-ui/react';
import { LuCrown, LuDisc3, LuEar, LuFileAudio } from 'react-icons/lu';
import { MdGroup } from 'react-icons/md';
import { useNavigate } from 'react-router-dom';

import { PageLayout } from '@/components/Layout/PageLayout';
import { TopBar } from '@/components/TopBar/TopBar';
import { useThemeMode } from '@/utils/theme-tools';

type HomeListType = {
  id: number;
  name: string;
  icon: ReactElement;
  to: string;
};
const homeList: HomeListType[] = [
  {
    id: 1,
    name: 'Genders',
    icon: <LuCrown size="60%" height="full" />,
    to: 'gender',
  },
  {
    id: 2,
    name: 'Artists',
    icon: <MdGroup size="60%" height="full" />,
    to: 'artist',
  },
  {
    id: 3,
    name: 'Albums',
    icon: <LuDisc3 size="60%" height="full" />,
    to: 'album',
  },
  {
    id: 4,
    name: 'Tracks',
    icon: <LuFileAudio size="60%" height="full" />,
    to: 'track',
  },
  {
    id: 5,
    name: 'Playlists',
    icon: <LuEar size="60%" height="full" />,
    to: 'playlists',
  },
];

export const HomePage = () => {
  const { mode } = useThemeMode();
  const navigate = useNavigate();
  const onSelectItem = (data: HomeListType) => {
    navigate(data.to);
  };
  return (
    <>
      <TopBar title="Home" />
      <PageLayout>
        <Wrap spacing="20px" marginX="auto" padding="20px" justify="center">
          {homeList.map((data) => (
            <WrapItem
              width="200px"
              height="190px"
              border="1px"
              borderColor="brand.900"
              backgroundColor={mode('#FFFFFF88', '#00000088')}
              key={data.id}
              padding="5px"
              as="button"
              _hover={{
                boxShadow: 'outline-over',
                bgColor: mode('#FFFFFFF7', '#000000F7'),
              }}
              onClick={() => onSelectItem(data)}
            >
              <Flex direction="column" width="full" height="full">
                <Center height="full">{data.icon}</Center>
                <Center>
                  <Text
                    fontSize="25px"
                    fontWeight="bold"
                    textTransform="uppercase"
                    userSelect="none"
                  >
                    {data.name}
                  </Text>
                </Center>
              </Flex>
            </WrapItem>
          ))}
        </Wrap>
      </PageLayout>
    </>
  );
};
