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 } from 'vega-slimmer/core';
import { SubStateObserverSlimmer } from '../../../../helpers/slimmers/sub-state/sub-state-observer-slimmer';
/**
 * The `VegaSelectionTileStateController` class is a TypeScript class that observes and manages
 * the state of a `HTMLVegaSelectionTileElement` component.
 */
export class VegaSelectionTileStateController extends SubStateObserverSlimmer {
  // eslint-disable-next-line jsdoc/require-jsdoc
  constructor() {
    super({
      parent: 'vega-selection-tile-group',
      subStates: [
        {
          subStateName: 'selectType',
          parentStateName: 'selectType',
        },
        {
          subStateName: 'disabled',
          parentStateName: 'disabled',
          /**
           * If group defined disabled property we should synchronize this value,
           * 		otherwise keep the disabled value in selection tile unchanged.
           *
           * @param {Nullable<boolean>} groupDisabled - Disabled value in parent selection tile group.
           */
          callback: (groupDisabled) => {
            if (typeof groupDisabled === 'boolean') {
              this.disabled = groupDisabled;
            }
          },
        },
        {
          subStateName: 'checked',
          parentStateName: 'value',
          /**
           * Synchronize checked status according by the value from parent selection tile group.
           *
           * @param {string | string[]} groupValue - The value from parent selection tile group.
           */
          callback: (groupValue) => {
            this.checkedController.setChecked(Array.isArray(groupValue)
              ? groupValue.includes(this.value)
              : groupValue === this.value);
          },
        },
        {
          subStateName: 'distributeEvenly',
          parentStateName: 'distributeEvenly',
        },
      ],
    });
  }
}
__decorate([
  MapToComponentField()
], VegaSelectionTileStateController.prototype, "host", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaSelectionTileStateController.prototype, "selectType", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaSelectionTileStateController.prototype, "disabled", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionTileStateController.prototype, "checked", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionTileStateController.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionTileStateController.prototype, "checkedController", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaSelectionTileStateController.prototype, "distributeEvenly", void 0);
