"use strict"

Object.defineProperty(exports, "__esModule", {
  value: true,
})
exports.StreetViewPanorama = undefined

var _defineProperty2 = require("babel-runtime/helpers/defineProperty")

var _defineProperty3 = _interopRequireDefault(_defineProperty2)

var _getPrototypeOf = require("babel-runtime/core-js/object/get-prototype-of")

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf)

var _classCallCheck2 = require("babel-runtime/helpers/classCallCheck")

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2)

var _createClass2 = require("babel-runtime/helpers/createClass")

var _createClass3 = _interopRequireDefault(_createClass2)

var _possibleConstructorReturn2 = require("babel-runtime/helpers/possibleConstructorReturn")

var _possibleConstructorReturn3 = _interopRequireDefault(
  _possibleConstructorReturn2
)

var _inherits2 = require("babel-runtime/helpers/inherits")

var _inherits3 = _interopRequireDefault(_inherits2)

var _invariant = require("invariant")

var _invariant2 = _interopRequireDefault(_invariant)

var _react = require("react")

var _react2 = _interopRequireDefault(_react)

var _propTypes = require("prop-types")

var _propTypes2 = _interopRequireDefault(_propTypes)

var _MapChildHelper = require("../utils/MapChildHelper")

var _constants = require("../constants")

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : { default: obj }
}

/**
 * A wrapper around `google.maps.StreetViewPanorama`
 *
 * @see https://developers.google.com/maps/documentation/javascript/3.exp/reference#StreetViewPanorama
 */
var StreetViewPanorama = (exports.StreetViewPanorama = (function(
  _React$PureComponent
) {
  ;(0, _inherits3.default)(StreetViewPanorama, _React$PureComponent)

  function StreetViewPanorama(props, context) {
    ;(0, _classCallCheck3.default)(this, StreetViewPanorama)

    var _this = (0, _possibleConstructorReturn3.default)(
      this,
      (
        StreetViewPanorama.__proto__ ||
        (0, _getPrototypeOf2.default)(StreetViewPanorama)
      ).call(this, props, context)
    )

    ;(0, _invariant2.default)(
      !!_this.context[_constants.MAP],
      "Did you render <StreetViewPanorama> as a child of <GoogleMap> with withGoogleMap() HOC?"
    )
    ;(0, _MapChildHelper.construct)(
      StreetViewPanorama.propTypes,
      updaterMap,
      _this.props,
      _this.context[_constants.MAP].getStreetView()
    )
    return _this
  }

  ;(0, _createClass3.default)(StreetViewPanorama, [
    {
      key: "getChildContext",
      value: function getChildContext() {
        return (0, _defineProperty3.default)(
          {},
          _constants.MAP,
          this.context[_constants.MAP].getStreetView()
        )
      },
    },
    {
      key: "componentDidMount",
      value: function componentDidMount() {
        ;(0, _MapChildHelper.componentDidMount)(
          this,
          this.context[_constants.MAP].getStreetView(),
          eventMap
        )
      },
    },
    {
      key: "componentDidUpdate",
      value: function componentDidUpdate(prevProps) {
        ;(0, _MapChildHelper.componentDidUpdate)(
          this,
          this.context[_constants.MAP].getStreetView(),
          eventMap,
          updaterMap,
          prevProps
        )
      },
    },
    {
      key: "componentWillUnmount",
      value: function componentWillUnmount() {
        ;(0, _MapChildHelper.componentWillUnmount)(this)
        var streetViewPanorama = this.context[_constants.MAP].getStreetView()
        if (streetViewPanorama) {
          streetViewPanorama.setVisible(false)
        }
      },
    },
    {
      key: "render",
      value: function render() {
        var children = this.props.children

        return _react2.default.createElement("div", null, children)
      },

      /**
       * Returns the set of navigation links for the Street View panorama.
       * @type Array<StreetViewLink>
       * @public
       */
    },
    {
      key: "getLinks",
      value: function getLinks() {
        return this.context[_constants.MAP].getLinks()
      },

      /**
       * Returns the StreetViewLocation of the current panorama.
       * @type StreetViewLocation
       * @public
       */
    },
    {
      key: "getLocation",
      value: function getLocation() {
        return this.context[_constants.MAP].getLocation()
      },

      /**
       * Returns the state of motion tracker. If true when the user physically moves the device and the browser supports it, the Street View Panorama tracks the physical movements.
       * @type boolean
       * @public
       */
    },
    {
      key: "getMotionTracking",
      value: function getMotionTracking() {
        return this.context[_constants.MAP].getMotionTracking()
      },

      /**
       * Returns the current panorama ID for the Street View panorama. This id is stable within the browser's current session only.
       * @type string
       * @public
       */
    },
    {
      key: "getPano",
      value: function getPano() {
        return this.context[_constants.MAP].getPano()
      },

      /**
       * Returns the heading and pitch of the photographer when this panorama was taken. For Street View panoramas on the road, this also reveals in which direction the car was travelling. This data is available after the `pano_changed` event.
       * @type StreetViewPovpano_changed
       * @public
       */
    },
    {
      key: "getPhotographerPov",
      value: function getPhotographerPov() {
        return this.context[_constants.MAP].getPhotographerPov()
      },

      /**
       * Returns the current `LatLng` position for the Street View panorama.
       * @type LatLngLatLng
       * @public
       */
    },
    {
      key: "getPosition",
      value: function getPosition() {
        return this.context[_constants.MAP].getPosition()
      },

      /**
       * Returns the current point of view for the Street View panorama.
       * @type StreetViewPov
       * @public
       */
    },
    {
      key: "getPov",
      value: function getPov() {
        return this.context[_constants.MAP].getPov()
      },

      /**
       * Returns the status of the panorama on completion of the `setPosition()` or `setPano()` request.
       * @type StreetViewStatussetPosition()setPano()
       * @public
       */
    },
    {
      key: "getStatus",
      value: function getStatus() {
        return this.context[_constants.MAP].getStatus()
      },

      /**
       * Returns `true` if the panorama is visible. It does not specify whether Street View imagery is available at the specified position.
       * @type booleantrue
       * @public
       */
    },
    {
      key: "getVisible",
      value: function getVisible() {
        return this.context[_constants.MAP].getVisible()
      },

      /**
       * Returns the zoom level of the panorama. Fully zoomed-out is level 0, where the field of view is 180 degrees. Zooming in increases the zoom level.
       * @type number
       * @public
       */
    },
    {
      key: "getZoom",
      value: function getZoom() {
        return this.context[_constants.MAP].getZoom()
      },
    },
  ])
  return StreetViewPanorama
})(
  _react2.default.PureComponent
)) /*
                                   * -----------------------------------------------------------------------------
                                   * This file is auto-generated from the corresponding file at `src/macros/`.
                                   * Please **DO NOT** edit this file directly when creating PRs.
                                   * -----------------------------------------------------------------------------
                                   */

StreetViewPanorama.propTypes = {
  /**
   * @type Array<StreetViewLink>
   */
  defaultLinks: _propTypes2.default.any,

  /**
   * @type boolean
   */
  defaultMotionTracking: _propTypes2.default.bool,

  /**
   * @type StreetViewPanoramaOptions
   */
  defaultOptions: _propTypes2.default.any,

  /**
   * @type string
   */
  defaultPano: _propTypes2.default.string,

  /**
   * @type LatLng|LatLngLiteral
   */
  defaultPosition: _propTypes2.default.any,

  /**
   * @type StreetViewPov
   */
  defaultPov: _propTypes2.default.any,

  /**
   * @type boolean
   */
  defaultVisible: _propTypes2.default.bool,

  /**
   * @type number
   */
  defaultZoom: _propTypes2.default.number,

  /**
   * @type Array<StreetViewLink>
   */
  links: _propTypes2.default.any,

  /**
   * @type boolean
   */
  motionTracking: _propTypes2.default.bool,

  /**
   * @type StreetViewPanoramaOptions
   */
  options: _propTypes2.default.any,

  /**
   * @type string
   */
  pano: _propTypes2.default.string,

  /**
   * @type LatLng|LatLngLiteral
   */
  position: _propTypes2.default.any,

  /**
   * @type StreetViewPov
   */
  pov: _propTypes2.default.any,

  /**
   * @type boolean
   */
  visible: _propTypes2.default.bool,

  /**
   * @type number
   */
  zoom: _propTypes2.default.number,

  /**
   * function
   */
  onCloseClick: _propTypes2.default.func,

  /**
   * function
   */
  onPanoChanged: _propTypes2.default.func,

  /**
   * function
   */
  onPositionChanged: _propTypes2.default.func,

  /**
   * function
   */
  onPovChanged: _propTypes2.default.func,

  /**
   * function
   */
  onResize: _propTypes2.default.func,

  /**
   * function
   */
  onStatusChanged: _propTypes2.default.func,

  /**
   * function
   */
  onVisibleChanged: _propTypes2.default.func,

  /**
   * function
   */
  onZoomChanged: _propTypes2.default.func,
}
StreetViewPanorama.contextTypes = (0, _defineProperty3.default)(
  {},
  _constants.MAP,
  _propTypes2.default.object
)
StreetViewPanorama.childContextTypes = (0, _defineProperty3.default)(
  {},
  _constants.MAP,
  _propTypes2.default.object
)
exports.default = StreetViewPanorama

var eventMap = {
  onCloseClick: "closeclick",
  onPanoChanged: "pano_changed",
  onPositionChanged: "position_changed",
  onPovChanged: "pov_changed",
  onResize: "resize",
  onStatusChanged: "status_changed",
  onVisibleChanged: "visible_changed",
  onZoomChanged: "zoom_changed",
}

var updaterMap = {
  links: function links(instance, _links) {
    instance.setLinks(_links)
  },
  motionTracking: function motionTracking(instance, _motionTracking) {
    instance.setMotionTracking(_motionTracking)
  },
  options: function options(instance, _options) {
    instance.setOptions(_options)
  },
  pano: function pano(instance, _pano) {
    instance.setPano(_pano)
  },
  position: function position(instance, _position) {
    instance.setPosition(_position)
  },
  pov: function pov(instance, _pov) {
    instance.setPov(_pov)
  },
  visible: function visible(instance, _visible) {
    instance.setVisible(_visible)
  },
  zoom: function zoom(instance, _zoom) {
    instance.setZoom(_zoom)
  },
}
