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, methodPlaceholder, VegaSlimmer, } from 'vega-slimmer/core';
import { MutationObserverSlimmer } from '../../../../helpers/slimmers/mutation-observer/mutation-observer-slimmer';
import { TagNameAndAttributeMutationFilter } from '../../../../helpers/slimmers/mutation-observer/mutation-observer-filters';
/** The `VegaButtonGroupAllItemsDisabledController` class monitors child button group items' disabled state and computes whether all items are disabled. */
export class VegaButtonGroupAllItemsDisabledController extends VegaSlimmer {
  constructor() {
    super(...arguments);
    this.mutationObserver = new MutationObserverSlimmer({
      // eslint-disable-next-line jsdoc/require-jsdoc
      target: /* istanbul ignore next */ () => this.host,
      options: {
        childList: true,
        subtree: true,
        attributes: true,
        attributeFilter: ['disabled'],
      },
      mutationFilter: TagNameAndAttributeMutationFilter('VEGA-BUTTON-GROUP-ITEM'),
      // eslint-disable-next-line jsdoc/require-jsdoc
      callback: /* istanbul ignore next */ () => this.updateAllItemsDisabledState(),
    });
  }
  /**
   * Component lifecycle - [disconnectedCallback]
   */
  disconnectedCallback() {
    methodPlaceholder();
  }
  /**
   * Component lifecycle - [componentWillLoad]
   */
  componentWillLoad() {
    this.updateAllItemsDisabledState();
  }
  /**
   * Check if all button group items are disabled and update the state.
   */
  updateAllItemsDisabledState() {
    const items = this.host.querySelectorAll('vega-button-group-item');
    this.allItemsDisabled =
      items.length > 0 &&
        Array.from(items).every((item) => item.disabled);
  }
}
__decorate([
  MapToComponentField()
], VegaButtonGroupAllItemsDisabledController.prototype, "host", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaButtonGroupAllItemsDisabledController.prototype, "allItemsDisabled", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaButtonGroupAllItemsDisabledController.prototype, "mutationObserver", void 0);
__decorate([
  MapToComponentMethod('disconnectedCallback')
], VegaButtonGroupAllItemsDisabledController.prototype, "disconnectedCallback", null);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaButtonGroupAllItemsDisabledController.prototype, "componentWillLoad", null);
