import { FC, useCallback, useMemo, useEffect, memo } from "react"; //import { type ComponentProcessProps } from "components/system/Apps/RenderComponent"; import RndWindow from "./RndWindow"; import StyledWindow from "./StyledWindow"; import Titlebar from "./Titlebar"; import useFocusable from "./useFocusable"; import useWindowTransitions from "./useWindowTransitions"; import { useWindows } from "@/contexts/windows"; import { useSession } from "@/contexts/session"; import { useMainElements } from "@/contexts/elements"; import { WindowProvider } from "@/contexts/windows/window"; import styled from "styled-components"; import ScrollBars from "@/styles/common/ScrollBars"; import { defaultStyles } from "@/styles/defaults"; import { useSignal } from "@/contexts/signal"; import { useConfig } from "@/contexts/config"; import { useWindow } from "@/contexts/windows/window"; const StyledPeekViewport = styled.div` ${defaultStyles} background-color: inherit; height: inherit; width: inherit; `; const StyledWindowWrapper = styled.div` ${defaultStyles} display: flex; flex-direction: column; position: relative; width: 100%; height: 100%; justify-content: center; `; const StyledWindowContent = styled.div` ${ScrollBars({ scrollbarGutter: false })} flex: 1; height: 100%; width: 100%; position: relative; display: flex; overflow: auto; `; // TODO: Take care of the different styled components inside the acutal components, // TODO: So Should take care of which styled component to actually render within. // eslint-disable-next-line @typescript-eslint/no-explicit-any const Window: FC = ({ children, id }) => { const { linkElement, windows: { [id]: currentWindow }, } = useWindows(); const { backgroundColor, Component, hideTitlebar, peekElement, maximized, snap, } = currentWindow || {}; const { disableAnimations } = useConfig(); const { foregroundId } = useSession(); const isForeground = id === foregroundId; const { zIndex, ...focusableProps } = useFocusable(id); const { previewID } = useSession() const windowTransitions = useWindowTransitions(id, maximized); const linkViewportEntry = useCallback( (viewportEntry: HTMLDivElement) => { if (Component && !peekElement && viewportEntry) { linkElement(id, "peekElement", viewportEntry); } }, [Component, id, linkElement, peekElement] ); const isSnap = snap && typeof snap === "object"; const isPreview = previewID !== false; const isPreviewAndNotOnUs = isPreview && previewID !== id //const isPreview = previewID !== false; //const highlightPreview = previewID !== false && previewID == id; return ( {!hideTitlebar && } {children} ); }; const MemoWindow = memo(Window); const WindowWithContext: FC = ({ children, id, ...others }) => { return ( {children} ); }; export default memo(WindowWithContext);