"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"] = _default;
var _react = _interopRequireWildcard(require("react"));
var _antd = require("antd");
var _toolsItem = _interopRequireDefault(require("../tools-item"));
var _classnames = _interopRequireDefault(require("classnames"));
var _useProps2 = _interopRequireDefault(require("../../_util/useProps"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _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(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
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(arr) { if (Array.isArray(arr)) return arr; }
function _default() {
  var _useState = (0, _react.useState)([]),
    _useState2 = _slicedToArray(_useState, 2),
    list = _useState2[0],
    setList = _useState2[1];
  var _useState3 = (0, _react.useState)(null),
    _useState4 = _slicedToArray(_useState3, 2),
    value = _useState4[0],
    setValue = _useState4[1];
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map;
  (0, _react.useEffect)(function () {
    var _map$baseMap = map.baseMap,
      imageryProvider = _map$baseMap.imageryProvider,
      options = _map$baseMap.options,
      style = _map$baseMap.style;
    if (options !== null && options !== void 0 && options.length) {
      setList(options);
    }
    if (imageryProvider && style) {
      setValue(map.baseMap.getValue());
    }
  }, []);

  // 切换
  var onChange = function onChange(item, val) {
    setValue(_objectSpread(_objectSpread({}, val), {}, {
      value: "".concat(item.value, "_").concat(val.value)
    }));
    map.baseMap.setValue(item.value, val.value);
  };
  var content = function content() {
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])('base-map-switch-list-wrap')
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])('base-map-switch-list-title')
    }, "\u5E95\u56FE\u9009\u62E9"), /*#__PURE__*/_react["default"].createElement("div", {
      className: (0, _classnames["default"])('base-map-switch-list')
    }, list.map(function (item) {
      return /*#__PURE__*/_react["default"].createElement(_antd.Row, {
        key: item.label
      }, /*#__PURE__*/_react["default"].createElement("div", {
        className: (0, _classnames["default"])('base-map-switch-list-label')
      }, item.label), /*#__PURE__*/_react["default"].createElement("div", {
        className: (0, _classnames["default"])('base-map-switch-list-item-wrap')
      }, /*#__PURE__*/_react["default"].createElement(_antd.Row, {
        gutter: [12, 12]
      }, item.children.map(function (v) {
        return /*#__PURE__*/_react["default"].createElement(_antd.Col, {
          span: 12,
          key: "".concat(item.label, "-").concat(v.label)
        }, /*#__PURE__*/_react["default"].createElement("div", {
          onClick: function onClick() {
            return onChange(item, v);
          },
          className: (0, _classnames["default"])('base-map-switch-list-item', {
            'base-map-switch-list-item-active': (value === null || value === void 0 ? void 0 : value.value) === "".concat(item.value, "_").concat(v.value)
          })
        }, /*#__PURE__*/_react["default"].createElement("img", {
          className: (0, _classnames["default"])('base-map-switch-list-item-img'),
          src: v.img,
          alt: ""
        }), /*#__PURE__*/_react["default"].createElement("div", {
          className: (0, _classnames["default"])('base-map-switch-list-item-label')
        }, v.label)));
      }))));
    })));
  };
  return /*#__PURE__*/_react["default"].createElement(_toolsItem["default"], {
    content: content
  }, (value === null || value === void 0 ? void 0 : value.img) && /*#__PURE__*/_react["default"].createElement("img", {
    src: value.img,
    className: (0, _classnames["default"])('base-map-switch-active'),
    alt: ""
  }));
}
//# sourceMappingURL=index.js.map
