import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import { createVNode as _createVNode } from "vue";
import { defineComponent, ref, Transition } from 'vue';
import { flattenChildren } from '../../_util/props-util';
import classNames from '../../_util/classNames';
import { mobileProps } from './interface';
export default defineComponent({
  name: 'MobilePopupInner',
  inheritAttrs: false,
  props: mobileProps,
  emits: ['mouseenter', 'mouseleave', 'mousedown', 'touchstart', 'align'],
  setup: function setup(props, _ref) {
    var expose = _ref.expose,
        slots = _ref.slots;
    var elementRef = ref();
    expose({
      forceAlign: function forceAlign() {},
      getElement: function getElement() {
        return elementRef.value;
      }
    });
    return function () {
      var _slots$default;

      var _ref2 = props,
          zIndex = _ref2.zIndex,
          visible = _ref2.visible,
          prefixCls = _ref2.prefixCls,
          _ref2$mobile = _ref2.mobile;
      _ref2$mobile = _ref2$mobile === void 0 ? {} : _ref2$mobile;
      var popupClassName = _ref2$mobile.popupClassName,
          popupStyle = _ref2$mobile.popupStyle,
          _ref2$mobile$popupMot = _ref2$mobile.popupMotion,
          popupMotion = _ref2$mobile$popupMot === void 0 ? {} : _ref2$mobile$popupMot,
          popupRender = _ref2$mobile.popupRender; // ======================== Render ========================

      var mergedStyle = _objectSpread({
        zIndex: zIndex
      }, popupStyle);

      var childNode = flattenChildren((_slots$default = slots.default) === null || _slots$default === void 0 ? void 0 : _slots$default.call(slots)); // Wrapper when multiple children

      if (childNode.length > 1) {
        var _childNode = function () {
          return childNode;
        }();

        childNode = _createVNode("div", {
          "class": "".concat(prefixCls, "-content")
        }, [childNode]);
      } // Mobile support additional render


      if (popupRender) {
        childNode = popupRender(childNode);
      }

      var mergedClassName = classNames(prefixCls, popupClassName);
      return _createVNode(Transition, _objectSpread({
        "ref": elementRef
      }, popupMotion), {
        default: function _default() {
          return [visible ? _createVNode("div", {
            "class": mergedClassName,
            "style": mergedStyle
          }, [childNode]) : null];
        }
      });
    };
  }
});