"use client"; import React, { useState } from 'react'; interface TreeNodeData { name: string; path: string; type: "folder" | "file"; // Specific values for 'type' totalSize: number; subfolderCount: number; fileCount: number; children?: TreeNodeData[]; } interface TreeNodeProps { node: TreeNodeData; rootSize: number; } function beautifyBytes(bytes: number): string { if (bytes === 0) return "0 Bytes"; const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"]; const i = Math.floor(Math.log(bytes) / Math.log(1024)); const readableSize = (bytes / Math.pow(1024, i)).toFixed(2); return `${readableSize} ${sizes[i]}`; } const TreeNode: React.FC = ({ node, rootSize }) => { const [isExpanded, setIsExpanded] = useState(false); const toggleExpand = () => { setIsExpanded(!isExpanded); }; const percentage = (node.totalSize / rootSize) * 100; return (
{node.path} Subfolders: {node.subfolderCount} Files: {node.fileCount} Size: {beautifyBytes(node.totalSize)}
70 ? 'red' : percentage > 40 ? 'yellow' : ''}`} style={{ width: `${percentage}%` }} >
{isExpanded && node.children && (
{node.children.map((child) => ( ))}
)}
); }; export default TreeNode;