import { Injectable, signal, computed } from '@angular/core'; export interface Comment { id: string; blockId: string; author: string; text: string; createdAt: Date; resolved?: boolean; } @Injectable({ providedIn: 'root' }) export class CommentService { private comments = signal([]); /** * Get all comments for a specific block */ getCommentsForBlock(blockId: string): Comment[] { return this.comments().filter(c => c.blockId === blockId); } /** * Get comment count for a specific block */ getCommentCount(blockId: string): number { return this.comments().filter(c => c.blockId === blockId && !c.resolved).length; } /** * Add a comment to a block */ addComment(blockId: string, text: string, author: string = 'User'): void { const newComment: Comment = { id: this.generateId(), blockId, author, text, createdAt: new Date() }; this.comments.update(comments => [...comments, newComment]); } /** * Delete a comment */ deleteComment(commentId: string): void { this.comments.update(comments => comments.filter(c => c.id !== commentId)); } /** * Mark comment as resolved */ resolveComment(commentId: string): void { this.comments.update(comments => comments.map(c => c.id === commentId ? { ...c, resolved: true } : c) ); } /** * Get all comments */ getAllComments(): Comment[] { return this.comments(); } private generateId(): string { return Math.random().toString(36).substring(2, 11); } /** * Add test comments to specific blocks (for demo purposes) */ addTestComments(blockIds: string[]): void { blockIds.forEach((blockId, index) => { // Add 1-3 random comments per block const commentCount = Math.floor(Math.random() * 3) + 1; for (let i = 0; i < commentCount; i++) { this.addComment( blockId, `Test comment ${i + 1} for block`, `User ${index + 1}` ); } }); } }