import React from "react" import { InputNumber } from "antd" import type { WidgetProps } from "@react-awesome-query-builder/antd" import { useTranslation } from "react-i18next" import { getDefaultIntervalValue, parseIntervalTriggerValue, stringifyIntervalTriggerValue, type IntervalValue, } from "./IntervalValueCodec" export { parseIntervalTriggerValue, stringifyIntervalTriggerValue } from "./IntervalValueCodec" export type { IntervalValue, IntervalUnit } from "./IntervalValueCodec" const buildNextIntervalValue = ( currentValue: IntervalValue | null, patch: Partial ): IntervalValue => { const base = currentValue ?? getDefaultIntervalValue() return { days: patch.days ?? base.days, hours: patch.hours ?? base.hours, minutes: patch.minutes ?? base.minutes, } } const getDisplayValue = (value: number | undefined, fallback = 0) => typeof value === "number" && Number.isFinite(value) ? value : fallback export const IntervalValueWidget: React.FC = ({ value, setValue, readonly, }) => { const { t } = useTranslation() const parsedValue = parseIntervalTriggerValue(value) const updateValue = (patch: Partial) => { const nextValue = buildNextIntervalValue(parsedValue, patch) const serialized = stringifyIntervalTriggerValue(nextValue) setValue(serialized) } return (
{t("autoScore.intervalPartDay")} updateValue({ days: Math.max(0, Number(next ?? 0)) })} style={{ width: "100%" }} />
{t("autoScore.intervalPartHour")} updateValue({ hours: Math.max(0, Number(next ?? 0)) })} style={{ width: "100%" }} />
{t("autoScore.intervalPartMinute")} updateValue({ minutes: Math.max(0, Number(next ?? 0)) })} style={{ width: "100%" }} />
) } export default IntervalValueWidget