import React, { useState } from 'react';
import { FormattedMessage } from 'react-intl';
import { endOfYear } from 'date-fns';
import Modal from './Modal';
import DropDown from './DropDown';
import DatePickerForm from 'components/forms/DatePickerForm';
import useLocale from 'hooks/useLocale';
import { getDateRange } from 'lib/date';
import { dateFormat } from 'lib/lang';
const filterOptions = [
{
label: (
),
value: '24hour',
},
{
label: (
),
value: '7day',
},
{
label: (
),
value: '30day',
},
{
label: (
),
value: '90day',
},
{ label: , value: '1day' },
{ label: , value: '1week' },
{
label: ,
value: '1month',
},
{ label: , value: '1year' },
{
label: ,
value: 'custom',
},
];
export default function DateFilter({ value, startDate, endDate, onChange, className }) {
const [locale] = useLocale();
const [showPicker, setShowPicker] = useState(false);
const displayValue =
value === 'custom'
? `${dateFormat(startDate, 'd LLL y', locale)} — ${dateFormat(endDate, 'd LLL y', locale)}`
: value;
function handleChange(value) {
if (value === 'custom') {
setShowPicker(true);
return;
}
onChange(getDateRange(value));
}
function handlePickerChange(value) {
setShowPicker(false);
onChange(value);
}
return (
<>
{showPicker && (
setShowPicker(false)}
/>
)}
>
);
}