import { t } from '@grafana/i18n';
import { type SceneObject } from '@grafana/scenes';

import { type DashboardDataLayerSet } from '../../scene/DashboardDataLayerSet';
import {
  type EditableDashboardElement,
  type EditableDashboardElementInfo,
} from '../../scene/types/EditableDashboardElement';
import { partitionAnnotationsByDisplay } from '../../sidebar/dashboard/DashboardAnnotationsList';

export class AnnotationSetEditableElement implements EditableDashboardElement {
  public readonly isEditableDashboardElement = true;

  public constructor(private dataLayerSet: DashboardDataLayerSet) {}

  public getEditableElementInfo(): EditableDashboardElementInfo {
    return {
      typeName: t('dashboard.sidebar.elements.annotation-set', 'Annotations & Alerts'),
      icon: 'comment-alt',
      instanceName: t('dashboard.sidebar.elements.annotation-set', 'Annotations & Alerts'),
      isHidden: this.dataLayerSet.state.annotationLayers.length === 0,
    };
  }

  public getOutlineChildren(): SceneObject[] {
    const { visible, controlsMenu, hidden } = partitionAnnotationsByDisplay(this.dataLayerSet.state.annotationLayers);
    return [...visible, ...controlsMenu, ...hidden];
  }
}
