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 { InjectVegaSlimmer, MapToComponentField, MapToComponentMethod, VegaSlimmer, methodPlaceholder, } from 'vega-slimmer/core';
import { MutationObserverSlimmer } from '../../../../helpers/slimmers/mutation-observer/mutation-observer-slimmer';
import { InternalProgressTrackerStep } from './dto/internal-progress-tracker-step';
/**
 * Controls the current steps of the progress tracker component.
 */
export class VegaProgressTrackerCurrentStepsController extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.mutationObserver = new MutationObserverSlimmer({
      // eslint-disable-next-line jsdoc/require-jsdoc
      target: () => this.host,
      options: {
        childList: true,
        subtree: true,
      },
      // eslint-disable-next-line jsdoc/require-jsdoc
      callback: /* istanbul ignore next */ () => {
        this.appendSlotAttribute();
        this.syncUpCurrentSteps();
      },
    });
  }
  /** connectedCallback */
  connectedCallback() {
    this.appendSlotAttribute();
  }
  /** disconnectedCallback */
  disconnectedCallback() {
    methodPlaceholder();
  }
  /** componentWillLoad */
  componentWillLoad() {
    this.syncUpCurrentSteps();
  }
  /** componentDidLoad */
  componentDidLoad() {
    methodPlaceholder();
  }
  /** while steps changed, we need sync up current steps */
  watchSteps() {
    this.syncUpCurrentSteps();
  }
  /** while current state changed, we need sync up current steps */
  watchCurrentChange() {
    this.syncUpCurrentSteps();
  }
  /** while completedStepArray changed, we need sync up current steps */
  watchCompletedStepArray() {
    this.syncUpCurrentSteps();
  }
  /** while completedSteps changed, we need sync up current steps */
  watchCompletedSteps() {
    this.syncUpCurrentSteps();
  }
  /**
   * Sync up current steps
   */
  syncUpCurrentSteps() {
    this.currentSteps = this.renderModeController.isSourceRenderMode()
      ? InternalProgressTrackerStep.fromSteps(this.host, this.steps, this.current, this.deprecatedPropertySlimmer.getValue())
      : InternalProgressTrackerStep.fromHostSlot(this.host, this.current, this.deprecatedPropertySlimmer.getValue());
  }
  /**
   * If template mode, append slot attribute to each step element in host.
   */
  appendSlotAttribute() {
    if (!this.renderModeController.isSourceRenderMode()) {
      Array.from(this.host.querySelectorAll('vega-progress-tracker-step')).map((step, index) => {
        step.setAttribute('slot', `step-${index}`);
      });
    }
  }
}
__decorate([
  MapToComponentField()
], VegaProgressTrackerCurrentStepsController.prototype, "host", void 0);
__decorate([
  MapToComponentField()
], VegaProgressTrackerCurrentStepsController.prototype, "steps", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaProgressTrackerCurrentStepsController.prototype, "currentSteps", void 0);
__decorate([
  MapToComponentField()
], VegaProgressTrackerCurrentStepsController.prototype, "renderModeController", void 0);
__decorate([
  MapToComponentField()
], VegaProgressTrackerCurrentStepsController.prototype, "current", void 0);
__decorate([
  MapToComponentField()
], VegaProgressTrackerCurrentStepsController.prototype, "deprecatedPropertySlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaProgressTrackerCurrentStepsController.prototype, "mutationObserver", void 0);
__decorate([
  MapToComponentMethod('connectedCallback')
], VegaProgressTrackerCurrentStepsController.prototype, "connectedCallback", null);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaProgressTrackerCurrentStepsController.prototype, "disconnectedCallback", null);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaProgressTrackerCurrentStepsController.prototype, "componentWillLoad", null);
__decorate([
  MapToComponentMethod('componentDidLoad')
], VegaProgressTrackerCurrentStepsController.prototype, "componentDidLoad", null);
__decorate([
  MapToComponentMethod('watchSteps')
], VegaProgressTrackerCurrentStepsController.prototype, "watchSteps", null);
__decorate([
  MapToComponentMethod('watchCurrentChange')
], VegaProgressTrackerCurrentStepsController.prototype, "watchCurrentChange", null);
__decorate([
  MapToComponentMethod('watchCompletedStepArray')
], VegaProgressTrackerCurrentStepsController.prototype, "watchCompletedStepArray", null);
__decorate([
  MapToComponentMethod('watchCompletedSteps')
], VegaProgressTrackerCurrentStepsController.prototype, "watchCompletedSteps", null);
