'use strict';Object.defineProperty(exports,'__esModule',{value:true});var normalizeComponent=require('./normalize-component-d9981c57.js');require('./es.array.includes-3990bfec.js'),require('./es.number.constructor-daccdeab.js');var BaseBox=require('./BaseBox-1df1f27d.js'),BaseButton=require('./BaseButton-0200f360.js');require('./export-61511812.js'),require('./object-keys-12f2c5e5.js'),require('./object-set-prototype-of-dfa14cf5.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');/**
 * Component to render content in expandable container
 */

var script = {
  name: 'BaseExpandBox',
  components: {
    BaseBox: BaseBox.B,
    BaseButton: BaseButton["default"]
  },
  props: {
    /**
     * expand box from outside
     */
    expand: {
      type: Boolean,
      default: false
    },

    /**
     * define padding of the box<br>
     * valid values: 'large' | 'small'
     */
    padding: {
      type: String,
      default: 'small',
      validator: function validator(val) {
        return ['large', 'small'].includes(val);
      }
    },

    /**
     * button text to show more content
     */
    showMoreText: {
      type: String,
      default: 'Show more'
    },

    /**
     * button text to show less content
     */
    showLessText: {
      type: String,
      default: 'Show less'
    },
    autoHeight: {
      type: Boolean,
      default: false
    },

    /**
     * define the max height of the collapsed box in px
     */
    maxCollapsedHeight: {
      type: Number,
      default: 300
    },

    /**
     * define the height including margin of the show-more button in px
     */
    showButtonHeight: {
      type: Number,
      default: 54
    }
  },
  data: function data() {
    return {
      expandInt: false,
      contentWidth: null,
      initialized: false,
      showButton: false
    };
  },
  computed: {
    maxCollapsedHeightInt: function maxCollapsedHeightInt() {
      return this.showButton ? this.maxCollapsedHeight - this.showButtonHeight : this.maxCollapsedHeight;
    },
    style: function style() {
      return {
        '--max-collapsed-height': "".concat(this.maxCollapsedHeightInt, "px")
      };
    }
  },
  mounted: function mounted() {
    this.init();
  },
  methods: {
    /**
     * init
     */
    init: function init() {
      if (this.expand) {
        // check if button is needed
        this.showButton = this.contentInnerHeight() > this.contentHeight();
        this.expandInt = true;
      }

      this.initialized = true; // observe resize of container and set visibility of button

      this.boxResize().observe(this.$el);
    },

    /**
     * check if box width changes and set visibility of button
     */
    boxResize: function boxResize() {
      var _this = this;

      return new ResizeObserver(function (entries) {
        var currentWidth = entries[0].contentRect.width;

        if (_this.contentWidth !== currentWidth) {
          // compare content to parent container -> set button visibility
          if (!_this.expandInt) {
            _this.showButton = _this.contentInnerHeight() > _this.contentHeight();
          } // close expanded box


          if (_this.expand && _this.expandInt && _this.contentWidth !== null) {
            _this.expandInt = false;
          }
        } // save currentWidth for next comparison


        _this.contentWidth = currentWidth; // emit box-size

        if (!_this.expandInt) {
          /**
           * emitting box-height on resize
           *
           * @type {String}
           */
          _this.$emit('box-height', _this.$el.offsetHeight);
        }
      });
    },

    /**
     * calculate height of content
     */
    contentHeight: function contentHeight() {
      return this.$el.querySelector('.base-expand-box-content').offsetHeight;
    },

    /**
     * calculate height of content inner
     */
    contentInnerHeight: function contentInnerHeight() {
      return this.$el.querySelector('.base-expand-box-content-inner > div').offsetHeight;
    },

    /**
     *
     */
    clicked: function clicked() {
      this.expandInt = !this.expandInt;
      /**
       * event emitted on button click
       *
       * @type {Event}
       */

      this.$emit('update:expand', this.expandInt);
    }
  }
};/* 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('base-box', {
    class: ['base-expand-box', 'base-expand-box-padding-' + _vm.padding, {
      'base-expand-box-auto-height': _vm.autoHeight
    }, {
      'base-expand-box-open': _vm.expandInt
    }],
    style: _vm.style,
    attrs: {
      "box-ratio": "0",
      "box-size": {},
      "box-hover": false
    }
  }, [_c('div', {
    class: ['base-expand-box-content', {
      'base-expand-box-content-fade-out': !_vm.initialized || !_vm.expandInt && _vm.showButton
    }]
  }, [_c('div', {
    staticClass: "base-expand-box-content-inner"
  }, [_c('div', [_vm._t("default")], 2)])]), _vm._v(" "), _vm.showButton ? _c('base-button', {
    class: ['base-expand-box-button', {
      'base-button-icon-rotate-180': _vm.expandInt
    }],
    attrs: {
      "text": _vm.expandInt ? _vm.showLessText : _vm.showMoreText,
      "has-background-color": false,
      "align-text": "left",
      "icon": "drop-down",
      "icon-position": "right"
    },
    on: {
      "clicked": _vm.clicked
    }
  }) : _vm._e(), _vm._v(" "), !!_vm.$slots.footer ? _c('div', {
    staticClass: "base-expand-box-footer"
  }, [_c('div', {
    staticClass: "base-expand-box-footer-inner"
  }, [_vm._t("footer")], 2)]) : _vm._e()], 1);
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = "data-v-1c7084d0";
/* module identifier */

var __vue_module_identifier__ = "data-v-1c7084d0";
/* 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 BaseExpandBox = __vue_component__;var Plugin = {
  install: function install(Vue) {
    normalizeComponent.r(Vue, BaseExpandBox);
  }
};
normalizeComponent.u(Plugin);exports.BaseExpandBox=BaseExpandBox;exports["default"]=Plugin;