/*
This file is part of GNU Taler
(C) 2021 Taler Systems S.A.
GNU Taler is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software
Foundation; either version 3, or (at your option) any later version.
GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
GNU Taler; see the file COPYING. If not, see
*/
/**
*
* @author Sebastian Javier Marchano (sebasjm)
*/
import { format } from "date-fns";
import { h, VNode } from "preact";
import { useState } from "preact/hooks";
import { Translate, useTranslator } from "../../i18n";
import { DatePicker } from "../picker/DatePicker";
import { InputProps, useField } from "./useField";
export interface Props extends InputProps {
readonly?: boolean;
expand?: boolean;
//FIXME: create separated components InputDate and InputTimestamp
withTimestampSupport?: boolean;
}
export function InputDate({
name,
readonly,
label,
placeholder,
help,
tooltip,
expand,
withTimestampSupport,
}: Props): VNode {
const [opened, setOpened] = useState(false);
const i18n = useTranslator();
const { error, required, value, onChange } = useField(name);
let strValue = "";
if (!value) {
strValue = withTimestampSupport ? "unknown" : "";
} else if (value instanceof Date) {
strValue = format(value, "yyyy/MM/dd");
} else if (value.t_s) {
strValue =
value.t_s === "never"
? withTimestampSupport
? "never"
: ""
: format(new Date(value.t_s * 1000), "yyyy/MM/dd");
}
return (