"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _antd = require("antd");
var _classnames = _interopRequireDefault(require("classnames"));
var _icons = require("@ant-design/icons");
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 _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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
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 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); }
var Context = /*#__PURE__*/_react["default"].createContext({
  wrapDom: null
});
var Provider = Context.Provider;

// 最外层包裹容器
var Wrap = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
  var children = props.children;
  var dom = (0, _react.useRef)(null);
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      dom: dom.current
    };
  });
  return /*#__PURE__*/_react["default"].createElement(Provider, {
    value: {
      wrapDom: dom.current
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    ref: dom,
    className: (0, _classnames["default"])('ol-map-popup')
  }, children));
});

// 关闭按钮
var Close = function Close(props) {
  var onClick = props.onClick;
  return /*#__PURE__*/_react["default"].createElement(_icons.CloseOutlined, {
    className: (0, _classnames["default"])('ol-map-popup-close'),
    width: 16,
    height: 16,
    onClick: onClick
  });
};

// 标题
var Title = function Title(props) {
  var title = props.title;
  return /*#__PURE__*/_react["default"].createElement("div", {
    title: title,
    className: (0, _classnames["default"])('ol-map-popup-title', {
      'ol-map-popup-noTitle': !title
    })
  }, title);
};

// 内容
var Content = function Content(props) {
  var list = props.list,
    gutter = props.gutter,
    _props$loading = props.loading,
    loading = _props$loading === void 0 ? false : _props$loading,
    children = props.children,
    _props$column = props.column,
    column = _props$column === void 0 ? 1 : _props$column,
    _props$style = props.style,
    style = _props$style === void 0 ? {} : _props$style;
  var _useContext = (0, _react.useContext)(Context),
    wrapDom = _useContext.wrapDom;
  var _style = _objectSpread({
    width: '100%'
  }, style);
  if (column >= 2) {
    _style.width = column * 200;
    wrapDom.style.setProperty('--popup-width', "".concat(_style.width, "px"));
  }
  return /*#__PURE__*/_react["default"].createElement(_antd.Spin, {
    spinning: loading
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])('ol-map-popup-content'),
    style: _style
  }, /*#__PURE__*/_react["default"].createElement(_antd.Row, {
    gutter: gutter || [5, 5]
  }, (list === null || list === void 0 ? void 0 : list.length) > 0 && list.map(function (item, index) {
    return /*#__PURE__*/_react["default"].createElement(_antd.Col, {
      key: index,
      span: item.span || 24 / column
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])('ol-map-popup-content-item'),
      onClick: item.onClick
    }, item.label && /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])('ol-map-popup-content-item-label')
    }, item.label, "\uFF1A"), (item.value || String(item.value) === '0' || item.unit) && /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])('ol-map-popup-content-item-value'),
      style: _objectSpread({
        color: item.onAlarm ? 'rgb(245,13,13)' : '#222'
      }, item.style || {}),
      title: item.value
    }, item.value, item.unit), item.content));
  })), children));
};

// 底部按钮
var Footer = function Footer(props) {
  var list = props.list;
  if ((list === null || list === void 0 ? void 0 : list.length) === 0) {
    return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null);
  }
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: (0, _classnames["default"])("ol-map-popup-footer")
  }, list.map(function (item, index) {
    return /*#__PURE__*/_react["default"].createElement("div", {
      key: index,
      className: (0, _classnames["default"])("ol-map-popup-footer-item"),
      onClick: item.onClick
    }, item.icon && /*#__PURE__*/_react["default"].createElement("span", {
      className: (0, _classnames["default"])("ol-map-popup-footer-item-icon")
    }, item.icon), item.label);
  }));
};

// 模版
var Template = function Template(props) {
  var loading = props.loading,
    contentList = props.contentList,
    contentStyle = props.contentStyle,
    content = props.content,
    otherContent = props.otherContent,
    gutter = props.gutter,
    column = props.column,
    footerList = props.footerList,
    footer = props.footer,
    detail = props.detail,
    children = props.children;

  // 底部按钮
  var footerButtons = [].concat(_toConsumableArray(detail !== null && detail !== void 0 && detail.show ? [_objectSpread({
    label: "详情",
    icon: /*#__PURE__*/_react["default"].createElement(_icons.ExclamationCircleOutlined, null)
  }, detail)] : []), _toConsumableArray(footerList || []));
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, content || /*#__PURE__*/_react["default"].createElement(Content, {
    loading: loading,
    list: contentList,
    column: column,
    gutter: gutter,
    style: contentStyle
  }, otherContent), children, footer || /*#__PURE__*/_react["default"].createElement(Footer, {
    list: footerButtons
  }));
};
var Popup = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
  var title = props.title,
    onClose = props.onClose,
    children = props.children;
  var wrapRef = (0, _react.useRef)({});
  (0, _react.useImperativeHandle)(ref, function () {
    return {
      wrapDom: wrapRef.current.dom
    };
  });
  return /*#__PURE__*/_react["default"].createElement(Wrap, {
    ref: wrapRef
  }, /*#__PURE__*/_react["default"].createElement(Title, {
    title: title
  }), onClose && /*#__PURE__*/_react["default"].createElement(Close, {
    onClick: onClose
  }), children);
});
Popup.Title = Title;
Popup.Content = Content;
Popup.Footer = Footer;
Popup.Template = Template;
var _default = exports["default"] = Popup;
//# sourceMappingURL=index.js.map
