"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _reactNative = require("react-native");
var _react = _interopRequireWildcard(require("react"));
var _MapContext = require("../modules/MapContext");
var _MSlot = _interopRequireDefault(require("./slots/MSlot"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (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; }
/**
 * Compass props
 *
 * @category Props
 */

const styles = _reactNative.StyleSheet.create({
  compassContainer: {
    alignItems: 'center',
    justifyContent: 'center',
    width: 50,
    height: 50,
    backgroundColor: 'rgba(255, 255, 255, 0.8)',
    borderRadius: 25
  },
  heading: {
    fontSize: 16,
    fontWeight: 'bold',
    color: '#fff'
  },
  compass: {
    width: 50,
    height: 50,
    borderRadius: 50,
    borderWidth: 1,
    borderColor: '#bfbfbf',
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: '#2c2c2c'
  },
  arrow: {
    width: 0,
    height: 0,
    borderLeftWidth: 5,
    borderRightWidth: 5,
    borderBottomWidth: 20,
    borderStyle: 'solid',
    borderTopColor: 'transparent',
    borderLeftColor: 'transparent',
    borderRightColor: 'transparent',
    borderBottomColor: '#fff'
  }
});

/**
 * 指南针组件，当地图加载完成后开始工作，针头指向正北方向。可适配：通过参数传递替换组件的图标/样式。
  @category Component
 */
const Compass = props => {
  const {
    style
  } = props;
  // const [heading, setHeading] = useState<number>(0);
  const [rotateStyle, setRotateStyle] = (0, _react.useState)(_reactNative.StyleSheet.create({
    ratate: {
      transform: [{
        rotate: '0deg'
      }]
    }
  }));
  const {
    map
  } = (0, _react.useContext)(_MapContext.MapContext);
  const onLocationChange = event => {
    if (event.coords && event.coords.heading) {
      // setHeading(event.coords.heading);
      const rotateDeg = `${event.coords.heading * (180 / Math.PI)}deg`;
      setRotateStyle(_reactNative.StyleSheet.create({
        ratate: {
          transform: [{
            rotate: rotateDeg
          }]
        }
      }));
    }
  };
  (0, _react.useEffect)(() => {
    map.locationManager.on('locationChange', onLocationChange);
    return () => {
      // subscription.remove();
      //map.locationManager.off('locationChange', onLocationChange);
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  return /*#__PURE__*/_react.default.createElement(_MSlot.default, {
    style: style
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: [styles.compass, rotateStyle.rotate]
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: [styles.arrow]
  }), /*#__PURE__*/_react.default.createElement(_reactNative.Text, {
    style: styles.heading
  }, "N"), /*#__PURE__*/_react.default.createElement(_reactNative.Text, null)));
};
var _default = exports.default = Compass;
//# sourceMappingURL=Compass.js.map