"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 _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; }
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
