import './es.object.keys-d3dfcee5.js';
import { c as createId } from './utils-7eb3ddfa.js';
import { B as BaseHoverBox } from './BaseHoverBox-d4e9fbd8.js';
import { n as normalizeComponent } from './normalize-component-1b2cdbb6.js';
import './well-known-symbol-50ce04e7.js';
import './object-keys-9554322f.js';
import './typeof-6c6d8d7a.js';
import './unsupportedIterableToArray-577176bf.js';
import './es.array.join-0615c07b.js';
import './array-method-is-strict-52649d4d.js';
import './es.array.map-4fca2d97.js';
import './array-iteration-ff0210fd.js';
import './function-bind-context-b3fabf77.js';
import './array-species-create-5816b140.js';
import './array-method-has-species-support-656e7824.js';
import './regexp-exec-abstract-624370ca.js';
import './string-multibyte-7b13020f.js';
import './regexp-flags-e2ab70ab.js';
import './es.string.split-220a43b5.js';
import './is-regexp-8abbad11.js';
import './es.array.slice-d73dafe0.js';
import './create-property-57a65091.js';
import './es.object.to-string-737ededb.js';
import './classof-7133e1c1.js';
import './es.regexp.to-string-e7ade2d0.js';
import './es.string.replace-9c64527b.js';
import './es.array.includes-42f5881f.js';
import './es.string.includes-e1768f8b.js';
import './es.array.sort-92ee60ae.js';
import './web.dom-collections.for-each-79a2d6b8.js';
import './dom-iterables-b6f5ef3b.js';
import './BaseImageBox-666878a3.js';
import './es.symbol.description-b01c009b.js';
import './set-to-string-tag-0ef163ef.js';
import './BaseBox-88c3238f.js';
import './BaseIcon-bcb4fb2a.js';
import './es.array.concat-f2cfcc9b.js';
import './BaseImage-12f88cf1.js';
import './es.object.values-b107765e.js';
import 'lazysizes';

/**
 * Basic Chip component
 */

var script = {
  name: 'BaseChip',
  components: {
    BaseHoverBox: BaseHoverBox
  },
  model: {
    prop: 'entry',
    event: 'value-changed'
  },
  props: {
    /**
     * @model
     *
     * pass the text for the chip
     */
    entry: {
      type: String,
      required: true
    },

    /**
     * set if entry is a linked data entry and displayed with grey background
     */
    isLinked: {
      type: Boolean,
      default: true
    },

    /**
     * if a hover box is associated with the chip add all relevant properties here
     * (@see [BaseHoverBox](#basehoverbox) for details)
     */
    hoverBoxContent: {
      type: Object,
      default: function _default() {
        return {};
      }
    },

    /**
     * set chip active (set color)
     */
    chipActive: {
      type: Boolean,
      default: false
    },

    /**
     * flag to specify if chip can be removed
     */
    isRemovable: {
      type: Boolean,
      default: true
    },

    /**
     * add some custom text styling
     */
    textStyling: {
      type: Object,
      default: function _default() {
        return {};
      }
    },

    /**
     * define true if chip should be editable on click
     * <br>
     * CAVEAT: chips can not showhoverBoxContent as soon as it is editable
     * respectively - if both are set true edit functionality takes precedent - chip will
     *  not be draggable, hoverBoxContent will not be shown!
     */
    editable: {
      type: Boolean,
      default: false
    },
    assistiveText: {
      type: String,
      default: ''
    }
  },
  data: function data() {
    return {
      /**
       * internal represenation of string provided by parent
       * @type {string}
       */
      entryInt: '',

      /**
       * handle showing of HoverBox
       * @type {boolean}
       */
      showInfoBox: false
    };
  },
  computed: {
    hoverBoxEnabled: function hoverBoxEnabled() {
      return this.isLinked && !!Object.keys(this.hoverBoxContent).length;
    },
    internalId: function internalId() {
      return createId();
    }
  },
  watch: {
    entry: {
      handler: function handler(val) {
        if (val !== this.entryInt) {
          this.entryInt = val;
        }
      },
      immediate: true
    }
  },
  methods: {
    /**
     * update the internal text variable if chip is editable and
     * inform parent
     * @param {KeyboardEvent} event
     */
    updateText: function updateText(event) {
      var textString = event.target.innerText;

      if (this.editable && textString !== this.entryInt) {
        this.entryInt = textString;
        /**
         * if chip is editable value is updated with this event
         *
         * @event value-changed
         * @type {string}
         */

        this.$emit('value-changed', this.entryInt);
      }
    },
    clickAction: function clickAction(e) {
      if (!this.editable) {
        e.stopPropagation();
        /**
         * event emitted when chip is clicked
         *
         * @event clicked
         *
         */

        this.$emit('clicked');

        if (this.isLinked) {
          this.$emit('hoverbox-active', true);
          this.$refs.hoverBox.setPosition(e);
          this.showInfoBox = !this.showInfoBox;
        }
      }
    },
    moveBox: function moveBox(e) {
      if (this.hoverBoxEnabled && this.showInfoBox) {
        this.$refs.hoverBox.setPosition(e);
      }
    },
    hideBox: function hideBox() {
      if (this.hoverBoxEnabled) {
        /**
         * event indicating if hover box was set to show / hide
         *
         * @type {Boolean}
         *
         */
        this.$emit('hoverbox-active', false);
        this.showInfoBox = false;
      }
    },
    onMouseDown: function onMouseDown(event) {
      /**
       * event on mouse down, needed by base chips input to determine active chip
       *
       * @type {Event}
       *
       */
      this.$emit('mouse-down', event);
    },
    removeClicked: function removeClicked() {
      /**
       * triggered when the remove icon is clicked and returns the data behind the chip
       *
       * @event remove-entry
       * @type {Object}
       *
       */
      this.$emit('remove-entry', this.entryInt);
    }
  }
};

var img = "data:image/svg+xml,%3c!-- Optimised/Generated by IcoMoon.io --%3e%3csvg version='1.1' xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3e%3ctitle%3eremove%3c/title%3e%3cpath d='M2.962 0.131l28.904 28.904-2.832 2.832-28.904-28.904 2.832-2.832z'%3e%3c/path%3e%3cpath d='M31.865 2.962l-28.904 28.904-2.832-2.832 28.904-28.904 2.832 2.832z'%3e%3c/path%3e%3c/svg%3e";
  var __$_require_static_icons_remove_svg__ = img;

/* script */
var __vue_script__ = script;

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

  var _c = _vm._self._c || _h;

  return _c('div', {
    class: ['base-chip', {
      'base-chip__removable': _vm.isRemovable
    }, {
      'base-chip__linked': _vm.isLinked
    }, {
      'base-chip__active': _vm.chipActive
    }]
  }, [_c('div', {
    ref: "chipText",
    staticClass: "base-chip__text",
    style: _vm.textStyling,
    attrs: {
      "contenteditable": _vm.editable ? 'true' : false,
      "aria-labelledby": _vm.assistiveText ? _vm.internalId + "_aria-label" : false,
      "enterkeyhint": "search"
    },
    on: {
      "blur": _vm.updateText,
      "keydown": function keydown($event) {
        if (!$event.type.indexOf('key') && _vm._k($event.keyCode, "enter", 13, $event.key, "Enter")) {
          return null;
        }

        $event.preventDefault();
        return _vm.updateText.apply(null, arguments);
      },
      "click": function click($event) {
        $event.stopPropagation();
        return _vm.clickAction.apply(null, arguments);
      },
      "mousedown": _vm.onMouseDown,
      "mousemove": _vm.moveBox,
      "mouseleave": _vm.hideBox
    }
  }, [_vm._v("\n    " + _vm._s(_vm.entryInt) + "\n  ")]), _vm._v(" "), _vm.assistiveText ? _c('span', {
    staticClass: "hide",
    attrs: {
      "id": _vm.internalId + "_aria-label"
    }
  }, [_vm._v("\n    " + _vm._s(_vm.assistiveText) + "\n  ")]) : _vm._e(), _vm._v(" "), _vm.isRemovable ? _c('div', {
    staticClass: "base-chip__icon",
    on: {
      "click": function click($event) {
        $event.stopPropagation();
        return _vm.removeClicked.apply(null, arguments);
      }
    }
  }, [_c('img', {
    staticClass: "base-chip__icon-img",
    attrs: {
      "src": __$_require_static_icons_remove_svg__,
      "alt": "remove"
    }
  })]) : _vm._e(), _vm._v(" "), _c('base-hover-box', _vm._b({
    ref: "hoverBox",
    class: {
      'base-chip__hover-box__hidden': !_vm.hoverBoxEnabled || !_vm.showInfoBox
    }
  }, 'base-hover-box', _vm.hoverBoxContent, false))], 1);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = "data-v-19eead1e";
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

/* style inject shadow dom */

var __vue_component__ = /*#__PURE__*/normalizeComponent({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined);

var BaseChip = __vue_component__;

export { BaseChip as default };
