export function isKeyboardTargetActive(
  target: HTMLElement | null | undefined,
  reactActive: boolean,
): boolean {
  return reactActive || (target != null && document.activeElement === target);
}

export function blurKeyboardTarget(
  target: HTMLElement | null | undefined,
): void {
  if (!target || document.activeElement !== target) return;
  target.blur();
}

export function getActiveElementTag(): string | null {
  const activeElement = document.activeElement;
  if (!activeElement) return null;

  const id = activeElement.id ? `#${activeElement.id}` : "";
  const className =
    typeof activeElement.className === "string" && activeElement.className
      ? `.${activeElement.className.split(/\s+/).filter(Boolean).join(".")}`
      : "";

  return `${activeElement.tagName.toLowerCase()}${id}${className}`;
}
