import { RTEFilterStylesStrategy } from '../filter-styles-strategy.abstract';
import { HorizontalAlignmentAnnotation } from '../../annotations/horizontal-alignment-annotation';
/**
 * Filters redundant `textAlign` from `customStyle` when parsing blocks that carry
 * a semantic `textAlign` annotation (RTETextBlock, RTEListBlock, RTEListItemBlock).
 *
 * During source-to-normal round-trips the `HorizontalAlignmentAnnotation` emits
 * `text-align` as an inline style (standalone mode), and `CustomStyleAnnotationHandler`
 * captures it into `customStyle`.  This strategy removes the duplicate so the
 * semantic annotation is the single source of truth.
 */
export class AlignmentFilterStylesStrategy extends RTEFilterStylesStrategy {
  constructor() {
    super(...arguments);
    this.stylesToBeFiltered = {};
  }
  /**
   * @returns {boolean} Always `true` — alignment inline styles are always emitted
   * in standalone/source-edit mode, so the duplicate is always safe to remove.
   */
  get alwaysFilter() {
    return true;
  }
  /**
   * Removes `textAlign` from `customStyle` when it duplicates the value returned
   * by `HorizontalAlignmentAnnotation.getDefaultStyles(textAlign)`.
   *
   * @param {VegaRTEAnnotations} annotations - The annotations object (mutated in place).
   * @returns {VegaRTEAnnotations} The same annotations reference.
   */
  filterAnnotations(annotations) {
    const { textAlign, customStyle } = annotations;
    if (!textAlign || !customStyle) {
      return annotations;
    }
    this.stylesToBeFiltered = HorizontalAlignmentAnnotation.getDefaultStyles(textAlign);
    return super.filterAnnotations(annotations);
  }
}
