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 { MapToComponentMethod, VegaSlimmer } from 'vega-slimmer/core';
import { UPDATE_TRANSLATION } from '../../change-manager/subject/static-subject/static-subject-title';
import ChangeManager from '../../change-manager/change-manager';
import { Observer } from '../../change-manager/observer/observer';
import { forceUpdate } from '@stencil/core';
import { VegaInternalTranslation } from '../../translation/internal-translation-controller';
/**
 * Class responsible for observing translation updates and triggering re-renders.
 */
export class VegaTranslateObserverSlimmer extends VegaSlimmer {
  constructor(option) {
    super();
    this.component = option.component;
  }
  /**
   * Component lifecycle - [connectedCallback]
   * Registers an observer to watch for translation updates, which triggers a forced update on the component.
   */
  connectedCallback() {
    this.observer = new Observer(this.isAcceptable.bind(this), () => {
      forceUpdate(this.component);
    });
    ChangeManager.register(UPDATE_TRANSLATION, this.observer);
  }
  /**
   * Component lifecycle - [disconnectedCallback]
   * Unregister the observer when the component is disconnected from the DOM.
   */
  disconnectedCallback() {
    if (this.observer) {
      ChangeManager.unregister(UPDATE_TRANSLATION, this.observer);
      this.observer = null;
    }
  }
  /**
   * Determines whether the observer should accept changes.
   *
   * @returns {boolean} Always returns true in the current implementation.
   */
  isAcceptable() {
    var _a, _b;
    const host = this.component['host'];
    return (_b = (_a = VegaInternalTranslation.getConnectedComponents().get(host.tagName)) === null || _a === void 0 ? void 0 : _a.has(host)) !== null && _b !== void 0 ? _b : false;
  }
}
__decorate([
  MapToComponentMethod('connectedCallback')
], VegaTranslateObserverSlimmer.prototype, "connectedCallback", null);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaTranslateObserverSlimmer.prototype, "disconnectedCallback", null);
