import React from 'react'
import { t } from 'ttag'
import { connect } from 'react-redux'
import ConfigurationStep from './ConfigurationStep'
import { timeLabels } from '../config'
import { selectClimateModel, selectClimateYear } from '../actions/climate'
type ClimateStepProps = {
title?: string
seedlotHelpText?: string
siteHelpText?: string
climate: any
number: number
active: boolean
onChange: (type: string, value: string, climate: string) => any
}
const ClimateStep = ({ title, seedlotHelpText, siteHelpText, climate, number, active, onChange }: ClimateStepProps) => {
const { seedlot, site } = climate
let modelSelect = null
if (!active) {
let siteKey = site.time
if (site.time !== '1961_1990' && site.time !== '1981_2010') {
siteKey += site.model
}
return (
{t`Seedlot climate:`}
{timeLabels[seedlot.time]}
{t`Planting site climate:`}
{timeLabels[siteKey]}
)
}
if (site.time !== '1961_1990' && site.time !== '1981_2010') {
modelSelect = (
)
}
return (
{seedlotHelpText}
{siteHelpText}
{modelSelect}
)
}
ClimateStep.defaultProps = {
title: t`Select climate scenarios`,
seedlotHelpText: t`Which climate are the seedlots adapted to?`,
siteHelpText: t`When should trees be best adapted to the planting site?`,
}
export default connect(
({ runConfiguration }: { runConfiguration: any }) => {
const { climate } = runConfiguration
return { climate }
},
(dispatch: (event: any) => any) => ({
onChange: (type: string, value: string, climate: string) => {
switch (type) {
case 'year':
dispatch(selectClimateYear(value, climate))
break
case 'model':
default:
dispatch(selectClimateModel(value, climate))
break
}
},
}),
)(ClimateStep)