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, MapToComponentField, VegaSlimmer } from 'vega-slimmer/core';
export class VegaSegmentControlSelectedController extends VegaSlimmer {
  /**
   * Component lifecycle - [componentWillLoad]{@link VegaSegmentControl.componentWillLoad}
   */
  componentWillLoad() {
    this.setDefaultSelected();
  }
  watchSegments() {
    this.setDefaultSelected();
  }
  watchSelected() {
    this.changeEventEmitter.emit(this.selected);
  }
  setSelected(props) {
    this.selected = props.key;
  }
  setDefaultSelected() {
    var _a;
    if (((_a = this.segments) === null || _a === void 0 ? void 0 : _a.length) > 0 &&
      !this.segments.find((segment) => segment.key === this.selected)) {
      this.selected = this.segments[0].key;
    }
  }
}
__decorate([
  MapToComponentField({ writable: true })
], VegaSegmentControlSelectedController.prototype, "selected", void 0);
__decorate([
  MapToComponentField()
], VegaSegmentControlSelectedController.prototype, "segments", void 0);
__decorate([
  MapToComponentField()
], VegaSegmentControlSelectedController.prototype, "changeEventEmitter", void 0);
__decorate([
  MapToComponentMethod('componentWillLoad')
], VegaSegmentControlSelectedController.prototype, "componentWillLoad", null);
__decorate([
  MapToComponentMethod('watchSegments')
], VegaSegmentControlSelectedController.prototype, "watchSegments", null);
__decorate([
  MapToComponentMethod('watchSelected')
], VegaSegmentControlSelectedController.prototype, "watchSelected", null);
