import React from 'react'
import { connect } from 'react-redux'
import { t, c, jt } from 'ttag'
import ConfigurationStep from './ConfigurationStep'
import PointChooser from './PointChooser'
import { setMapMode } from '../actions/map'
import { addUserSite } from '../actions/point'
type LocationStepProps = {
objective: string
number: number
elevation?: any
}
const LocationStep = ({ objective, number, elevation }: LocationStepProps) => {
const elevationNode =
elevation !== null ? (
{t`Elevation:`} {Math.round(elevation.ft)} ft ({Math.round(elevation.m)} m)
) : (
elevation
)
const siteLabel =
objective === 'sites'
? c("This is one possible value of 'siteLabel'").t`seedlot (its climatic center)`
: c("This is one possible value of 'siteLabel'").t`planting site`
return (
{t`Location`}
{jt`Locate your ${siteLabel} by using the map or entering coordinates.`}
)
}
LocationStep.defaultProps = {
elevation: null,
}
export default connect(
({ runConfiguration, map }: { runConfiguration: any; map: any }) => {
const { mode } = map
const { objective, point } = runConfiguration
let { elevation } = point
if (elevation !== null) {
elevation = { ft: elevation / 0.3048, m: elevation }
}
return { objective, point, elevation, mode }
},
dispatch => ({
onSetMapMode: (mode: string) => dispatch(setMapMode(mode)),
onAddUserSite: (lat: number, lon: number, label: string) => {
dispatch(addUserSite({ lat, lon }, label))
dispatch(setMapMode('normal'))
},
}),
)(LocationStep)