/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var Vue = require('vue');
var raf = require('raf');
var isFunction = require('lodash/isFunction');
var utils_dom = require('../utils/dom.js');
var popup_utils = require('./utils.js');
var popup_trigger = require('./trigger.js');
require('lodash/isString');
require('../utils/easing.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
var raf__default = /*#__PURE__*/_interopDefaultLegacy(raf);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);

var Container = Vue__default["default"].extend({
  name: "Trigger",
  props: {
    parent: Object,
    visible: Boolean,
    attach: [Function]
  },
  data: function data() {
    return {
      content: null
    };
  },
  mounted: function mounted() {
    var _this = this;
    if (this.visible) raf__default["default"](this.mountContent);
    this.$watch("visible", function (visible) {
      if (visible) _this.mountContent();
    });
  },
  destroyed: function destroyed() {
    var _process$env;
    if (typeof process !== "undefined" && ((_process$env = process.env) === null || _process$env === void 0 ? void 0 : _process$env.NODE_ENV) === "test") return;
    this.unmountContent();
  },
  methods: {
    mountContent: function mountContent() {
      var _this$$refs, _this$$refs$triggerRe;
      if (this.content) return;
      var parent = this;
      var elm = document.createElement("div");
      elm.style.cssText = "position: absolute; top: 0px; left: 0px; width: 100%";
      elm.appendChild(document.createElement("div"));
      this.content = new this.$root.constructor({
        parent: parent,
        render: function render() {
          return parent.$slots.content;
        },
        mounted: function mounted() {
          parent.$emit("contentMounted");
          var content = this.$el.children[0];
          if (content) {
            this.$on("hook:destroyed", popup_utils.observeResize(content, function () {
              parent.$emit("resize");
            }));
          }
        },
        destroyed: function destroyed() {
          parent.content = null;
          utils_dom.removeDom(elm);
        }
      });
      var _this$attach = this.attach(),
        attach = _this$attach.attach,
        current = _this$attach.current;
      var currentAttach = attach === "CURRENT_NODE" ? current : attach;
      utils_dom.getAttach(currentAttach, (_this$$refs = this.$refs) === null || _this$$refs === void 0 ? void 0 : (_this$$refs$triggerRe = _this$$refs.triggerRef) === null || _this$$refs$triggerRe === void 0 ? void 0 : _this$$refs$triggerRe.$el).appendChild(elm);
      this.content.$mount(elm.children[0]);
    },
    unmountContent: function unmountContent() {
      var _this$content;
      if (isFunction__default["default"]((_this$content = this.content) === null || _this$content === void 0 ? void 0 : _this$content.$destroy)) this.content.$destroy();
    },
    updateContent: function updateContent() {
      var _this$content2;
      (_this$content2 = this.content) === null || _this$content2 === void 0 ? void 0 : _this$content2.$forceUpdate();
    }
  },
  render: function render() {
    var _this2 = this;
    var h = arguments[0];
    return h(popup_trigger["default"], {
      "ref": "triggerRef",
      "on": {
        "resize": function resize() {
          return _this2.$emit("resize");
        }
      }
    }, [this.$slots["default"]]);
  }
});

exports["default"] = Container;
//# sourceMappingURL=container.js.map
