import { IconButton, Tooltip, useScrollTrigger } from "@mui/material";
import { Link, useLocation, useNavigate } from "@tanstack/react-router";
import React, { useEffect, useLayoutEffect, useRef } from "react";
import { useShallow } from "zustand/shallow";
import { AppStatusIndicator } from "@/components/appStatus";
import BackButton from "@/components/buttons/backButton";
import CastButton from "@/components/buttons/castButton";
import { UserAvatarMenu } from "@/components/userAvatarMenu";
import WindowControls from "@/components/windowControls";
import {
getLocalMediaTransfer,
useCurrentMediaItem,
} from "@/utils/methods/localTransfer";
import useSearchStore from "@/utils/store/search";
import { shouldShowTitlebar } from "./routeVisibility";
import { type AppNavItem, useAppNavigation } from "./useAppNavigation";
import "./appTitlebar.scss";
const BlinkMark = () => (
);
const isItemActive = (item: AppNavItem, pathname: string) =>
item.kind === "home"
? pathname === "/home"
: pathname === `/library/${item.libraryId}` ||
(item.key === "music" && pathname.startsWith("/music/"));
const NavItem = ({ item, active }: { item: AppNavItem; active: boolean }) => {
const className = `app-titlebar-nav-link${active ? " is-active" : ""}`;
if (item.kind === "home") {
return (
{item.label}
);
}
return (
{item.label}
);
};
export const AppTitlebar = () => {
const { pathname } = useLocation();
const navigate = useNavigate();
const visible = shouldShowTitlebar(pathname);
const isHome = pathname === "/home";
const scrolled = useScrollTrigger({
disableHysteresis: true,
threshold: 20,
});
const navigation = useAppNavigation(visible);
const navRef = useRef(null);
const currentMedia = useCurrentMediaItem();
const toggleSearchDialog = useSearchStore(
useShallow((s) => s.toggleSearchDialog),
);
useLayoutEffect(() => {
document.documentElement.classList.toggle("has-app-titlebar", visible);
}, [visible]);
useEffect(() => {
const active = navRef.current?.querySelector(
".app-titlebar-nav-link.is-active",
);
active?.scrollIntoView({
behavior: "smooth",
block: "nearest",
inline: "center",
});
}, [pathname, navigation.length]);
if (!visible) return null;
const overlay = isHome && !scrolled;
return (
<>
Blink
search
navigate({ to: "/downloads" })}
aria-label="Загрузки"
>
download
settings
>
);
};