// Utility functions
export function generateId() {
    return `upload_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
}
export function formatFileSize(bytes) {
    if (bytes === 0)
        return "0 Bytes";
    const k = 1024;
    const sizes = ["Bytes", "KB", "MB", "GB"];
    const i = Math.floor(Math.log(bytes) / Math.log(k));
    return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
}
export function mapProgressStageToStatus(stage) {
    switch (stage) {
        case "loading":
        case "initializing":
            return "pending";
        case "uploading":
            return "uploading";
        case "complete":
            return "success";
        case "failed":
            return "failed";
        case "conflict":
            return "conflict";
        case "unsupported-document-type":
            return "unsupported-document-type";
        default:
            return "pending";
    }
}
export function mapUploadsToFileItems(uploadsArray, removeUpload, setSelectedNodeFn, onConflictResolution) {
    return uploadsArray
        .filter((upload) => upload !== undefined)
        .map((upload) => ({
        fileName: upload.fileName,
        fileSize: upload.fileSize,
        status: upload.status,
        progress: upload.progress,
        errorDetails: upload.errorDetails,
        documentType: upload.documentType,
        onClose: () => {
            removeUpload(upload.id);
        },
        onOpenDocument: upload.status === "success"
            ? () => {
                if (upload.fileNode && setSelectedNodeFn) {
                    setSelectedNodeFn(upload.fileNode);
                }
                else {
                    console.error("Opening document for upload:", upload.id, "- fileNode not available or setSelectedNode not provided");
                }
            }
            : undefined,
        onFindResolution: upload.status === "failed"
            ? () => {
                console.log("Finding resolution for upload:", upload.id);
            }
            : upload.status === "conflict"
                ? () => {
                    console.log("Finding conflict resolution for upload:", upload.id);
                    onConflictResolution?.(upload.id);
                }
                : undefined,
    }));
}
//# sourceMappingURL=utils.js.map