"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _debounce = _interopRequireDefault(require("lodash/debounce"));
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
var _isNumber = _interopRequireDefault(require("lodash/isNumber"));
var _Typography = _interopRequireDefault(require("@material-ui/core/Typography"));
var _i18n = require("../../i18n");
var _propTypes = _interopRequireDefault(require("prop-types"));
require("./Style.scss");
var _excluded = ["contentOverflow"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
var whichTransitionEvent = function whichTransitionEvent() {
  var t;
  var el = document.createElement('fakeelement');
  var transitions = {
    transition: 'transitionend',
    OTransition: 'oTransitionEnd',
    MozTransition: 'transitionend',
    WebkitTransition: 'webkitTransitionEnd'
  };
  for (t in transitions) {
    if (el.style[t] !== undefined) {
      return transitions[t];
    }
  }
};
var transitionEvent = whichTransitionEvent();
var Dialog = exports["default"] = /*#__PURE__*/function (_React$Component) {
  _inherits(Dialog, _React$Component);
  var _super = _createSuper(Dialog);
  function Dialog(_props) {
    var _this;
    _classCallCheck(this, Dialog);
    _this = _super.call(this, _props);
    _defineProperty(_assertThisInitialized(_this), "getParent", function () {
      return _this.props.parent || _this.dialogContainer.current && _this.dialogContainer.current.parentElement || document.body.firstElementChild;
    });
    _defineProperty(_assertThisInitialized(_this), "onContentImageLoaded", function (event) {
      // recalculating position when images are loaded
      if (event.target.tagName === 'IMG') {
        _this.imageLoaded = true;
        _this.shouldUpdate = true;
        _this.forceUpdate();
      }
    });
    _defineProperty(_assertThisInitialized(_this), "onContentImageError", function (event) {
      // recalculating position when images are loaded
      if (event.target.tagName === 'IMG') {
        _this.imageLoaded = false;
        _this.shouldUpdate = true;
        _this.forceUpdate();
      }
    });
    _defineProperty(_assertThisInitialized(_this), "calculatePosition", function (props) {
      var _ref = props || _this.props,
        width = _ref.width,
        height = _ref.height,
        relativePosition = _ref.relativePosition,
        show = _ref.show,
        fixToLeft = _ref.fixToLeft,
        relativeOffset = _ref.relativeOffset;
      var relativeTo = _this.lastRelativeElement;
      var parent = _this.getParent();
      if (relativeTo === 'parent') {
        relativeTo = parent;
      }
      var _assertThisInitialize = _assertThisInitialized(_this),
        dialogContent = _assertThisInitialize.dialogContent,
        dialogTitleBar = _assertThisInitialize.dialogTitleBar,
        dialog = _assertThisInitialize.dialog;
      var dialogStyle = typeof window.getComputedStyle === 'undefined' ? dialog.current.currentStyle : window.getComputedStyle(dialog.current);

      // read the inner content height
      var contentHeight;
      var maxContentHeight;
      if (!height) {
        if (dialogContent.current && dialogTitleBar.current) {
          contentHeight = dialogContent.current.scrollHeight;
          var contentHeightAdds = _this.calculateHeightAdds(dialogContent.current);
          height = contentHeight + contentHeightAdds + dialogTitleBar.current.offsetHeight;

          // add horizontal padding and border of the dialog element
          var paddingAndBorder = (parseInt(dialogStyle.paddingTop) || 0) + (parseInt(dialogStyle.paddingBottom) || 0) + (parseInt(dialogStyle.borderTop) || 0) + (parseInt(dialogStyle.borderBottom) || 0);
          height += paddingAndBorder;
          maxContentHeight = (/%$/.test(dialogStyle.maxHeight) ? parent.clientHeight * parseInt(dialogStyle.maxHeight) / 100 : parseInt(dialogStyle.maxHeight)) - dialogTitleBar.current.offsetHeight;
          if (!(0, _isNumber["default"])(maxContentHeight)) {
            // fallback to parents height
            maxContentHeight = parent.clientHeight;
          }
        } else {
          height = dialog.current && Math.max(dialog.current.scrollHeight, dialog.current.clientHeight);
        }
      }
      if (width === 'adjust' && relativeTo) {
        width = relativeTo.offsetWidth;
      }
      if (!width) {
        width = dialog.current && Math.max(dialog.current.scrollWidth, dialog.current.offsetWidth);
      }
      var element = relativeTo,
        top = 0,
        left = 0,
        bottom,
        contentOverflow = _this.position.contentOverflow || false;
      if (element) {
        do {
          top += element.offsetTop || 0;
          left += element.offsetLeft || 0;

          // fix scroll offset
          var scrollElement = element;
          do {
            top -= scrollElement.scrollTop || 0;
            left -= scrollElement.scrollLeft || 0;
            scrollElement = scrollElement.parentElement;
          } while (scrollElement && scrollElement !== element.offsetParent);
          element = element.offsetParent;
        } while (element && element !== parent);
      }

      // set max width
      if (width > parent.clientWidth) {
        width = parent.clientWidth;
      }
      // set max height
      if (height > parent.clientHeight) {
        height = parent.clientHeight;
      }
      // set content overflow
      if (dialogContent.current) {
        contentOverflow = contentHeight > maxContentHeight;
      }
      if (!!relativeTo && relativePosition[0]) {
        var x = relativePosition[0]; // x = [0:<dialogPositionX>,1:<basePositionX>]
        // cx: horizontal base value, relative position to the element
        var cx = 0;
        switch (x[1]) {
          case 'left':
            cx = left;
            break;
          case 'right':
            cx = left + relativeTo.offsetWidth;
            break;
          case 'center':
            cx = left + relativeTo.offsetWidth / 2;
            break;
        }
        // dialog positioning to cx
        switch (x[0]) {
          case 'left':
            left = cx;
            break;
          case 'right':
            left = cx - width;
            break;
          case 'center':
            left = cx - Math.round(width / 2);
            break;
        }
        var y = relativePosition[1]; // y = [0:<dialogPositionY>,1:<basePositionY>]
        // cy: vertical base value, relative position to the element
        var cy = 0;
        switch (y[1]) {
          case 'top':
            cy = top;
            break;
          case 'bottom':
            cy = top + relativeTo.offsetHeight;
            break;
          case 'center':
            cy = top + relativeTo.offsetHeight / 2;
            break;
        }
        // dialog positioning to cy
        switch (y[0]) {
          case 'top':
            top = cy;
            break;
          case 'bottom':
            top = cy - height;
            bottom = parent.clientHeight - cy;
            if (bottom + height > parent.clientHeight) {
              var margins = parseInt(dialogStyle.marginBottom) + parseInt(dialogStyle.marginTop);
              height = parent.clientHeight - bottom - margins;
            }
            break;
          case 'center':
            top = cy - Math.round(height / 2);
            break;
        }
        if (relativeOffset) {
          top += +relativeOffset.top;
          left += +relativeOffset.left;
        }
      }
      left += _this.offset.left;
      top += _this.offset.top;

      // correct left
      if (left + width > parent.clientWidth) {
        left = parent.clientWidth - width;
      }
      if (left < 0) {
        left = 0;
      }
      // correct top
      if (top + height > parent.clientHeight) {
        top = parent.clientHeight - height;
      }
      if (top < 0) {
        top = 0;
      }
      // set height and overflow if needed
      if (bottom) {
        // set max height
        if (bottom + height > parent.clientHeight) {
          height = parent.clientHeight - bottom;
          contentOverflow = true;
        }
      }
      var position = relativeTo ? {
        top: bottom ? 'auto' : top,
        left: fixToLeft ? undefined : left,
        bottom: bottom || 'auto'
      } : {};
      if (!show) {
        return _objectSpread(_objectSpread({}, position), {}, {
          width: width,
          height: height,
          opacity: 0
        });
      }
      return _objectSpread(_objectSpread({}, position), {}, {
        width: width,
        height: height,
        opacity: !!width && !!height ? 1 : 0,
        contentOverflow: 'contentOverflow' in _this.props ? _this.props.contentOverflow : contentOverflow,
        contentHeight: contentHeight
      });
    });
    _defineProperty(_assertThisInitialized(_this), "onCloseClick", function (e) {
      e.stopPropagation();
      _this.props.onClose && _this.props.onClose();
    });
    _defineProperty(_assertThisInitialized(_this), "stopEvent", function (e) {
      return e.stopPropagation();
    });
    /*detectOrientation = () => {
        let orientation = 'landscape';
        if (window.matchMedia("(orientation: portrait)").matches) {
            orientation = 'portrait';
        }
        if (this.orientation !== orientation) {
            this.orientation = orientation;
        }
    };*/
    _defineProperty(_assertThisInitialized(_this), "moveStart", function (e) {
      if (e.target === _this.dialogClose.current) {
        return;
      }
      e.preventDefault();
      var pp = _this.getPointerPosition(e);
      _this.startPosition = {
        x: pp.x - _this.offset.left,
        y: pp.y - _this.offset.top
      };
      _this.dialog.current.style.transition = 'none';
      if ('ontouchstart' in window) {
        window.addEventListener('touchmove', _this.moveHandler);
      }
      window.addEventListener('mousemove', _this.moveHandler);
    });
    _defineProperty(_assertThisInitialized(_this), "moveHandler", function (e) {
      var pp = _this.getPointerPosition(e);
      var lastLeft = _this.offset.left;
      var lastTop = _this.offset.top;
      _this.offset.left = pp.x - _this.startPosition.x;
      _this.offset.top = pp.y - _this.startPosition.y;
      var position = _this.calculatePosition();
      if (position.top === _this.position.top) {
        _this.offset.top = lastTop;
      }
      if (position.left === _this.position.left) {
        _this.offset.left = lastLeft;
      }
      _this.dialog.current.style.left = position.left + 'px';
      _this.dialog.current.style.top = position.top + 'px';
      _this.position = position;
    });
    _defineProperty(_assertThisInitialized(_this), "moveEnd", function (e) {
      if (e.target === _this.dialogClose.current) {
        return;
      }
      e.preventDefault();
      if ('ontouchstart' in window) {
        window.removeEventListener('touchmove', _this.moveHandler);
      }
      window.removeEventListener('mousemove', _this.moveHandler);
      _this.dialog.current.style.transition = '';
    });
    _this.position = {};
    _this.zIndex = Dialog.zIndex += 2;
    _this.imageLoaded = false;
    _this.lastRelativeElement = null;
    _this.offset = {
      top: 0,
      left: 0
    };
    _this.dialogContainer = /*#__PURE__*/_react["default"].createRef();
    _this.dialogClose = /*#__PURE__*/_react["default"].createRef();
    _this.dialogTitleBar = /*#__PURE__*/_react["default"].createRef();
    _this.dialog = /*#__PURE__*/_react["default"].createRef();
    _this.dialogOverlay = /*#__PURE__*/_react["default"].createRef();
    _this.dialogContent = /*#__PURE__*/_react["default"].createRef();
    return _this;
  }
  _createClass(Dialog, [{
    key: "componentDidUpdate",
    value: function componentDidUpdate() {
      if (this.shouldUpdate) {
        this.shouldUpdate = false;
        var position = this.calculatePosition();
        // check the position after rendering
        if (!(0, _isEqual["default"])(position, this.position)) {
          // rerender if not correct
          this.position = position;
          this.forceUpdate();
        } else {
          // if no change no update needed
          this.shouldUpdate = false;
        }
      }
    }
  }, {
    key: "componentWillReceiveProps",
    value: function componentWillReceiveProps(props) {
      var shouldRecalculate = this.props.show ^ props.show; // was or will be shown

      if (!(0, _isEqual["default"])(props, this.props) && props.show) {
        if (!this.props.show) {
          this.zIndex = Dialog.zIndex += 2;
        }
        var relativeElement = (0, _isFunction["default"])(props.relativeTo) ? props.relativeTo() : props.relativeTo;
        if (relativeElement && relativeElement !== this.lastRelativeElement) {
          this.lastRelativeElement = relativeElement;
          shouldRecalculate = true;
        }
        if (props.refValue !== this.props.refValue || props.children !== this.props.children) {
          shouldRecalculate = true;
        }
      }
      if (shouldRecalculate) {
        this.position = this.calculatePosition(props);
      }
    }
  }, {
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this2 = this;
      var _this$props = this.props,
        relativeTo = _this$props.relativeTo,
        show = _this$props.show;
      var relativeElement = (0, _isFunction["default"])(relativeTo) ? relativeTo() : relativeTo;
      if (relativeElement && show) {
        this.lastRelativeElement = relativeElement;
      }
      this.position = this.calculatePosition();
      this.forceUpdate();
      this.dialog.current.addEventListener(transitionEvent, function (evt) {
        if (evt.target === _this2.dialog.current) {
          // check the position after rendering
          var position = _this2.calculatePosition();
          // check the position after rendering
          if (!(0, _isEqual["default"])(position, _this2.position)) {
            // rerender if not correct
            _this2.position = position;
            _this2.forceUpdate();
          }
        }
      });
      if ('MutationObserver' in window) {
        var updateIfPositionChanged = function updateIfPositionChanged() {
          var position = _this2.calculatePosition();
          // check the position after rendering
          if (!(0, _isEqual["default"])(position, _this2.position)) {
            // rerender if not correct
            _this2.position = position;
            _this2.forceUpdate();
          }
        };
        var updateDebounced = (0, _debounce["default"])(updateIfPositionChanged, 50);

        // create an observer instance
        this.observer = new MutationObserver(function (mutations) {
          mutations.forEach(function (mutation) {
            switch (mutation.type) {
              case 'childList':
                Array.prototype.forEach.call(mutation.target.children, function (child) {
                  if (child.tagName === 'IMG') {
                    child.removeEventListener('load', _this2.onContentImageLoaded, false);
                    child.addEventListener('load', _this2.onContentImageLoaded, false);
                    child.removeEventListener('error', _this2.onContentImageError, false);
                    child.addEventListener('error', _this2.onContentImageError, false);
                  }
                });
                break;
            }
            updateDebounced();
          });
        });
        var config = {
          attributes: true,
          childList: true,
          characterData: true,
          subtree: true
        };
        this.observer.observe(this.dialog.current, config);
      }
      if (this.props.movable) {
        this.initMoving();
      }
    }
  }, {
    key: "componentWillUnmount",
    value: function componentWillUnmount() {
      this.dialog.current && this.dialog.current.removeEventListener('load', this.onContentImageLoaded, true);
      this.observer && this.observer.disconnect();
    }
  }, {
    key: "calculateHeightAdds",
    value: function calculateHeightAdds(element) {
      var compstyle = typeof window.getComputedStyle === 'undefined' ? element.currentStyle : window.getComputedStyle(element);
      var marginTop = parseInt(compstyle.marginTop);
      var marginBottom = parseInt(compstyle.marginBottom);
      var borderTopWidth = parseInt(compstyle.borderTopWidth);
      var borderBottomWidth = parseInt(compstyle.borderBottomWidth);
      return (isNaN(marginTop) ? 0 : marginTop) + (isNaN(marginBottom) ? 0 : marginBottom) + (isNaN(borderTopWidth) ? 0 : borderTopWidth) + (isNaN(borderBottomWidth) ? 0 : borderBottomWidth);
    }
  }, {
    key: "calculateVerticalPaddings",
    value: function calculateVerticalPaddings(element) {
      var compstyle = typeof window.getComputedStyle === 'undefined' ? element.currentStyle : window.getComputedStyle(element);
      var paddingTop = parseInt(compstyle.paddingTop);
      var paddingBottom = parseInt(compstyle.paddingBottom);
      return (isNaN(paddingTop) ? 0 : paddingTop) + (isNaN(paddingBottom) ? 0 : paddingBottom);
    }
  }, {
    key: "calculateHeight",
    value: function calculateHeight(element) {
      return element.offsetHeight + this.calculateHeightAdds(element);
    }
  }, {
    key: "getPointerPosition",
    value: function getPointerPosition(e) {
      var x = 0;
      var y = 0;
      if (e.touches !== undefined) {
        x = e.touches[0].clientX;
        y = e.touches[0].clientY;
      } else {
        x = e.clientX;
        y = e.clientY;
      }
      return {
        x: x,
        y: y
      };
    }
  }, {
    key: "initMoving",
    value: function initMoving() {
      if ('ontouchstart' in window) {
        this.dialogTitleBar.current.addEventListener('touchstart', this.moveStart);
        this.dialogTitleBar.current.addEventListener('touchend', this.moveEnd);
      }
      this.dialogTitleBar.current.addEventListener('mousedown', this.moveStart);
      this.dialogTitleBar.current.addEventListener('mouseup', this.moveEnd);

      //window.addEventListener('resize', this.detectOrientation);
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
        show = _this$props2.show,
        title = _this$props2.title,
        children = _this$props2.children,
        overlay = _this$props2.overlay,
        overlayClassName = _this$props2.overlayClassName,
        className = _this$props2.className,
        animation = _this$props2.animation,
        onClose = _this$props2.onClose;
      var zIndex = this.zIndex,
        onCloseClick = this.onCloseClick,
        dialog = this.dialog,
        dialogContainer = this.dialogContainer,
        dialogClose = this.dialogClose,
        dialogTitleBar = this.dialogTitleBar,
        dialogContent = this.dialogContent,
        dialogOverlay = this.dialogOverlay;
      var _this$position = _objectSpread({}, this.position),
        contentOverflow = _this$position.contentOverflow,
        position = _objectWithoutProperties(_this$position, _excluded);
      var display = show ? 'block' : 'none';
      var imageClass = this.imageLoaded ? 'with-image' : '';
      var containerClassName = ['dialog-container', animation, imageClass, className || ''].join(' ');
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: containerClassName,
        style: {
          display: display
        },
        ref: dialogContainer,
        onClick: onCloseClick
      }, overlay && /*#__PURE__*/_react["default"].createElement("div", {
        ref: dialogOverlay,
        className: 'dialog-overlay ' + (overlayClassName || ''),
        style: {
          zIndex: zIndex
        }
      }), /*#__PURE__*/_react["default"].createElement("div", {
        ref: dialog,
        className: "dialog",
        style: _objectSpread(_objectSpread({}, position), {}, {
          zIndex: zIndex + 1
        }),
        onClick: this.stopEvent
      }, /*#__PURE__*/_react["default"].createElement(_Typography["default"], {
        variant: 'subtitle1'
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: "dialog-title-bar",
        ref: dialogTitleBar
      }, onClose && /*#__PURE__*/_react["default"].createElement("span", {
        ref: dialogClose,
        className: "dialog-close",
        onClick: onCloseClick
      }, "X"), title && /*#__PURE__*/_react["default"].createElement("h3", {
        className: "dialog-title"
      }, (0, _i18n.T)(title)))), /*#__PURE__*/_react["default"].createElement("div", {
        className: 'dialog-content' + (contentOverflow ? ' overflow' : ''),
        ref: dialogContent
      }, /*#__PURE__*/_react["default"].createElement(_Typography["default"], null, children))));
    }
  }]);
  return Dialog;
}(_react["default"].Component);
_defineProperty(Dialog, "defaultProps", {
  relativePosition: [['center', 'center'], ['center', 'center']],
  animation: 'all',
  // ('show', 'grow', 'all') -> css class with transition,
  overlayClassName: '',
  onClose: false,
  fixToLeft: false,
  relativeTo: undefined,
  // the element to which the dialog is relative (if not set it will be fixed)
  refValue: undefined,
  // if this value changes it will trigger the recalculation of the dialog height
  relativeOffset: undefined,
  // { top, left }
  movable: false
});
_defineProperty(Dialog, "zIndex", 1000);