import React, { ReactNode } from 'react';
import { Box, Icon, IconButton, Icons, Scroll, Text, config } from 'folds';
import { BackRouteHandler } from '../../../components/BackRouteHandler';
import {
  Page,
  PageContent,
  PageContentCenter,
  PageHeader,
  PageHero,
  PageHeroSection,
} from '../../../components/page';
import { ScreenSize, useScreenSizeContext } from '../../../hooks/useScreenSize';

type BotStatePageProps = {
  title: ReactNode;
  description: ReactNode;
  icon?: ReactNode;
  children?: ReactNode;
};

export function BotStatePage({ title, description, icon, children }: BotStatePageProps) {
  const screenSize = useScreenSizeContext();

  return (
    // Safe-top on the wrapper, not on `PageHeader`: the recipe is a
    // folds `Header size="600"` with fixed height, so inner padding
    // would clip its content (same constraint as PageNav, Page.tsx).
    // No-op on web / inside Modal500 where `--vojo-safe-top` is 0px.
    <Page style={{ paddingTop: 'var(--vojo-safe-top, 0px)' }}>
      {screenSize === ScreenSize.Mobile && (
        <PageHeader balance outlined={false}>
          <Box grow="Yes" alignItems="Center" gap="200">
            <BackRouteHandler>
              {(onBack) => (
                <IconButton onClick={onBack}>
                  <Icon src={Icons.ArrowLeft} />
                </IconButton>
              )}
            </BackRouteHandler>
            <Text size="H4" truncate>
              {title}
            </Text>
          </Box>
        </PageHeader>
      )}
      <Box grow="Yes">
        <Scroll hideTrack visibility="Hover">
          <PageContent>
            <PageContentCenter>
              <PageHeroSection>
                <PageHero
                  icon={icon ?? <Icon size="600" src={Icons.Info} />}
                  title={title}
                  subTitle={description}
                >
                  {children && (
                    <Box
                      direction="Column"
                      alignItems="Center"
                      gap="200"
                      style={{ paddingTop: config.space.S200 }}
                    >
                      {children}
                    </Box>
                  )}
                </PageHero>
              </PageHeroSection>
            </PageContentCenter>
          </PageContent>
        </Scroll>
      </Box>
    </Page>
  );
}
