/**
* Settings of "Live result": which calculations it shows, with which labels, and whether it is a
* card in the step or a box that stays visible on the following steps.
*/
import React from 'react';
import type { ResultField, ResultLine } from '@funnelforms/form-schema';
import type { Edit } from './Answers';
import { useBuilder, useEnv } from './context';
import { __, sprintf } from './i18n';
import { put, TextProp } from './texts';
import { Button, ChoiceTiles, IconButton, icons, Notice, Select, Sketch, TextInput, Toggle } from './ui';
import { LineTextToggle, ResultReveal } from './ResultReveal';
const MAX_LINES = 10;
const NONE: never[] = [];
export function ResultProps( { field, edit }: { field: ResultField; edit: Edit } ) {
const { ctx, lang, readOnly } = useEnv();
const calculations = useBuilder( ( st ) => st.doc?.calculations ?? NONE );
const p = field.props;
const props = ( recipe: ( props: ResultField[ 'props' ] ) => void, key?: string ): void => edit( ( f ) => recipe( ( f as ResultField ).props ), key );
const line = ( i: number, recipe: ( l: ResultLine ) => void, key: string ): void =>
props( ( pr ) => {
const item = pr.lines[ i ];
if ( item ) {
recipe( item );
}
}, `lines.${ i }.${ key }` );
const choices = calculations.map( ( c ) => ( { value: c.id, label: c.label || c.id } ) );
return (
<>
},
{ value: 'card', label: __( 'Card in this step', 'funnelforms-pro' ), icon: },
] }
onChange={ ( v ) => props( ( pr ) => void ( pr.style = v ), 'style' ) }
/>
{ 'sticky' === p.style ?
{ __( 'A bar at the bottom on phones, a card beside the steps on wide screens.', 'funnelforms-pro' ) }
: null }
{ choices.length ? null : { __( 'Add a calculation first, e.g. the price. The live result shows its result and updates it while visitors answer.', 'funnelforms-pro' ) } }
{ __( 'Results', 'funnelforms-pro' ) }
{ __( 'The first result is shown large, the others break it down. Currency and decimals come from the calculation.', 'funnelforms-pro' ) }
{ p.lines.map( ( l, i ) => (
{ 0 === i ? __( 'Main result', 'funnelforms-pro' ) : sprintf( /* translators: %d: number of the line in the breakdown */ __( 'Line %d', 'funnelforms-pro' ), i ) } props( ( pr ) => void pr.lines.splice( i, 1 ) ) } />