"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"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _cesium = require("cesium");
var _useProps2 = _interopRequireDefault(require("../use-props"));
var _classnames = _interopRequireDefault(require("classnames"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var SliderScene = function SliderScene(props) {
  var left = props.left,
    right = props.right,
    top = props.top,
    bottom = props.bottom;
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map;
  var mode = props.mode;
  var domRef = (0, _react.useRef)(null);
  (0, _react.useEffect)(function () {
    var slider = domRef.current;
    map.scene.splitPosition = slider.offsetLeft / slider.parentElement.offsetWidth;
    map.scene.imagerySplitPosition = slider.offsetLeft / slider.parentElement.offsetWidth;
    var handler = new _cesium.ScreenSpaceEventHandler(domRef.current);
    var moveActive = false;
    function move(movement) {
      if (!moveActive) {
        return;
      }
      var relativeOffset = movement.endPosition.x;
      var imagerySplitPosition = (slider.offsetLeft + relativeOffset) / slider.parentElement.offsetWidth;
      if (imagerySplitPosition < 0.01) {
        imagerySplitPosition = 0.01;
      } else if (imagerySplitPosition > 0.99) {
        imagerySplitPosition = 0.99;
      }
      slider.style.left = "".concat(100.0 * imagerySplitPosition, "%");
      map.scene.splitPosition = imagerySplitPosition;
      map.scene.imagerySplitPosition = imagerySplitPosition;
    }
    handler.setInputAction(function () {
      moveActive = true;
    }, _cesium.ScreenSpaceEventType.LEFT_DOWN);
    handler.setInputAction(function () {
      moveActive = true;
    }, _cesium.ScreenSpaceEventType.PINCH_START);
    handler.setInputAction(move, _cesium.ScreenSpaceEventType.MOUSE_MOVE);
    handler.setInputAction(move, _cesium.ScreenSpaceEventType.PINCH_MOVE);
    handler.setInputAction(function () {
      moveActive = false;
    }, _cesium.ScreenSpaceEventType.LEFT_UP);
    handler.setInputAction(function () {
      moveActive = false;
    }, _cesium.ScreenSpaceEventType.PINCH_END);
  }, []);
  (0, _react.useEffect)(function () {
    setLayerByList(left, 'LEFT');
  }, [JSON.stringify(left)]);
  (0, _react.useEffect)(function () {
    setLayerByList(right, 'RIGHT');
  }, [JSON.stringify(right)]);
  var setLayerByList = function setLayerByList(val, splitDirection) {
    var id = val.id;
    id = Array.isArray(id) ? id : [id];
    id.map(function (id) {
      setLayer(id, splitDirection);
    });
  };
  var setLayer = function setLayer(id, splitDirection) {
    var layer = map.getLayerByKey(id);
    if (layer) {
      layer.splitDirection = (_cesium.SplitDirection === null || _cesium.SplitDirection === void 0 ? void 0 : _cesium.SplitDirection[splitDirection]) || (_cesium.ImagerySplitDirection === null || _cesium.ImagerySplitDirection === void 0 ? void 0 : _cesium.ImagerySplitDirection[splitDirection]);
    }
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    ref: domRef,
    className: (0, _classnames["default"])('cs-map-sidebar')
  });
};
var _default = exports["default"] = SliderScene;
//# sourceMappingURL=index.js.map
