import { jsx as _jsx } from "react/jsx-runtime";
import { forwardRef, } from "react";
import { Avatar } from "../../components/ui/avatar";
import { cn } from "../../lib/utils";
import { getFeedbackAvatarClassName, useFeedbackAuthor, } from "../reviews/feedbackAvatar";
function getFeedbackAuthorDedupeKey(item) {
    const author = item.author?.trim();
    if (author)
        return author.toLocaleLowerCase();
    const displayName = item.authorDisplayName?.trim();
    if (displayName)
        return displayName.toLocaleLowerCase();
    return item.id;
}
export function dedupeFeedbackHighlightItems(items, isPreferred = () => false) {
    const dedupedByAuthor = new Map();
    for (const item of items) {
        const key = getFeedbackAuthorDedupeKey(item);
        const existing = dedupedByAuthor.get(key);
        if (!existing || (!isPreferred(existing) && isPreferred(item))) {
            dedupedByAuthor.set(key, item);
        }
    }
    return Array.from(dedupedByAuthor.values());
}
export const FeedbackHighlightBadge = forwardRef(function FeedbackHighlightBadge({ item, isSelected = false, isDimmed = false, zIndex, testId, ariaSubject, variant = "default", minimapColorClassName, className, style, ...buttonProps }, ref) {
    const author = useFeedbackAuthor(item);
    const authorColorClassName = getFeedbackAvatarClassName(item);
    const dotColorClassName = minimapColorClassName ?? authorColorClassName;
    if (variant === "minimap") {
        return (_jsx("button", { ref: ref, type: "button", className: cn("relative -ml-0.5 flex h-3 w-3 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent p-0 transition-transform first:ml-0 hover:scale-125 focus-visible:outline-none", isSelected && "scale-125", isDimmed && "opacity-40", className), style: { ...style, zIndex }, "data-testid": testId, "aria-label": `Open ${ariaSubject} by ${author.displayName}`, title: author.displayName, ...buttonProps, children: _jsx("span", { className: cn("block size-2 rounded-full", dotColorClassName, isSelected && "scale-125", isDimmed && "opacity-70") }) }));
    }
    return (_jsx("button", { ref: ref, type: "button", className: cn("relative -ml-1.5 flex h-7 w-7 cursor-pointer items-center justify-center rounded-full border-0 bg-transparent p-0 transition-transform first:ml-0 hover:scale-105 focus-visible:outline-none", isSelected && "scale-105", isDimmed && "opacity-40", className), style: { ...style, zIndex }, "data-testid": testId, "aria-label": `Open ${ariaSubject} by ${author.displayName}`, title: author.displayName, ...buttonProps, children: _jsx(Avatar, { src: author.avatarUrl, name: author.displayName, fallbackColor: author.fallbackColor, fallbackClassName: authorColorClassName, size: "sm", className: "size-7 border border-white !text-[10px] font-medium", title: author.displayName }) }));
});
export function FeedbackHighlightBadgeTray({ children, className, style, variant = "default", }) {
    return (_jsx("div", { className: cn(variant === "minimap"
            ? "pointer-events-auto absolute z-[100] flex items-center"
            : "pointer-events-auto absolute z-[100] flex items-center rounded-[15px] rounded-bl-none bg-white p-[3px] shadow-[0_0_6px_0_var(--color-neutral-grey-15)]", className), style: style, children: children }));
}
//# sourceMappingURL=FeedbackHighlightBadge.js.map