diff --git a/frontend/src/tools/drawing/CapacityDisplayTool.ts b/frontend/src/tools/drawing/CapacityDisplayTool.ts index 4f15400..a1808d2 100644 --- a/frontend/src/tools/drawing/CapacityDisplayTool.ts +++ b/frontend/src/tools/drawing/CapacityDisplayTool.ts @@ -2,9 +2,12 @@ import { Tool } from '../Tool'; import { YjsDocument } from '../../crdt/YjsDocument'; class CapacityDisplayTool extends Tool { - constructor(yjsDoc: YjsDocument) { + private onCapacityUpdate: (totalCapacity: number, selectedCapacity: number) => void; + + constructor(yjsDoc: YjsDocument, onCapacityUpdate?: (totalCapacity: number, selectedCapacity: number) => void) { super(yjsDoc); this.name = 'CapacityDisplayTool'; + this.onCapacityUpdate = onCapacityUpdate || (() => {}); } onMouseDown(event: MouseEvent): void { @@ -34,17 +37,29 @@ class CapacityDisplayTool extends Tool { // Calculate capacity for selected tables calculateSelectedCapacity(): number { // In a real implementation, this would get selected tables from the canvas - // and calculate the total capacity based on table type and size - // For now, we'll return a placeholder value - return 0; + // For now, we'll count all chair elements as selected capacity + const elements = this.yjsDoc.getElements(); + let count = 0; + elements.forEach(element => { + if (element.type === 'chair') { + count++; + } + }); + return count; } // Calculate capacity for entire drawing calculateTotalCapacity(): number { - // In a real implementation, this would iterate through all elements in the Yjs document - // and count chairs or calculate capacity based on tables - // For now, we'll return a placeholder value - return 0; + // Iterate through all elements in the Yjs document + // and count chairs + const elements = this.yjsDoc.getElements(); + let count = 0; + elements.forEach(element => { + if (element.type === 'chair') { + count++; + } + }); + return count; } // Display capacity information @@ -52,14 +67,8 @@ class CapacityDisplayTool extends Tool { const totalCapacity = this.calculateTotalCapacity(); const selectedCapacity = this.calculateSelectedCapacity(); - // In a real implementation, this would update the UI to show capacity information - console.log(`Total capacity: ${totalCapacity} seats`); - if (selectedCapacity > 0) { - console.log(`Selected capacity: ${selectedCapacity} seats`); - } - - // In a real implementation, this would show a modal or update a panel in the UI - alert(`Total capacity: ${totalCapacity} seats${selectedCapacity > 0 ? `\nSelected capacity: ${selectedCapacity} seats` : ''}`); + // Update the UI through the callback + this.onCapacityUpdate(totalCapacity, selectedCapacity); } }