import { Outlet, useNavigation } from "react-router";
import { HydrateFallback } from "../HydrateFallback";
import { AppBar } from "../AppBar";
import styled from "styled-components";
import { WebScoketContext } from "../../context/WebsocketContext";
import { Alert } from "antd";
import { useEffect } from "react";
import { initServiceWorker } from "../../utils/firebase-frontend";

const StyledContainer = styled.div`
  padding-bottom: 90px;
  box-sizing: border-box;
`;
export const AppBarLayout = () => {
  const navigation = useNavigation();
  const loading = navigation.state === 'loading';
  useEffect(() => {
    initServiceWorker();
  }, []);
  return loading ? <HydrateFallback /> : (<StyledContainer>
    <WebScoketContext.Provider value={{}}>
      <Alert.ErrorBoundary>
        <Outlet />
      </Alert.ErrorBoundary>
      <AppBar />
    </WebScoketContext.Provider>
  </StyledContainer>);
}