import PropTypes from 'prop-types';
import { withTheme } from '../../styles';

/* istanbul ignore next */
const PolylineComponent = (props) => {
  const { maps, color, theme, options, path, map } = props;
  const { Polyline } = maps;

  const settings = {
    geodesic: true,
    strokeColor: color || theme.colors.primary.base,
    strokeOpacity: 0.5,
    strokeWeight: 3,
    ...options,
  };

  const polyline = new Polyline({
    path,
    ...settings,
  });

  polyline.setMap(map);

  return null;
};

PolylineComponent.propTypes = {
  maps: PropTypes.objectOf(Object).isRequired,
  map: PropTypes.objectOf(Object).isRequired,
  path: PropTypes.oneOfType([PropTypes.array, PropTypes.string]).isRequired,
  options: PropTypes.objectOf(Object),
  color: PropTypes.string,
};

PolylineComponent.defaultProps = {
  options: {},
};

export default withTheme(PolylineComponent);
