import type { PaywallPlan } from '@funnelsgrove/payments'; import { resolveStepEditorUserVariableValues, type StepEditorSection, } from '@funnelsgrove/runtime'; export const buildPlanVariableValues = (plans: readonly PaywallPlan[]): Record => { return Object.fromEntries( plans.flatMap((plan) => { const prefix = `plan.${plan.id}`; return [ [`${prefix}.priceLabel`, plan.priceLabel], [`${prefix}.dailyPrice`, plan.comparison?.perDay || `${plan.perDayAmount}/day`], [`${prefix}.weeklyPrice`, plan.comparison?.perWeek || ''], [`${prefix}.monthlyPrice`, plan.comparison?.perMonth || plan.priceLabel], [`${prefix}.yearlyPrice`, plan.comparison?.perYear || ''], ]; }), ); }; export const buildStepVariableValues = ( sections: readonly StepEditorSection[], answers: Record, extraValues?: Record, ): Record => { return { ...resolveStepEditorUserVariableValues(sections, answers), ...(extraValues || {}), }; };