import { ActionHandleStrategy } from '../../../dto/action-handle-strategies/action-handle-strategy.abstract';
/**
 * Update table cell properties action handler strategy
 */
export class UpdateTableCellPropertiesStrategy extends ActionHandleStrategy {
  /**
   * @inheritDoc
   */
  handleAction(action, target) {
    const annotation = action.toAnnotation();
    const tableCellRef = this.getDOMByEntity(target);
    if (tableCellRef) {
      const { width, height, borderStr, padding, textAlign, verticalAlign } = annotation;
      const backgroundColor = annotation.renderStyle().backgroundColor || '';
      tableCellRef.style.backgroundColor = backgroundColor;
      tableCellRef.style.border = borderStr;
      tableCellRef.style.width = width;
      tableCellRef.style.height = height;
      tableCellRef.style.padding = padding;
      tableCellRef.style.textAlign = textAlign;
      tableCellRef.style.verticalAlign = verticalAlign;
      this.updateCustomStyleAnnotation(target, [
        'backgroundColor',
        'border',
        'width',
        'height',
        'padding',
        'textAlign',
        'verticalAlign',
      ]);
    }
  }
}
