import { ReactNode, useEffect, useState } from 'react';
import {
Affix,
AppShell,
Box,
Button,
Flex,
Image,
MantineSpacing,
rem,
Transition,
Text,
UnstyledButton,
} from '@mantine/core';
import { useHeadroom, useViewportSize, useWindowScroll } from '@mantine/hooks';
import Link from 'next/link';
import NextImage from 'next/image';
import CustomDrawer from '@/components/custom_drawer/custom_drawer';
import logoTransparent from '@/public/images/spark_logo_transparent.png';
import { useIsMobile } from '@/utils/breakpoint_utils';
import ImageGrid from '@/components/image_grid/image_grid';
import CustomFooter from '../custom_footer/custom_footer';
interface CustomAppShellProps {
children: ReactNode;
imageSrc?: string[];
height?: number;
width?: number | string;
padding?: MantineSpacing;
}
function CustomAppShell({
imageSrc = [],
height = 900,
width = '100%',
padding = 'md',
children,
}: CustomAppShellProps) {
const pinned = useHeadroom({ fixedAt: 30 });
const isMobile = useIsMobile();
const imageGrid = (
);
const [scroll, scrollTo] = useWindowScroll();
const { height: vh, width: vw } = useViewportSize();
const documentHeight = document.documentElement.scrollHeight;
const [originalHeight, setOriginalHeight] = useState(0);
useEffect(() => {
if (originalHeight <= vh) setOriginalHeight(documentHeight);
}, [scroll]);
return (
<AppShell
header={{
height: 60,
collapsed: isMobile ? !pinned : false,
offset: false,
}}
padding={padding}
>
<AppShell.Header>
<Flex
direction={'row'}
gap={'md'}
px={'md'}
py={'xs'}
align={'center'}
>
<UnstyledButton
component={Link}
href={'/home'}
mr={'auto'}
>
<Image
h={40}
w={'auto'}
fit={'contain'}
component={NextImage}
src={logoTransparent}
alt={'My image'}
/>
</AppShell.Header>
<div style={{ position: 'relative' }}>
<div
style={{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
zIndex: 0,
}}
>
{imageGrid}
<Box
h={'auto'}
bg={'#252525'}
py={'xl'}
>
<div style={{ position: 'relative', zIndex: 1 }}>
<AppShell.Main
style={{ position: 'relative', zIndex: 1 }}
pt={calc(${rem(60)} + var(--mantine-spacing-md))}
>
{children}
</AppShell.Main>
<Affix position={{ bottom: 0, right: 20 }}>
<Transition
transition='slide-up'
mounted={true}
>
{(transitionStyles) => (
<Button
h={'max-content'}
style={transitionStyles}
onClick={() => scrollTo({ y: 0 })}
>
<Flex direction={'column'}>
<Text>Scroll Y:{scroll.y}</Text>
<Text>ViewPort Height: {vh}</Text>
<Text>Original Height: {originalHeight}</Text>
<Text>Document Height: {documentHeight}</Text>
<Text> Combination: {scroll.y + vh} </Text>
</Flex>
</Button>
)}
</Transition>
</Affix>
{scroll.y + vh >= originalHeight && <CustomFooter />}
</AppShell>
);
}
export default CustomAppShell;