import { h } from 'preact'; import { useCallback, useEffect, useState } from 'preact/hooks'; export const DateFilterOptions = [ { label: 'All', value: ['all'], }, { label: 'Today', value: { //Before before: new Date().setHours(24, 0, 0, 0) / 1000, //After after: new Date().setHours(0, 0, 0, 0) / 1000, }, }, { label: 'Yesterday', value: { //Before before: new Date(new Date().setDate(new Date().getDate() - 1)).setHours(24, 0, 0, 0) / 1000, //After after: new Date(new Date().setDate(new Date().getDate() - 1)).setHours(0, 0, 0, 0) / 1000, }, }, { label: 'Last 7 Days', value: { //Before before: new Date().setHours(24, 0, 0, 0) / 1000, //After after: new Date(new Date().setDate(new Date().getDate() - 7)).setHours(0, 0, 0, 0) / 1000, }, }, { label: 'This Month', value: { //Before before: new Date().setHours(24, 0, 0, 0) / 1000, //After after: new Date(new Date().getFullYear(), new Date().getMonth(), 1).getTime() / 1000, }, }, { label: 'Last Month', value: { //Before before: new Date(new Date().getFullYear(), new Date().getMonth(), 1).getTime() / 1000, //After after: new Date(new Date().getFullYear(), new Date().getMonth() - 1, 1).getTime() / 1000, }, }, { label: 'Custom Range', value: 'custom_range', }, ]; export default function DatePicker({ helpText, keyboardType = 'text', inputRef, label, leadingIcon: LeadingIcon, onBlur, onChangeText, onFocus, trailingIcon: TrailingIcon, value: propValue = '', ...props }) { const [isFocused, setFocused] = useState(false); const [value, setValue] = useState(propValue); useEffect(() => { if (propValue !== value) { setValue(propValue); } }, [propValue, setValue, value]); const handleFocus = useCallback( (event) => { setFocused(true); onFocus && onFocus(event); }, [onFocus] ); const handleBlur = useCallback( (event) => { setFocused(false); onBlur && onBlur(event); }, [onBlur] ); const handleChange = useCallback( (event) => { const { value } = event.target; setValue(value); onChangeText && onChangeText(value); }, [onChangeText, setValue] ); const onClick = (e) => { props.onclick(e); }; const labelMoved = isFocused || value !== ''; return (