import { useDocumentStore } from '../stores/document';
import { getManifest } from '../core/widgets';
import { t } from '../core/i18n';

/** True when a note's element no longer exists in the document (page notes never are). */
export function isRemoved(elementId: string): boolean {
  return Boolean(elementId) && !useDocumentStore().get(elementId);
}

/** What a note is attached to: the element's navigator name, "Page", or "Element removed". */
export function anchorLabel(elementId: string): string {
  if (!elementId) return t('Page');
  const el = useDocumentStore().get(elementId);
  if (!el) return t('Element removed');
  return el.label || t(getManifest(el.type)?.title ?? '') || el.type;
}
