import MuiAppBar from "@mui/material/AppBar";
import IconButton from "@mui/material/IconButton";
import Tooltip from "@mui/material/Tooltip";
import Typography from "@mui/material/Typography";
import useScrollTrigger from "@mui/material/useScrollTrigger";
import { useLocation, useNavigate } from "@tanstack/react-router";
import React, { useCallback, useState } from "react";
import "./appBar.scss";
import { useShallow } from "zustand/shallow";
import { openSyncPlayDialog } from "@/utils/methods/syncPlay";
import useHeaderStore from "@/utils/store/header";
import useSearchStore from "@/utils/store/search";
import BackButton from "../buttons/backButton";
import CastButton from "../buttons/castButton";
import { UserAvatarMenu } from "../userAvatarMenu";
import { NavigationDrawer } from "./navigationDrawer";
import WindowControls from "../windowControls";
const MemoizeBackButton = React.memo(BackButton);
const HIDDEN_PATHS = [
"/login",
"/setup",
"/server",
"/player",
"/error",
"/settings",
"/library",
"/search",
// The home page draws its own header inside the hero frame.
"/home",
];
/** Whether the global app header is drawn for this route. */
export const shouldShowAppBar = (pathname: string) =>
!HIDDEN_PATHS.some(
(path) =>
(pathname.startsWith(path) && pathname !== "/player/audio") ||
pathname === "/",
);
const AppBarContent = () => {
const navigate = useNavigate();
const location = useLocation();
const toggleSearchDialog = useSearchStore(
useShallow((s) => s.toggleSearchDialog),
);
// This hook subscribes to page scroll; keep it out of hidden routes.
const trigger = useScrollTrigger({
disableHysteresis: true,
threshold: 20,
});
const [showDrawer, setShowDrawer] = useState(false);
const handleDrawerClose = useCallback(() => {
setShowDrawer(false);
}, []);
const handleDrawerOpen = useCallback(() => {
setShowDrawer(true);
}, []);
const handleNavigateToHome = useCallback(() => navigate({ to: "/home" }), []);
const handleNavigateToFavorite = useCallback(() => {
navigate({ to: "/favorite" });
}, []);
const { pageTitle } = useHeaderStore(
useShallow((s) => ({ pageTitle: s.pageTitle })),
);
const fallbackTitle = (() => {
const path = location.pathname;
if (path === "/favorite") return "Favorites";
if (path.startsWith("/music/")) return "Music";
if (path.startsWith("/player/audio")) return "Now Playing";
return "";
})();
const title = pageTitle || fallbackTitle;
return (
<>
menu
home
{title && (
{title}
)}
groups
search
favorite
>
);
};
export const AppBar = () => {
const location = useLocation();
if (!shouldShowAppBar(location.pathname)) return null;
return ;
};