"use strict";

exports.__esModule = true;
exports.RotateCircularViewSlider = RotateCircularViewSlider;
var _react = _interopRequireDefault(require("react"));
var _useDebounce = require("use-debounce");
var _constants = require("../constants/constants");
var _UncontrolledSliderWithPlusMinusBtns = _interopRequireDefault(require("../helperComponents/UncontrolledSliderWithPlusMinusBtns"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function RotateCircularViewSlider(_ref) {
  var setRotationRadians = _ref.setRotationRadians,
    zoomLevel = _ref.zoomLevel,
    maxZoomLevel = _ref.maxZoomLevel,
    bindOutsideChangeHelper = _ref.bindOutsideChangeHelper,
    smallSlider = _ref.smallSlider;
  var target = _react["default"].useRef();
  var showLabelsDebounced = (0, _useDebounce.useDebouncedCallback)(function () {
    try {
      var el = target.current.closest(".veCircularView").querySelector(".circularViewSvg");
      if (el) el.classList.remove("veHideLabels");else {
        console.error("whoops we shouldn't be here");
      }
    } catch (e) {
      console.error("error 92hf290fasd:", e);
    }
  },
  // delay in ms
  300, {
    leading: true
  });
  var stepSize = Math.min(3, 3 / (zoomLevel / 2) * (maxZoomLevel / (zoomLevel / 2)));
  return /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      zIndex: 900,
      position: "absolute"
    }
  }, /*#__PURE__*/_react["default"].createElement(_UncontrolledSliderWithPlusMinusBtns["default"], {
    bindOutsideChangeHelper: bindOutsideChangeHelper,
    onChange: function onChange(_val) {
      var val = 360 - _val;
      var el = target.current.closest(".veCircularView").querySelector(".circularViewSvg");
      var innerEl = target.current.closest(".veCircularView").querySelector(".circularViewSvg g");
      innerEl.style.transform = "rotate(" + val + "deg)";
      setRotationRadians(val * Math.PI / 180);
      if (zoomLevel <= 1) {
        el.classList.add("veHideLabels");
      }
      showLabelsDebounced();
    },
    smallSlider: true,
    passedRef: target,
    showTrackFill: false,
    leftIcon: "arrow-left",
    rightIcon: "arrow-right",
    title: "Rotate",
    style: {
      paddingTop: "4px",
      width: smallSlider ? _constants.SLIDER_SMALL_WIDTH : _constants.SLIDER_NORM_WIDTH
    },
    className: "veRotateCircularSlider ove-slider",
    labelRenderer: false,
    stepSize: stepSize,
    justUpdateInitialValOnce: true
    // initialValue={initialRotation || 0}
    ,
    max: 360,
    min: 0
  }));
}