"use client";
import { cnb } from "cnbuilder";
import { useAppSize } from "../media-queries/AppSizeProvider.js";
import { useToggle } from "../useToggle.js";
import { useHorizontalLayoutTransition } from "./useHorizontalLayoutTransition.js";
import { useSsr } from "../SsrProvider.js";
import { useTemporaryLayout } from "./useTemporaryLayout.js";
/**
 * @example Main Usage
 * ```tsx
 * import {
 *   AppBarTitle,
 *   Button,
 *   LayoutAppBar,
 *   LayoutNav,
 *   Main,
 *   Sheet,
 *   useExpandableLayout,
 * } from "@react-md/core";
 * import type { ReactElement, ReactNode } from "react";
 *
 * import { CustomNavigation } from "./CustomNavigation";
 *
 * export interface LayoutProps {
 *   children: ReactNode;
 * }
 *
 * export function Layout(props: LayoutProps): ReactElement {
 *   const { children } = props;
 *
 *   // choose whichever one for your app
 *   // nextjs app dir
 *   const pathname = usePathname();
 *   // nextjs pages
 *   const { pathname } = useRouter();
 *   // react router
 *   const { pathname } = useHistory();
 *
 *   const {
 *     temporary,
 *     appBarProps,
 *     expandableNavProps,
 *     mainProps,
 *     navToggleProps,
 *     temporaryNavProps,
 *     windowSplitterProps,
 *   } = useExpandableLayout({ pathname });
 *
 *   return {
 *     <>
 *       <LayoutAppBar {...appBarProps}>
 *         <Button {...navToggleProps} />
 *         <AppBarTitle>Hello, world!</AppBarTitle>
 *       </LayoutAppBar>
 *       <LayoutNav {...expandableNavProps}>
 *         <CustomNavigation />
 *       </LayoutNav>
 *       {temporary && (
 *         <Sheet {...temporaryNavProps}>
 *           <CustomNavigation />
 *         </Sheet>
 *       )}
 *       <Main {...mainProps}>{children}</Main>
 *     </>
 *   }
 * }
 * ```
 *
 * If you have a large navigation panel, you can conditionally render the
 * `LayoutNav` with the `persistent` boolean returned by the hook which will
 * ensure that the DOM has rehydrated before unmounting to prevent SSR errors.
 *
 * @example Safely Conditionally Rendering
 * ```diff
 *   const {
 *     temporary,
 * +   persistent,
 *     appBarProps,
 *     expandableNavProps,
 *     mainProps,
 *     navToggleProps,
 *     temporaryNavProps,
 *     windowSplitterProps,
 *   } = useExpandableLayout({ pathname });
 *
 *   return {
 *     <>
 *       <LayoutAppBar {...appBarProps}>
 *         <Button {...navToggleProps} />
 *         <AppBarTitle>Hello, world!</AppBarTitle>
 *       </LayoutAppBar>
 * -     <LayoutNav {...expandableNavProps}>
 * -       <CustomNavigation />
 * -     </LayoutNav>
 * +     {persistent && (
 * +       <LayoutNav {...expandableNavProps}>
 * +         <CustomNavigation />
 * +       </LayoutNav>
 * +     )}
 *       {temporary && (
 *         <Sheet {...temporaryNavProps}>
 *           <CustomNavigation />
 *         </Sheet>
 *       )}
 *       <Main {...mainProps}>{children}</Main>
 *     </>
 *   }
 * ```
 *
 * @since 6.0.0
 * @see {@link useResizableLayout}
 */ export function useExpandableLayout(options) {
    const { fullHeightNav = false, temporaryUntil = "tablet", transitionProps, defaultExpanded = fullHeightNav === "static", ...temporaryOptions } = options;
    const ssr = useSsr();
    const { appBarProps, mainProps, navToggleProps, temporaryNavProps, hideTemporaryNav, showTemporaryNav, visible } = useTemporaryLayout(temporaryOptions);
    const { toggled: expanded, enable: expandNavigation, disable: collapseNavigation, toggle: toggleNavigation } = useToggle(defaultExpanded);
    const { elementProps } = useHorizontalLayoutTransition({
        ...transitionProps,
        transitionIn: expanded
    });
    const { isPhone, isDesktop } = useAppSize();
    const temporary = isPhone || temporaryUntil === "desktop" && !isDesktop;
    return {
        visible,
        temporary,
        persistent: ssr || !temporary,
        hideTemporaryNav,
        showTemporaryNav,
        expanded,
        expandNavigation,
        collapseNavigation,
        toggleNavigation,
        appBarProps: {
            ...appBarProps,
            ...fullHeightNav ? elementProps : {}
        },
        mainProps: {
            ...mainProps,
            ...elementProps
        },
        temporaryNavProps,
        expandableNavProps: {
            expanded,
            appBarOffset: !fullHeightNav
        },
        navToggleProps: {
            ...navToggleProps,
            onClick () {
                if (temporary) {
                    showTemporaryNav();
                } else {
                    toggleNavigation();
                }
            },
            className: cnb(fullHeightNav === "static" && "rmd-layout-nav-toggle")
        }
    };
}

//# sourceMappingURL=useExpandableLayout.js.map