var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  return c > 3 && r && Object.defineProperty(target, key, r), r;
};
import { MapToComponentField, MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
import { isArrayEqual } from '../../../../utils/array';
/**
 * attach the extension styles to the host.
 */
export class RTEExtensionStylesController extends VegaSlimmer {
  /**
   * Attach extension styles to the host after load.
   */
  attachExtensionStyles() {
    this.attachStylesToHost();
  }
  /**
   * Update extension context when extensions property changes.
   *
   * @param {VegaRTEExtension[]} newValue - New extensions array.
   * @param {VegaRTEExtension[]} oldValue - Old extensions array.
   */
  handleExtensionsChange(newValue, oldValue) {
    if (!isArrayEqual(newValue, oldValue, false, (a, b) => a === b ? 0 : 1)) {
      this.attachStylesToHost();
    }
  }
  /**
   * Collects and attaches custom styles from all extensions to the host component.
   */
  attachStylesToHost() {
    if (this.extensions) {
      let customStyles = '';
      for (const extension of this.extensions) {
        const extensionStyles = extension.collectExtensionRendererStyles();
        if (extensionStyles) {
          customStyles += `${extensionStyles}\n`;
        }
      }
      this.extensionStyles = customStyles;
    }
  }
}
__decorate([
  MapToComponentField()
], RTEExtensionStylesController.prototype, "extensions", void 0);
__decorate([
  MapToComponentField()
], RTEExtensionStylesController.prototype, "host", void 0);
__decorate([
  MapToComponentField({ writable: true })
], RTEExtensionStylesController.prototype, "extensionStyles", void 0);
__decorate([
  MapToComponentMethod('componentWillLoad')
], RTEExtensionStylesController.prototype, "attachExtensionStyles", null);
__decorate([
  MapToComponentMethod('watchExtensions')
], RTEExtensionStylesController.prototype, "handleExtensionsChange", null);
