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';
/**
 * Sync the property value from parent group.
 */
export class VegaSelectionChipStateController extends SubStateObserverSlimmer {
  // eslint-disable-next-line jsdoc/require-jsdoc
  constructor() {
    super({
      parent: 'vega-selection-chip-group',
      subStates: [
        {
          subStateName: 'disabled',
          parentStateName: 'disabled',
          /**
           * If group defined disabled property we should synchronize this value,
           * 		otherwise keep the disabled value in selection chip unchanged.
           *
           * @param {Nullable<boolean>} groupDisabled - Disabled value in parent selection chip group.
           */
          callback: (groupDisabled) => {
            if (typeof groupDisabled === 'boolean') {
              this.disabled = groupDisabled;
            }
          },
        },
        {
          subStateName: 'selectType',
          parentStateName: 'selectType',
          /**
           * If group defined selectType property we should synchronize this value.
           *
           * @param {VegaSelectionChipGroupSelectType} selectType - SelectType value in parent selection chip group.
           */
          callback: (selectType) => {
            this.selectType = selectType === 'checkbox' ? 'checkbox' : 'radio';
          },
        },
        {
          subStateName: 'checked',
          parentStateName: 'value',
          /**
           * Synchronize checked status according by the value from parent selection chip group.
           *
           * @param {string | string[]} groupValue - The value from parent selection chip group.
           */
          callback: (groupValue) => {
            this.checkedController.setChecked(Array.isArray(groupValue)
              ? groupValue.includes(this.value)
              : groupValue === this.value);
          },
        },
      ],
    });
  }
}
__decorate([
  MapToComponentField()
], VegaSelectionChipStateController.prototype, "host", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaSelectionChipStateController.prototype, "disabled", void 0);
__decorate([
  MapToComponentField({ writable: true })
], VegaSelectionChipStateController.prototype, "selectType", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionChipStateController.prototype, "value", void 0);
__decorate([
  MapToComponentField()
], VegaSelectionChipStateController.prototype, "checkedController", void 0);
