import { AbsoluteTime, AmountJson, Amounts, TranslatedString, } from "@gnu-taler/taler-util"; import { FormState } from "../handlers/FormProvider.js"; import { DoubleColumnFormSection } from "../handlers/forms.js"; import { State } from "../pages/AntiMoneyLaunderingForm.js"; import { amlStateConverter } from "../pages/CaseDetails.js"; import { AmlExchangeBackend } from "../types.js"; import { FlexibleForm } from "./index.js"; export const v1 = (current: State): FlexibleForm => ({ versionId: "2023-05-25", design: [ { title: "Simple form" as TranslatedString, fields: [ { type: "textArea", props: { name: "comment", label: "Comments" as TranslatedString, }, }, ], }, resolutionSection(current), ], behavior: function formBehavior( v: Partial, ): FormState { return { when: { disabled: true, }, threshold: { disabled: v.state === AmlExchangeBackend.AmlState.frozen, }, }; }, }); export namespace Simplest { export interface WithResolution { when: AbsoluteTime; threshold: AmountJson; state: AmlExchangeBackend.AmlState; } export interface Form extends WithResolution { comment: string; } } export function resolutionSection(current: State): DoubleColumnFormSection { return { title: "Resolution" as TranslatedString, description: `Current state is ${amlStateConverter.toStringUI( current.state, )} and threshold at ${Amounts.stringifyValue( current.threshold, )}` as TranslatedString, fields: [ { type: "date", props: { name: "when", label: "Decision Time" as TranslatedString, }, }, { type: "choiceHorizontal", props: { name: "state", label: "New state" as TranslatedString, converter: amlStateConverter, choices: [ { value: AmlExchangeBackend.AmlState.frozen, label: "Frozen" as TranslatedString, }, { value: AmlExchangeBackend.AmlState.pending, label: "Pending" as TranslatedString, }, { value: AmlExchangeBackend.AmlState.normal, label: "Normal" as TranslatedString, }, ], }, }, { type: "amount", props: { name: "threshold", label: "New threshold" as TranslatedString, }, }, ], }; }