"use client";
import { useCallback, useState } from "react";
import { useSsr } from "./SsrProvider.js";
import { useResizeListener } from "./useResizeListener.js";
/**
 * This is just a convenience wrapper around the {@link useResizeListener}.
 *
 * @example Simple Example
 * ```tsx
 * import { useWindowSize } from "@react-md/core/useWindowSize";
 * import type { ReactElement } from "react";
 * import { useState } from "react";
 *
 * function Example(): ReactElement {
 *   const { height, width } = useWindowSize();
 *
 *   return (
 *     <>
 *       The current window size:
 *       <pre><code>{JSON.stringify(size, null, 2)}</code></pre>
 *     </>
 *   );
 * }
 * ```
 *
 * @since 6.0.0
 */ export function useWindowSize(options = {}) {
    const { once, signal, capture, passive, throttle, ssrHeight = 0, ssrWidth = 0, disableWidth, disableHeight } = options;
    const ssr = useSsr();
    const [size, setSize] = useState(()=>{
        if (typeof window === "undefined" || ssr) {
            return {
                height: ssrHeight,
                width: ssrWidth
            };
        }
        return {
            height: window.innerHeight,
            width: window.innerWidth
        };
    });
    useResizeListener({
        once,
        signal,
        capture,
        passive,
        throttle,
        disabled: disableHeight && disableWidth,
        onUpdate: useCallback(()=>{
            setSize((prevSize)=>{
                const nextSize = {
                    height: window.innerHeight,
                    width: window.innerWidth
                };
                const isHeightChange = !disableHeight && prevSize.height !== nextSize.height;
                const isWidthChange = !disableWidth && prevSize.width !== nextSize.width;
                return isHeightChange || isWidthChange ? nextSize : prevSize;
            });
        }, [
            disableHeight,
            disableWidth
        ])
    });
    return size;
}

//# sourceMappingURL=useWindowSize.js.map