import { ListAnnotation } from '../../annotations/list-annotation';
import { RTEFilterStylesStrategy } from '../filter-styles-strategy.abstract';
import { Predicate } from '../predicate';
/**
 * Filters the default ListAnnotation styles (paddingLeft, marginLeft) from
 * customStyle when parsing an RTEListBlock.
 */
export class ListBlockFilterStylesStrategy extends RTEFilterStylesStrategy {
  constructor() {
    super(...arguments);
    this.stylesToBeFiltered = ListAnnotation.getDefaultStyles();
    this.elementTagName = 'ol,ul';
  }
  /**
   * @inheritDoc
   */
  canFilter(blockOrNodeInstance) {
    return Predicate.isListBlock(blockOrNodeInstance.constructor.name);
  }
  /**
   * @inheritDoc
   */
  canRefill(blockOrNodeClassName, element) {
    return Predicate.isListBlock(blockOrNodeClassName) && element.matches(this.elementTagName);
  }
  /**
   * @inheritDoc
   */
  toCssText() {
    const selector = this.elementTagName
      .split(',')
      .map((tag) => `.${RTEFilterStylesStrategy.RTE_CONTENT_CONTAINER_CLASS_NAME} ${tag.trim()}`)
      .join(', ');
    return `${selector} { ${this.convertStylesMapToCssText(this.stylesToBeFiltered)} }`;
  }
}
