"use strict";

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); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.Modal = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactDom = _interopRequireDefault(require("react-dom"));
var _CloseOutlined = _interopRequireDefault(require("@ant-design/icons/CloseOutlined"));
var _LeftOutlined = _interopRequireDefault(require("@ant-design/icons/LeftOutlined"));
var _RightOutlined = _interopRequireDefault(require("@ant-design/icons/RightOutlined"));
var _button = _interopRequireDefault(require("antd/lib/button"));
var _propTypes = _interopRequireDefault(require("prop-types"));
require("./index.less");
var _olMap = require("@vtx/ol-map");
var _excluded = ["children", "map", "dom"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(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 (e.includes(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 _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); }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; } /*
 * @description:自定义弹框组件-挂载到body或其他节点上-默认挂载在地图上
 */
var Modal = exports.Modal = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
  var visible = props.visible,
    title = props.title,
    _props$isCanFold = props.isCanFold,
    isCanFold = _props$isCanFold === void 0 ? false : _props$isCanFold,
    _props$isShowHidden = props.isShowHidden,
    isShowHidden = _props$isShowHidden === void 0 ? false : _props$isShowHidden,
    isFold = props.isFold,
    setIsFold = props.setIsFold,
    onCancel = props.onCancel,
    width = props.width,
    _props$style = props.style,
    style = _props$style === void 0 ? {} : _props$style,
    className = props.className,
    contentClassName = props.contentClassName;
  var widthNum = width || 410;
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    hidden = _useState2[0],
    setHidden = _useState2[1];
  (0, _react.useEffect)(function () {
    props.onChange && props.onChange(hidden);
  }, [hidden]);
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      setHidden: setHidden
    };
  }, []);
  var classnames = function classnames(name) {
    if (name) {
      return "ol-map-CustomModal-".concat(name);
    }
    return "ol-map-CustomModal";
  };
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, visible ? /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classnames('wrap'), " ").concat(classnames(hidden ? 'hidden' : 'show')),
    style: _objectSpread({
      width: widthNum
    }, style)
  }, /*#__PURE__*/_react["default"].createElement(_olMap.Legend, {
    style: {
      left: 0,
      bottom: 0,
      transform: 'translateX(calc(-100% - 10px)'
    }
  }), isShowHidden && /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('hidden-btn'),
    onClick: function onClick() {
      return setHidden(!hidden);
    }
  }, hidden ? /*#__PURE__*/_react["default"].createElement(_LeftOutlined["default"], {
    style: {
      fontSize: 12
    }
  }) : /*#__PURE__*/_react["default"].createElement(_RightOutlined["default"], {
    style: {
      fontSize: 12
    }
  })), /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classnames('analysisModal'), " ").concat(className, " "),
    style: _objectSpread({
      width: widthNum
    }, style)
  }, isCanFold ? /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('foldWrap'),
    onClick: function onClick() {
      setIsFold(!isFold);
    }
  }, /*#__PURE__*/_react["default"].createElement(_button["default"], {
    style: {
      width: '25px',
      height: '25px',
      borderRadius: '50%'
    },
    type: "primary",
    icon: isFold ? /*#__PURE__*/_react["default"].createElement(_LeftOutlined["default"], {
      style: {
        fontSize: 12
      }
    }) : /*#__PURE__*/_react["default"].createElement(_RightOutlined["default"], {
      style: {
        fontSize: 12
      }
    })
  })) : null, title ? /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('titleWrap'),
    style: {
      paddingLeft: '25px'
      // paddingLeft: '46px',
    }
  }, /*#__PURE__*/_react["default"].createElement("div", null, title), /*#__PURE__*/_react["default"].createElement(_CloseOutlined["default"], {
    width: 16,
    height: 16,
    onClick: onCancel
  })) : null, /*#__PURE__*/_react["default"].createElement("div", {
    className: "".concat(classnames('content_'), " ").concat(contentClassName)
  }, props.children))) : null);
});
Modal.propTypes = {
  visible: _propTypes["default"].bool,
  title: _propTypes["default"].any,
  isCanFold: _propTypes["default"].bool,
  isFold: _propTypes["default"].bool,
  setIsFold: _propTypes["default"].func,
  onCancel: _propTypes["default"].func,
  width: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
  style: _propTypes["default"].object,
  className: _propTypes["default"].string,
  contentClassName: _propTypes["default"].string
};
var CustomPortal = function CustomPortal(props, ref) {
  var children = props.children,
    map = props.map,
    dom = props.dom,
    otherProps = _objectWithoutProperties(props, _excluded);
  var _useState3 = (0, _react.useState)(null),
    _useState4 = _slicedToArray(_useState3, 2),
    container = _useState4[0],
    setContainer = _useState4[1];
  var modalRef = (0, _react.useRef)();
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      setHidden: function setHidden(hidden) {
        if (modalRef.current) {
          modalRef.current.setHidden(hidden);
        }
      }
    };
  }, []);
  (0, _react.useEffect)(function () {
    var mapEl = map === null || map === void 0 ? void 0 : map.values_.target;
    var _dom = dom || mapEl;
    if (_dom) {
      // 创建一个新的 div 元素
      var newContainer = document.createElement('div');
      // 将新的 div 元素添加到节点上
      _dom.appendChild(newContainer);
      // 设置状态
      setContainer(newContainer);
      // 组件卸载时，从节点上移除 div 元素
      return function () {
        _dom.removeChild(newContainer);
      };
    }
  }, []);

  // 使用 createPortal() 将子元素插入到新的 div 元素中
  return container ? /*#__PURE__*/_reactDom["default"].createPortal(/*#__PURE__*/_react["default"].createElement(Modal, _extends({}, otherProps, {
    ref: modalRef
  }), children), container) : null;
};
var _default = exports["default"] = /*#__PURE__*/(0, _react.forwardRef)(CustomPortal);
//# sourceMappingURL=index.js.map
