import { View } from "@tarojs/components";
import React from "react";
import PageWrapper from "../page-wrapper/index";
import { useAppStore } from "@/store/appStore";

interface Props {
  children?: React.ReactChild | React.ReactChild[];
  bgColor?: string;
  isflex?: boolean; // 有横向滚动的scroll-view 容器不能包裹在 flex comlumn 布局中
  style?: React.CSSProperties;
  styleBg?: string|null;
  paddingTop?: number;
  fullPage?: boolean;
  isTabPage?: boolean; // tab 页需要单独去掉 bottomSafeHeight
  onClick?: (e:any)=> void
}

const Index: React.FC<Props> = ({ children, isTabPage = false, isflex = true, fullPage = false,  paddingTop, style, styleBg, onClick }) => {
  const headerHeight = useAppStore((state) => state.headerHeight);
  const bottomSafeHeight = useAppStore((state) => state.bottomSafeHeight);
  const flexStyle = isflex ? "flex flex-col items-center" : "";
  const offsetTop = paddingTop ?? headerHeight;
  const pageHeight = fullPage ? `calc(100vh - ${ isTabPage ? 0 : bottomSafeHeight}px)` : 'auto'
  
  return (
    <PageWrapper style={style} styleBg={styleBg} onClick={onClick}>
      <View
          className={`${flexStyle} h-full w-full`}
          style={{ paddingTop: offsetTop, height: pageHeight}}
        >
          {children}
        </View>
    </PageWrapper>
  );
};

export default Index;
