"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _maps = _interopRequireDefault(require("@rnmapbox/maps"));
var _reactNative = require("react-native");
var _react = _interopRequireWildcard(require("react"));
var _MapContext = require("../modules/MapContext");
var _style = require("../config/style");
var _Map = require("../modules/Map");
var _LeftSlot = _interopRequireDefault(require("./slots/LeftSlot"));
var _BottomSlot = _interopRequireDefault(require("./slots/BottomSlot"));
var _RightSlot = _interopRequireDefault(require("./slots/RightSlot"));
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; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
 * MapView Props
 *
 * @category Props
 */

/**
 * @example
 * ```
 * import Mapa from 'react-native-mapa';
 * // 或者import { MapView, Camera } from 'react-native-mapa';
 *
 * <Mapa.MapView>
 *  <Mapa.Camera pitch={60} />
 * </Mapa.MapView>
 * ```
 *
 * @category Component
 */
const MapView = /*#__PURE__*/_react.default.forwardRef((props, ref) => {
  const {
    children,
    style = 'MapboxVector',
    projection = 'mercator',
    onPress,
    onLongPress,
    onMapIdle
  } = props;
  const mapInsRef = (0, _react.useRef)(null);
  const [customStyles, setStyle] = (0, _react.useState)(() => {
    return (0, _style.styleFormat)(style);
  });
  const containerSlotValue = (0, _react.useRef)({
    leftSlotChildren: [],
    rightSlotChildren: [],
    bottomSlotChildren: []
  });
  const [lChildren, setLChildren] = (0, _react.useState)([]);
  const [rChildren, setRChildren] = (0, _react.useState)([]);
  const [bChildren, setBChildren] = (0, _react.useState)([]);
  const mapRef = (0, _react.useRef)(new class extends _Map.Map {
    constructor() {
      super(null);
    }
    updateStyle(stl) {
      setStyle((0, _style.styleFormat)(stl));
    }
  }());
  // mapView pix layout
  const [pixLayoutInfo, setLayoutInfo] = (0, _react.useState)({
    width: _reactNative.Dimensions.get('window').width,
    height: _reactNative.Dimensions.get('window').height
  });
  const onMapPress = e => {
    onPress?.(e);
    mapRef.current.emit('onPress', e);
  };
  (0, _react.useImperativeHandle)(ref, () => mapRef.current);

  // 获取地图的像素尺寸, 默认地图全屏！！改代码！！
  const getMapDimensions = () => {
    const {
      width,
      height
    } = _reactNative.Dimensions.get('window');
    setLayoutInfo({
      width,
      height
    });
  };
  (0, _react.useEffect)(() => {
    setStyle((0, _style.styleFormat)(style));
  }, [style]);
  (0, _react.useLayoutEffect)(() => {
    mapRef.current?.setMap(mapInsRef.current);
  }, []);
  return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: styles.page
  }, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
    style: styles.container
  }, /*#__PURE__*/_react.default.createElement(_maps.default.MapView, {
    ref: mapInsRef,
    styleURL: customStyles.styleURL,
    styleJSON: customStyles.styleJSON,
    projection: projection,
    attributionEnabled: false,
    logoEnabled: false,
    zoomEnabled: true,
    compassEnabled: false,
    scaleBarEnabled: false,
    rotateEnabled: true // 允许地图旋转
    ,
    onLayout: getMapDimensions,
    onPress: onMapPress,
    onLongPress: onLongPress,
    onMapIdle: onMapIdle,
    onCameraChanged: (...args) => mapRef.current?.emit('cameraChanged', ...args),
    onDidFinishLoadingMap: (...args) => mapRef.current?.emit('loaded', ...args),
    style: styles.map
  }, /*#__PURE__*/_react.default.createElement(_MapContext.MapContext.Provider, {
    value: {
      map: mapRef.current,
      pixLayoutInfo
    }
  }, /*#__PURE__*/_react.default.createElement(_MapContext.ContainerSlotContext.Provider, {
    value: {
      ...containerSlotValue.current,
      setLChildren,
      setRChildren,
      setBChildren
    }
  }, children, /*#__PURE__*/_react.default.createElement(_LeftSlot.default, {
    children: lChildren
  }), /*#__PURE__*/_react.default.createElement(_RightSlot.default, {
    children: rChildren
  }), /*#__PURE__*/_react.default.createElement(_BottomSlot.default, {
    children: bChildren
  }))))));
});
var _default = exports.default = MapView;
const styles = _reactNative.StyleSheet.create({
  page: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF'
  },
  container: {
    height: '100%',
    width: '100%',
    backgroundColor: 'tomato'
  },
  map: {
    flex: 1
  }
});
//# sourceMappingURL=MapView.js.map