import { Component, Event, h, Host, Prop } from '@stencil/core';
function toggleOption(value = [], option) {
  if (value.indexOf(option) > -1) {
    return value.filter(o => o !== option);
  }
  else {
    return [...value, option];
  }
}
export class DvnTagCloud {
  constructor() {
    this.editable = false;
    this.value = [];
    this.options = [];
  }
  render() {
    const { disabled, editable, options, value } = this;
    if (editable) {
      return (h(Host, null, options.map(option => (h("dvn-button", { disabled: disabled, leaned: true, scale: "small", shape: "rounded", tint: value.includes(option.value) ? 'primary' : 'neutral', view: value.includes(option.value) ? 'solid' : 'outline', onClick: (e) => {
          e.stopPropagation();
          this.change.emit(toggleOption(this.value, option.value));
        } }, option.label)))));
    }
    return (h(Host, null, value.map(v => {
      var _a;
      return (h("dvn-button", { leaned: true, scale: "small", shape: "rounded", view: "outline", tagMode: true }, ((_a = options.find(o => o.value === v)) === null || _a === void 0 ? void 0 : _a.label) || v));
    })));
  }
  static get is() { return "dvn-tag-cloud"; }
  static get originalStyleUrls() { return {
    "$": ["dvn-tag-cloud.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["dvn-tag-cloud.css"]
  }; }
  static get properties() { return {
    "disabled": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "disabled",
      "reflect": false
    },
    "editable": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "attribute": "editable",
      "reflect": false,
      "defaultValue": "false"
    },
    "value": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "string[]",
        "resolved": "string[]",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "[]"
    },
    "options": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "{ label: string, value: string, disabled?: boolean }[]",
        "resolved": "{ label: string; value: string; disabled?: boolean; }[]",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": ""
      },
      "defaultValue": "[]"
    }
  }; }
  static get events() { return [{
      "method": "change",
      "name": "change",
      "bubbles": true,
      "cancelable": true,
      "composed": true,
      "docs": {
        "tags": [],
        "text": ""
      },
      "complexType": {
        "original": "any",
        "resolved": "any",
        "references": {}
      }
    }]; }
}
