import { ReactNode, useEffect } from 'react';

import { Flex, FlexProps } from '@chakra-ui/react';
import { useLocation } from 'react-router-dom';

import { PageLayout } from '@/components/Layout/PageLayout';
import { useColorModeValue } from '@/components/ui/color-mode';
import { colors } from '@/theme/colors';

export type LayoutProps = FlexProps & {
  children: ReactNode;
};

export const PageLayoutInfoCenter = ({
  children,
  width = '25%',
  ...rest
}: LayoutProps) => {
  const { pathname } = useLocation();

  useEffect(() => {
    window.scrollTo(0, 0);
  }, [pathname]);

  return (
    <PageLayout>
      <Flex
        direction="column"
        margin="auto"
        minWidth={width}
        border="back.900"
        borderWidth="1px"
        borderRadius="8px"
        padding="10px"
        boxShadow={'0px 0px 16px ' + colors.back[900]}
        backgroundColor={useColorModeValue('#FFFFFF', '#000000')}
        {...rest}
      >
        {children}
      </Flex>
    </PageLayout>
  );
};
