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 { Component, h, Host, Prop, State, Event, Element, Watch } from '@stencil/core';
import { sanitizeVegaComponent } from '../../utils/component';
import { ItemToggleTransitionMillisecond } from '../../constants/ui';
import { DomNodeSubjectObserverFactory } from '../../helpers/change-manager/subject/dom-node-subject/dom-node-subject-observer-factory';
import { VegaClick, VegaToggleStatus } from '../../helpers/event-manager/event-id/vega-event-id';
import { createEventEmitSlimmer, } from '../../helpers/event-manager/slimmers/event-emit-slimmer';
import { InjectVegaGlobalSlimmer, InjectVegaSlimmer } from 'vega-slimmer/core';
import { createDeprecatedPropertySlimmer, } from '../../helpers/slimmers/deprecated-property-slimmer';
import { VegaComponentUsageRuntimeMetricsSlimmer } from '../../helpers/slimmers/component-usage-runtime-metrics';
import { VegaItemToggleRuntimeMetricsPayloadDefinition } from '../../constants/runtime-metrics-payload-definition/vega-item-toggle/runtime-metrics-payload-definition';
/**
 * @vegaVersion 1.0.5
 */
export class VegaItemToggle {
  constructor() {
    this.globalSlimmers = {};
    this.toggleStatusEventEmitter = createEventEmitSlimmer(VegaItemToggle, VegaToggleStatus);
    this.deprecatedPropertySlimmer = createDeprecatedPropertySlimmer(VegaItemToggle, 'statusMap', 'itemToggleStatusMap', VegaItemToggle.defaultStatusMap);
    this.vegaComponentUsageRuntimeMetricsSlimmer = new VegaComponentUsageRuntimeMetricsSlimmer(VegaItemToggleRuntimeMetricsPayloadDefinition);
    this.toggleItemStatus = 'unToggled';
    /**
     * Defines the labels and icons associated with the toggle states.
     * @deprecated This property will be removed soon and replaced by prop statusMap
     *
     * @vegaVersion 1.3.0
     * @defaultValue {unToggledIcon: 'plus-sign', toggledIcon: 'delete-bin', unToggledLabel: 'Add', togglingLabel: 'Added', toggledLabel: 'Remove', unTogglingLabel: 'Removed'}
     */
    this.itemToggleStatusMap = VegaItemToggle.defaultStatusMap;
    /**
     * Defines the labels and icons associated with the toggle states.
     *
     * @vegaVersion 2.2.0
     * @defaultValue {unToggledIcon: 'plus-sign', toggledIcon: 'delete-bin', unToggledLabel: 'Add', togglingLabel: 'Added', toggledLabel: 'Remove', unTogglingLabel: 'Removed'}
     */
    this.statusMap = VegaItemToggle.defaultStatusMap;
    /**
     * Determines whether the item is toggled on.
     *
     * @vegaVersion 1.3.0
     */
    /* eslint-disable-next-line @stencil/strict-mutable */
    this.isToggled = false;
    this.handleToggle = () => {
      if (!this.isTogglingOrUnToggling()) {
        this.updateToggleStatus();
      }
    };
  }
  onToggledPropsChange() {
    this.updateTransitionStatus();
  }
  componentWillLoad() {
    this.updateTransitionStatus();
  }
  render() {
    return sanitizeVegaComponent(h(Host, { class: {
        'vega-toggled-status': this.isTogglingOrUnToggling(),
      } },
      this.renderLabelDom(),
      h("vega-button-circle", { size: "small", variant: "secondary", icon: this.toggleItemStatus === 'unToggled'
          ? this.deprecatedPropertySlimmer.getValue().unToggledIcon || 'plus-sign'
          : this.toggleItemStatus === 'toggled'
            ? this.deprecatedPropertySlimmer.getValue().toggledIcon || 'delete-bin'
            : 'checkmark', ref: (ref) => {
          DomNodeSubjectObserverFactory.addUniqueObserverToNode(ref, VegaClick, this.handleToggle);
        } })), this.host);
  }
  renderLabelDom() {
    let label;
    switch (this.toggleItemStatus) {
      case 'unToggled':
        label = this.deprecatedPropertySlimmer.getValue().unToggledLabel;
        break;
      case 'toggling':
        label = this.deprecatedPropertySlimmer.getValue().togglingLabel;
        break;
      case 'toggled':
        label = this.deprecatedPropertySlimmer.getValue().toggledLabel;
        break;
      case 'unToggling':
        label = this.deprecatedPropertySlimmer.getValue().unTogglingLabel;
        break;
    }
    return h("div", null, label || 'No label defined');
  }
  isTogglingOrUnToggling() {
    return this.toggleItemStatus === 'toggling' || this.toggleItemStatus === 'unToggling';
  }
  updateToggleStatus() {
    switch (this.toggleItemStatus) {
      case 'unToggled':
        this.toggleItemStatus = 'toggling';
        setTimeout(() => {
          this.isToggled = true;
        }, ItemToggleTransitionMillisecond);
        break;
      case 'toggled':
        this.toggleItemStatus = 'unToggling';
        setTimeout(() => {
          this.isToggled = false;
        }, ItemToggleTransitionMillisecond);
        break;
    }
  }
  updateTransitionStatus() {
    this.isToggled ? (this.toggleItemStatus = 'toggled') : (this.toggleItemStatus = 'unToggled');
    this.toggleStatusEventEmitter.emit(this.isToggled);
  }
  static get is() { return "vega-item-toggle"; }
  static get encapsulation() { return "shadow"; }
  static get originalStyleUrls() { return {
    "$": ["vega-item-toggle.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["vega-item-toggle.css"]
  }; }
  static get properties() { return {
    "itemToggleStatusMap": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "ItemToggleStatusMap",
        "resolved": "{ unToggledIcon?: string; toggledIcon?: string; unToggledLabel?: string; togglingLabel?: string; toggledLabel?: string; unTogglingLabel?: string; }",
        "references": {
          "ItemToggleStatusMap": {
            "location": "import",
            "path": "./types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "deprecated",
            "text": "This property will be removed soon and replaced by prop statusMap"
          }, {
            "name": "vegaVersion",
            "text": "1.3.0"
          }, {
            "name": "defaultValue",
            "text": "{unToggledIcon: 'plus-sign', toggledIcon: 'delete-bin', unToggledLabel: 'Add', togglingLabel: 'Added', toggledLabel: 'Remove', unTogglingLabel: 'Removed'}"
          }],
        "text": "Defines the labels and icons associated with the toggle states."
      },
      "defaultValue": "VegaItemToggle.defaultStatusMap"
    },
    "statusMap": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "ItemToggleStatusMap",
        "resolved": "{ unToggledIcon?: string; toggledIcon?: string; unToggledLabel?: string; togglingLabel?: string; toggledLabel?: string; unTogglingLabel?: string; }",
        "references": {
          "ItemToggleStatusMap": {
            "location": "import",
            "path": "./types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "2.2.0"
          }, {
            "name": "defaultValue",
            "text": "{unToggledIcon: 'plus-sign', toggledIcon: 'delete-bin', unToggledLabel: 'Add', togglingLabel: 'Added', toggledLabel: 'Remove', unTogglingLabel: 'Removed'}"
          }],
        "text": "Defines the labels and icons associated with the toggle states."
      },
      "defaultValue": "VegaItemToggle.defaultStatusMap"
    },
    "isToggled": {
      "type": "boolean",
      "mutable": true,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.3.0"
          }],
        "text": "Determines whether the item is toggled on."
      },
      "attribute": "is-toggled",
      "reflect": false,
      "defaultValue": "false"
    }
  }; }
  static get states() { return {
    "toggleItemStatus": {}
  }; }
  static get events() { return [{
      "method": "vegaToggleStatus",
      "name": "vegaToggleStatus",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "vegaVersion",
            "text": "1.3.0"
          }],
        "text": "An event emitter notifying an item toggle event."
      },
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      }
    }, {
      "method": "toggleStatus",
      "name": "toggleStatus",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [{
            "name": "eventSemantics",
            "text": "namespace:native"
          }, {
            "name": "vegaVersion",
            "text": "2.0.0"
          }],
        "text": "An event emitter notifying an item toggle event."
      },
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      }
    }]; }
  static get elementRef() { return "host"; }
  static get watchers() { return [{
      "propName": "isToggled",
      "methodName": "onToggledPropsChange"
    }]; }
}
VegaItemToggle.defaultStatusMap = {
  unToggledIcon: 'plus-sign',
  toggledIcon: 'delete-bin',
  unToggledLabel: 'Add',
  togglingLabel: 'Added',
  toggledLabel: 'Remove',
  unTogglingLabel: 'Removed',
};
__decorate([
  InjectVegaGlobalSlimmer()
], VegaItemToggle.prototype, "globalSlimmers", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaItemToggle.prototype, "toggleStatusEventEmitter", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaItemToggle.prototype, "deprecatedPropertySlimmer", void 0);
__decorate([
  InjectVegaSlimmer()
], VegaItemToggle.prototype, "vegaComponentUsageRuntimeMetricsSlimmer", void 0);
