import { useMemo } from "react"; import { useTheme } from "styled-components"; import { type Size } from "./useResizable"; import { parseSnap } from "../functions"; import { type Variant } from "framer-motion"; import { useWindows } from "@/contexts/windows"; import { DEFAULT_WINDOW_SIZE } from "@/utils/constants"; import { SnapInfo } from "@/contexts/windows/types"; import { useMainElements } from "@/contexts/elements"; import { getElementSize } from "@/utils/functions"; const useDefaultSize = (id: string): Size => { const { windows: { [id]: currentWindow } = {} } = useWindows(); const { defaultSize, snap = false } = currentWindow || {}; const { WindowsViewArea, WindowsViewAreaSize } = useMainElements(); const isSnap = useMemo(() => snap && typeof snap === "object", [snap]); const data: Variant | null = useMemo(() => { if (isSnap) { const parentSize = WindowsViewArea ? getElementSize(WindowsViewArea) : WindowsViewAreaSize; return parseSnap(snap as SnapInfo, parentSize); } return null; // eslint-disable-next-line react-hooks/exhaustive-deps }, [isSnap, snap, WindowsViewArea]); return useMemo(() => { if (isSnap && data) { return { height: data.height as number, // Cast to number width: data.width as number, // Cast to number }; } return defaultSize ? { height: defaultSize.height, width: defaultSize.width, } : DEFAULT_WINDOW_SIZE; }, [isSnap, data, defaultSize]); }; export default useDefaultSize;