diff --git a/apps/web/src/app/create/worksheets/addition/displayRules.ts b/apps/web/src/app/create/worksheets/addition/displayRules.ts index 5f58e334..4cce28b6 100644 --- a/apps/web/src/app/create/worksheets/addition/displayRules.ts +++ b/apps/web/src/app/create/worksheets/addition/displayRules.ts @@ -1,32 +1,36 @@ // Display rules for conditional per-problem scaffolding -import type { ProblemMeta, SubtractionProblemMeta } from './problemAnalysis' +import type { ProblemMeta, SubtractionProblemMeta } from "./problemAnalysis"; -export type AnyProblemMeta = ProblemMeta | SubtractionProblemMeta +export type AnyProblemMeta = ProblemMeta | SubtractionProblemMeta; export type RuleMode = - | 'always' // Always show this display option - | 'never' // Never show this display option - | 'whenRegrouping' // Show when problem requires any regrouping - | 'whenMultipleRegroups' // Show when 2+ place values regroup - | 'when3PlusDigits' // Show when maxDigits >= 3 + | "always" // Always show this display option + | "never" // Never show this display option + | "whenRegrouping" // Show when problem requires any regrouping + | "whenMultipleRegroups" // Show when 2+ place values regroup + | "when3PlusDigits"; // Show when maxDigits >= 3 export interface DisplayRules { - carryBoxes: RuleMode - answerBoxes: RuleMode - placeValueColors: RuleMode - tenFrames: RuleMode - problemNumbers: RuleMode - cellBorders: RuleMode + carryBoxes: RuleMode; + answerBoxes: RuleMode; + placeValueColors: RuleMode; + tenFrames: RuleMode; + problemNumbers: RuleMode; + cellBorders: RuleMode; + borrowNotation: RuleMode; // Subtraction: scratch boxes showing borrowed 10s + borrowingHints: RuleMode; // Subtraction: arrows and visual hints } export interface ResolvedDisplayOptions { - showCarryBoxes: boolean - showAnswerBoxes: boolean - showPlaceValueColors: boolean - showTenFrames: boolean - showProblemNumbers: boolean - showCellBorder: boolean + showCarryBoxes: boolean; + showAnswerBoxes: boolean; + showPlaceValueColors: boolean; + showTenFrames: boolean; + showProblemNumbers: boolean; + showCellBorder: boolean; + showBorrowNotation: boolean; // Subtraction: scratch work boxes in minuend + showBorrowingHints: boolean; // Subtraction: hints with arrows } /** @@ -35,24 +39,26 @@ export interface ResolvedDisplayOptions { */ export function evaluateRule(mode: RuleMode, problem: AnyProblemMeta): boolean { switch (mode) { - case 'always': - return true + case "always": + return true; - case 'never': - return false + case "never": + return false; - case 'whenRegrouping': + case "whenRegrouping": // Works for both: requiresRegrouping (addition) or requiresBorrowing (subtraction) - return 'requiresRegrouping' in problem + return "requiresRegrouping" in problem ? problem.requiresRegrouping - : problem.requiresBorrowing + : problem.requiresBorrowing; - case 'whenMultipleRegroups': + case "whenMultipleRegroups": // Works for both: regroupCount (addition) or borrowCount (subtraction) - return 'regroupCount' in problem ? problem.regroupCount >= 2 : problem.borrowCount >= 2 + return "regroupCount" in problem + ? problem.regroupCount >= 2 + : problem.borrowCount >= 2; - case 'when3PlusDigits': - return problem.maxDigits >= 3 + case "when3PlusDigits": + return problem.maxDigits >= 3; } } @@ -62,10 +68,10 @@ export function evaluateRule(mode: RuleMode, problem: AnyProblemMeta): boolean { */ export function resolveDisplayForProblem( rules: DisplayRules, - problem: AnyProblemMeta + problem: AnyProblemMeta, ): ResolvedDisplayOptions { - console.log('[resolveDisplayForProblem] Input rules:', rules) - console.log('[resolveDisplayForProblem] Problem meta:', problem) + console.log("[resolveDisplayForProblem] Input rules:", rules); + console.log("[resolveDisplayForProblem] Problem meta:", problem); const resolved = { showCarryBoxes: evaluateRule(rules.carryBoxes, problem), @@ -74,15 +80,17 @@ export function resolveDisplayForProblem( showTenFrames: evaluateRule(rules.tenFrames, problem), showProblemNumbers: evaluateRule(rules.problemNumbers, problem), showCellBorder: evaluateRule(rules.cellBorders, problem), - } + showBorrowNotation: evaluateRule(rules.borrowNotation, problem), + showBorrowingHints: evaluateRule(rules.borrowingHints, problem), + }; - console.log('[resolveDisplayForProblem] Resolved display options:', resolved) + console.log("[resolveDisplayForProblem] Resolved display options:", resolved); console.log( - '[resolveDisplayForProblem] Ten-frames rule:', + "[resolveDisplayForProblem] Ten-frames rule:", rules.tenFrames, - '-> showTenFrames:', - resolved.showTenFrames - ) + "-> showTenFrames:", + resolved.showTenFrames, + ); - return resolved + return resolved; }