'use client';

import { memo } from 'react';
import { cn } from '@djangocfg/ui-core/lib';

export interface TreeLabelProps {
  children: React.ReactNode;
  isMatchingSearch?: boolean;
  className?: string;
}

/**
 * TreeLabel — truncated label for a tree row.
 *
 * Memoised: re-renders only when `children`, `isMatchingSearch` or
 * `className` change. `children` is compared by reference.
 */
function TreeLabelRaw({ children, isMatchingSearch, className }: TreeLabelProps) {
  return (
    <span
      style={{ fontSize: 'var(--tree-font-size)' }}
      className={cn(
        'truncate leading-tight tracking-[-0.005em]',
        isMatchingSearch && 'font-medium text-foreground',
        className,
      )}
    >
      {children}
    </span>
  );
}

export const TreeLabel = memo(TreeLabelRaw);
