"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _reactNative = require("react-native");
var _MapViewManager = require("./MapViewManager");
var _SendCommand = require("./SendCommand");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
const MapView = (props, parentRef) => {
  const nodeRef = (0, _react.useRef)(null);
  (0, _react.useEffect)(() => {
    if (_reactNative.Platform.OS == 'android') {
      (0, _SendCommand.createFragment)((0, _reactNative.findNodeHandle)(nodeRef.current));
    }
  }, []);
  (0, _react.useImperativeHandle)(parentRef, () => {
    const viewId = (0, _reactNative.findNodeHandle)(nodeRef.current);
    const listeners = {
      setMapVenue: credentials => {
        setTimeout(function () {
          (0, _SendCommand.setMapVenue)({
            viewId,
            credentials
          });
        }, 500);
      },
      // setMapVenue: ({
      //   credentials,
      //   compass,
      //   floorSelector,
      //   zoomButtons,
      //   search,
      // }: {
      //   credentials: MAP_CREDENTIALS;
      //   compass?: MAP_COMPASS_PROPERTIES;
      //   floorSelector?: MAP_FLOOR_SELECTOR_PROPERTIES;
      //   zoomButtons?: MAP_ZOOM_BUTTON_PROPERTIES;
      //   search?: MAP_SEARCH_PROPERTIES;
      // }) => {
      //   setMapVenue({
      //     viewId,
      //     credentials,
      //     compass,
      //     floorSelector,
      //     zoomButtons,
      //     search,
      //   });
      // },
      centerMapOnUser: function (orientation) {
        let animationDuration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1000;
        (0, _SendCommand.centerMap)(viewId, orientation, animationDuration);
      },
      //   setFollowBlueDot: (
      //     enabled: boolean,
      //     rotate: boolean = false,
      //     interval: number = 500
      //   ) => {
      //     setFollowBlueDot(viewId, enabled, rotate, interval);
      //   },
      setUserPosition: (lat, long, heading) => {
        (0, _SendCommand.setUserPosition)(viewId, lat, long, heading);
      }
      //   setUserPositionXY: (x: number, y: number, heading: number) => {
      //     setUserPosition(viewId, x, y, heading, 'xy');
      //   },
      //   clearWayfindingPath: () => {
      //     clearWayfindingPath(viewId);
      //   },
      //   wayfindToWaypoint: (waypointId: number) => {
      //     wayfindToWaypoint(viewId, waypointId);
      //   },
      //   wayfindBetweenWaypoints: (originId: number, destinationId: number) => {
      //     wayfindBetweenWaypoints(viewId, originId, destinationId);
      //   },
      //   drawNavigationPath: (
      //     pathId: string,
      //     shouldFocus: boolean = true,
      //     style: JIBESTREAM_STYLE = {
      //       stroke: '#ffc956',
      //       strokeWidth: 3,
      //     }
      //   ) => {
      //     drawNavigationPath(viewId, pathId, shouldFocus, style);
      //   },
      //   styleUnitsForDestination: (
      //     destination: JIBESTREAM_DESTINATION,
      //     style: JIBESTREAM_STYLE = { fill: '#ABABAB' }
      //   ) => {
      //     styleUnitsForDestination(viewId, destination, style);
      //   },
      //   styleShape: (
      //     unitId: number,
      //     style: JIBESTREAM_STYLE = { fill: '#ABABAB' }
      //   ) => {
      //     styleShape(viewId, unitId, style);
      //   },
    };

    return listeners;
  });
  (0, _react.useEffect)(() => {
    var _eventEmitter;
    console.log('Initializing Event Emitter');
    let eventEmitter = null;
    if (_reactNative.Platform.OS == 'android') {
      eventEmitter = _reactNative.DeviceEventEmitter;
    } else if (_reactNative.Platform.OS == 'ios') {
      console.log(_MapViewManager.CTPEventEmitter);
      eventEmitter = new _reactNative.NativeEventEmitter(_MapViewManager.CTPEventEmitter);
    }
    // eventEmitter?.addListener(
    //   'DESTINATION_SELECTED',
    //   (data: JIBESTREAM_DESTINATION) =>
    //     props.onMapMessage.onDestinationSelected?.(data)
    // );
    // eventEmitter?.addListener(
    //   'NAVIGATION_PATH_GENERATED',
    //   (data: {
    //     pathId: string;
    //     instructions: INSTRUCTION[];
    //     start: JIBESTREAM_WAYPOINT;
    //     end: JIBESTREAM_WAYPOINT;
    //     path: JIBESTREAM_PATH[];
    //   }) =>
    //     props.onMapMessage.onNavigationPathGenerated?.(
    //       data.pathId,
    //       data.instructions,
    //       data.start,
    //       data.end,
    //       data.path
    //     )
    // );
    (_eventEmitter = eventEmitter) === null || _eventEmitter === void 0 ? void 0 : _eventEmitter.addListener('USER_POSITION_UPDATED', data => {
      var _props$onMapMessage$o, _props$onMapMessage;
      return (_props$onMapMessage$o = (_props$onMapMessage = props.onMapMessage).onUserPositionUpdated) === null || _props$onMapMessage$o === void 0 ? void 0 : _props$onMapMessage$o.call(_props$onMapMessage, data);
    });
    // eventEmitter?.addListener('WINDOW_LOADED', () =>
    //   props.onMapMessage.onWindowLoaded?.()
    // );
    // eventEmitter?.addListener('MAP_TAPPED_GENERIC', (data: MAP_TAP_EVENT) =>
    //   props.onMapMessage.onMapTappedGeneric?.(data)
    // );
    // eventEmitter?.addListener('ODP_READY', (event: ODP_ON_READY) => {
    //   console.log('ODP onReady');
    //   props.onOdpEvent.onReady?.(event);
    // });
    // eventEmitter?.addListener(
    //   'ODP_KEY_VALIDATION',
    //   (event: ODP_ON_KEY_VALIDATION) => {
    //     console.log('ODP onKeyValidation');
    //     props.onOdpEvent.onKeyValidation?.(event);
    //   }
    // );
    // eventEmitter?.addListener(
    //   'ODP_NAVIGATION_UPDATE',
    //   (event: ODP_ON_NAVIGATION_UPDATE) => {
    //     props.onOdpEvent.onNavigationUpdate?.(event);
    //   }
    // );
    // eventEmitter?.addListener(
    //   'ODP_FACILITY_UPDATE',
    //   (event: ODP_ON_FACILITY_UPDATE) => {
    //     console.log('ODP onFacilityUpdate');
    //     props.onOdpEvent.onFacilityUpdate?.(event);
    //   }
    // );
    return () => {
      var _eventEmitter2;
      console.log('Removing Event Emitters');
      //   eventEmitter?.removeAllListeners('DESTINATION_SELECTED');
      //   eventEmitter?.removeAllListeners('NAVIGATION_PATH_GENERATED');
      (_eventEmitter2 = eventEmitter) === null || _eventEmitter2 === void 0 ? void 0 : _eventEmitter2.removeAllListeners('USER_POSITION_UPDATED');
      //   eventEmitter?.removeAllListeners('WINDOW_LOADED');
      //   eventEmitter?.removeAllListeners('MAP_TAPPED_GENERIC');
      //   eventEmitter?.removeAllListeners('ODP_READY');
      //   eventEmitter?.removeAllListeners('ODP_KEY_VALIDATION');
      //   eventEmitter?.removeAllListeners('ODP_NAVIGATION_UPDATE');
      //   eventEmitter?.removeAllListeners('ODP_FACILITY_UPDATE');
    };
  }, []);
  return /*#__PURE__*/_react.default.createElement(_reactNative.SafeAreaView, {
    style: {
      flex: 1,
      width: '100%',
      height: '100%'
    }
  }, _MapViewManager.MapViewManager ? /*#__PURE__*/_react.default.createElement(_MapViewManager.MapViewManager, {
    style: _reactNative.Platform.OS == 'android' ? {
      // converts dpi to px, provide desired height
      height: _reactNative.PixelRatio.getPixelSizeForLayoutSize(props.style.height),
      // converts dpi to px, provide desired width
      width: _reactNative.PixelRatio.getPixelSizeForLayoutSize(props.style.width)
    } : {
      height: props.style.height / 1,
      width: props.style.width / 1
      // converts dpi to px, provide desired height
      // height: PixelRatio.getPixelSizeForLayoutSize(props.style.height),
      // converts dpi to px, provide desired width
      // width: PixelRatio.getPixelSizeForLayoutSize(props.style.width),
    },

    ref: nodeRef
  }) : null);
};
var _default = /*#__PURE__*/(0, _react.forwardRef)(MapView);
exports.default = _default;
//# sourceMappingURL=MapView.js.map