import { ffid } from "../../../utils/ffID/ffid";
const useNode = () => {
    const insertNode = (tree, commentId, item) => {
        return tree.map((node) => {
            if (node.id === commentId) {
                return {
                    ...node,
                    comments: [
                        ...node.comments,
                        {
                            id: ffid(),
                            description: item.description,
                            comments: [],
                            createdBy: node.createdBy,
                            modifiedBy: node.modifiedBy,
                            createdByUname: node.createdByUname,
                            modifiedByUname: node.modifiedByUname,
                            createdOn: new Date().toLocaleString(),
                            modifiedOn: new Date().toLocaleString(),
                            commentParentId: commentId,
                        },
                    ],
                };
            }
            return {
                ...node,
                comments: insertNode(node.comments, commentId, item),
            };
        });
    };
    const editNode = (tree, commentId, value) => {
        return tree.map((node) => ({
            ...node,
            description: node.id === commentId ? value : node.description,
            comments: editNode(node.comments, commentId, value),
        }));
    };
    const deleteNode = (tree, commentId) => {
        return tree
            .filter((node) => node.id !== commentId)
            .map((node) => ({
            ...node,
            comments: deleteNode(node.comments, commentId),
        }));
    };
    return { insertNode, editNode, deleteNode };
};
export default useNode;
//# sourceMappingURL=useNode.js.map