/** * External dependencies */ import { __ } from '@wordpress/i18n'; import moment from 'moment'; import { SelectControl } from '@wordpress/components'; import { DatePicker } from '@woocommerce/components'; import { dateValidationMessages } from '@woocommerce/date'; function HistoricalDataPeriodSelector( { dateFormat, disabled, onDateChange, onPeriodChange, value, } ) { const onSelectChange = ( val ) => { onPeriodChange( val ); }; const onDatePickerChange = ( val ) => { if ( val.date && val.date.isValid ) { onDateChange( val.date.format( dateFormat ) ); } else { onDateChange( val.text ); } }; const getDatePickerError = ( momentDate ) => { if ( ! momentDate.isValid() || value.date.length !== dateFormat.length ) { return dateValidationMessages.invalid; } if ( momentDate.isAfter( new Date(), 'day' ) ) { return dateValidationMessages.future; } return null; }; const getDatePicker = () => { const momentDate = moment( value.date, dateFormat ); return (