import { IonButtons, IonContent, IonHeader, IonMenuButton, IonPage, IonTitle, IonToolbar } from '@ionic/react';
import React from 'react';
import Map from '../components/Map';
import { connect } from '../data/connect';
import * as selectors from '../data/selectors';
import { Location } from '../models/Location';
import './MapView.scss';

interface OwnProps {}

interface StateProps {
  locations: Location[];
  mapCenter: Location;
}

interface DispatchProps {}

interface MapViewProps extends OwnProps, StateProps, DispatchProps {}

const MapView: React.FC<MapViewProps> = ({ locations, mapCenter }) => {
  return (
    <IonPage id="map-view">
      <IonHeader>
        <IonToolbar>
          <IonButtons slot="start">
            <IonMenuButton></IonMenuButton>
          </IonButtons>
          <IonTitle>Map</IonTitle>
        </IonToolbar>
      </IonHeader>

      <IonContent class="map-page">
        <Map locations={locations} mapCenter={mapCenter} />
      </IonContent>
    </IonPage>
  );
};

export default connect<OwnProps, StateProps, DispatchProps>({
  mapStateToProps: state => ({
    locations: state.data.locations,
    mapCenter: selectors.mapCenter(state),
  }),
  component: MapView,
});
