"use client"
import { useEffect, useRef, useState } from "react"
import Link from "next/link"
import { LayoutGrid, Pencil } from "lucide-react"
import { Button } from "@/components/ui/button"
import {
SUITE_FAVORITE_APPS,
type FavoriteApp,
} from "@/lib/suite/favorite-apps"
import { SUITE_HEADER_DROPDOWN_CLASS, SUITE_ICON_BTN } from "@/lib/suite/suite-chrome-classes"
import { cn } from "@/lib/utils"
const FAVORITE_TILE_CLASS =
"flex flex-col items-center gap-2 rounded-lg p-3 transition-colors hover:bg-accent"
const DEFAULT_ICON_BTN_CLASS = cn(
"rounded-full",
SUITE_ICON_BTN,
"hover:text-accent-foreground",
)
function FavoriteAppTile({
app,
onNavigate,
}: {
app: FavoriteApp
onNavigate?: () => void
}) {
const content = (
<>

{
const target = e.target as HTMLImageElement
target.style.display = "none"
target.parentElement!.innerHTML = `
${app.name[0]}
`
}}
/>
{app.name}
>
)
if (!app.href) {
return (
)
}
if (app.external) {
return (
{content}
)
}
return (
{content}
)
}
interface SuiteFavoritesMenuProps {
className?: string
iconButtonClass?: string
dropdownClass?: string
/** Fermer un autre panneau header (ex. compte) à l’ouverture. */
onOpen?: () => void
}
export function SuiteFavoritesMenu({
className,
iconButtonClass = DEFAULT_ICON_BTN_CLASS,
dropdownClass = SUITE_HEADER_DROPDOWN_CLASS,
onOpen,
}: SuiteFavoritesMenuProps) {
const [open, setOpen] = useState(false)
const menuRef = useRef(null)
useEffect(() => {
function handleClickOutside(event: MouseEvent) {
if (menuRef.current && !menuRef.current.contains(event.target as Node)) {
setOpen(false)
}
}
document.addEventListener("mousedown", handleClickOutside)
return () => document.removeEventListener("mousedown", handleClickOutside)
}, [])
return (
{open ? (
{SUITE_FAVORITE_APPS.map((app) => (
setOpen(false)}
/>
))}
) : null}
)
}