'use strict';Object.defineProperty(exports,'__esModule',{value:true});var normalizeComponent=require('./normalize-component-d9981c57.js');require('./es.array.includes-3990bfec.js');var BaseButton=require('./BaseButton-0200f360.js'),BaseLoader=require('./BaseLoader-a331376d.js'),i18n=require('./i18n-68e039d3.js');require('./export-61511812.js'),require('./object-keys-12f2c5e5.js'),require('./es.symbol.description-bf683260.js'),require('./array-species-create-c414c2ec.js'),require('./set-to-string-tag-240bb3b0.js'),require('./array-iteration-f8b4483d.js'),require('./function-bind-context-e4685306.js'),require('./utils-2e136d65.js'),require('./typeof-6b9e62b8.js'),require('./unsupportedIterableToArray-40a00645.js'),require('./es.array.join-88750c41.js'),require('./array-method-is-strict-99341ee3.js'),require('./es.array.map-4cfed4ef.js'),require('./array-method-has-species-support-983ac207.js'),require('./regexp-exec-abstract-216cd44a.js'),require('./string-multibyte-a2dff6e3.js'),require('./regexp-flags-abc49c4a.js'),require('./es.string.split-98e29ede.js'),require('./is-regexp-d6f1551e.js'),require('./create-property-240c71a5.js'),require('./es.object.to-string-f27a75a8.js'),require('./classof-819fc780.js'),require('./es.regexp.to-string-5606f728.js'),require('./es.string.replace-25e9e098.js'),require('./es.string.includes-ec03e639.js'),require('./es.array.sort-7d68b195.js'),require('./web.dom-collections.for-each-c07b0e22.js'),require('./dom-iterables-e2602b7e.js'),require('./es.object.keys-c57f02bd.js'),require('./BaseIcon-1ed3bf6e.js'),require('./es.array.concat-bb8715dc.js'),require('./BaseBoxTooltip-59ec05c0.js');var script = {
  name: 'BaseEditControl',
  components: {
    BaseButton: BaseButton["default"],
    BaseLoader: BaseLoader["default"]
  },
  mixins: [i18n.i],
  props: {
    /**
     * toggle control buttons
     */
    controls: {
      type: Boolean,
      default: false
    },

    /**
     * disable edit button
     */
    disabled: {
      type: Boolean,
      default: false
    },

    /**
     * set edit mode
     */
    edit: {
      type: Boolean,
      default: false
    },

    /**
     * flag to set if loader should be shown (for autocomplete requests
     */
    isLoading: {
      type: Boolean,
      default: false
    },

    /**
     * define title
     */
    title: {
      type: String,
      default: 'Title'
    },

    /**
     * define subtitle
     */
    subtitle: {
      type: String,
      default: ''
    },

    /**
     * render title as e.g.: 'h2' | 'h3'
     */
    renderTitleAs: {
      type: String,
      default: 'h2'
    },

    /**
     * define button text<br>
     * could be string or path to i18n json as well
     */
    editButtonText: {
      type: String,
      default: 'Edit'
    },

    /**
     * define button text<br>
     * could be string or path to i18n json as well
     */
    cancelButtonText: {
      type: String,
      default: 'Cancel'
    },

    /**
     * define button text<br>
     * could be string or path to i18n json as well
     */
    saveButtonText: {
      type: String,
      default: ''
    },

    /**
     * decide on buttons presented in edit mode<br>
     *  <b>save</b>: element has a 'save' and 'cancel' button
     *  <b>done</b>: element solely has a 'done' button. this button is also emitting
     *    a 'saved' event when clicked and uses the saveButtonText
     */
    editMode: {
      type: String,
      default: 'save',
      validator: function validator(val) {
        return ['save', 'done'].includes(val);
      }
    }
  },
  computed: {
    /**
     * set icon depending on editMode
     * @returns {string}
     */
    saveButtonIcon: function saveButtonIcon() {
      if (this.isLoading) {
        return '';
      }

      return this.editMode === 'done' ? 'check-mark' : 'save-file';
    },

    /**
     * set default save button text depending on editMode
     * @returns {string}
     */
    saveButtonTextInt: function saveButtonTextInt() {
      return this.saveButtonText || (this.editMode === 'done' ? 'Done' : 'Save');
    }
  },
  watch: {
    edit: {
      handler: function handler(val) {
        if (val) {
          window.addEventListener('keyup', this.escEventHandler);
        } else {
          window.removeEventListener('keyup', this.escEventHandler);
        }
      }
    }
  },
  methods: {
    activate: function activate(event) {
      /**
       * event emitted by click on edit button
       *
       * @type {PointerEvent}
       */
      this.$emit('activated', event);
    },
    cancel: function cancel(event) {
      /**
       * event emitted by click on cancel button
       *
       * @type {PointerEvent}
       */
      this.$emit('canceled', event);
    },
    save: function save(event) {
      /**
       * event emitted by click on save button
       *
       * @type {PointerEvent}
       */
      this.$emit('saved', event);
    },

    /**
     * intercept escape key event and reset edit mode
     */
    escEventHandler: function escEventHandler(e) {
      if (e.key === 'Escape') {
        this.cancel();
      }
    }
  }
};/* script */
var __vue_script__ = script;
/* template */

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

  var _h = _vm.$createElement;

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

  return _c('div', {
    staticClass: "base-edit-control"
  }, [_vm.title ? _c(_vm.renderTitleAs, {
    tag: "component",
    staticClass: "base-edit-control__title  base-text-fade-out-background"
  }, [_vm._t("default", function () {
    return [_vm._v("\n      " + _vm._s(_vm.title) + "\n      "), _vm.subtitle ? _c('span', {
      staticClass: "base-edit-control__title__additional"
    }, [_vm._v("\n        " + _vm._s(_vm.subtitle) + "\n      ")]) : _vm._e()];
  })], 2) : _vm._e(), _vm._ssrNode(" "), _vm.controls ? _vm._ssrNode("<div class=\"base-edit-control__buttons\" data-v-79a9b246>", "</div>", [!_vm.edit ? _c('base-button', {
    staticClass: "base-edit-control__button",
    attrs: {
      "disabled": _vm.disabled,
      "has-background-color": false,
      "icon": !_vm.isLoading ? 'edit' : '',
      "text": _vm.getI18nTerm(_vm.editButtonText)
    },
    on: {
      "clicked": _vm.activate
    }
  }, [_vm.isLoading ? _c('template', {
    slot: "left-of-text"
  }, [_c('span', {
    staticClass: "base-edit-control__loader"
  }, [_c('BaseLoader')], 1)]) : _vm._e()], 2) : _vm._e(), _vm._ssrNode(" "), _vm.edit ? _c('base-button', {
    staticClass: "base-edit-control__button",
    attrs: {
      "disabled": _vm.disabled,
      "has-background-color": false,
      "icon": _vm.saveButtonIcon,
      "text": _vm.getI18nTerm(_vm.saveButtonTextInt)
    },
    on: {
      "clicked": _vm.save
    }
  }, [_vm.isLoading ? _c('template', {
    slot: "left-of-text"
  }, [_c('span', {
    staticClass: "base-edit-control__loader"
  }, [_c('BaseLoader')], 1)]) : _vm._e()], 2) : _vm._e(), _vm._ssrNode(" "), _vm.editMode === 'save' && _vm.edit ? _c('base-button', {
    staticClass: "base-edit-control__button",
    attrs: {
      "has-background-color": false,
      "icon": "remove",
      "text": _vm.getI18nTerm(_vm.cancelButtonText)
    },
    on: {
      "clicked": _vm.cancel
    }
  }) : _vm._e()], 2) : _vm._e()], 2);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = "data-v-79a9b246";
/* module identifier */

var __vue_module_identifier__ = "data-v-79a9b246";
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

/* style inject shadow dom */

var __vue_component__ = /*#__PURE__*/normalizeComponent.n({
  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 BaseEditControl = __vue_component__;var Plugin = {
  install: function install(Vue) {
    normalizeComponent.r(Vue, BaseEditControl);
  }
};
normalizeComponent.u(Plugin);exports.BaseEditControl=BaseEditControl;exports["default"]=Plugin;