"use client"; import { useState, useEffect } from 'react'; import { useParams } from 'next/navigation'; import { DocumentSidebar } from '@/widgets/editor/sidebar/document-sidebar'; import { RichTextEditor } from '@/widgets/editor/editor/core/rich-text-editor'; import { Button } from '@/shared/ui/button'; import { ArrowLeft, Copy, Check, Share2, User, Calendar } from 'lucide-react'; import Link from 'next/link'; import type { Document } from '@/shared/types/document'; import { SharedDocumentSkeleton } from '@/shared/ui/skeleton'; interface SharedDocument extends Document { user: { name: string; email: string; }; } export default function ShareDocumentPage() { const params = useParams(); const documentId = params.id as string; const [document, setDocument] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchDocument = async () => { try { const response = await fetch(`/api/documents/${documentId}/public`); if (!response.ok) { throw new Error('Document not found or not published'); } const data = await response.json(); setDocument(data); } catch (err) { setError(err instanceof Error ? err.message : 'Failed to load document'); } finally { setLoading(false); } }; if (documentId) { fetchDocument(); } }, [documentId]); const getWordCount = (content: any): number => { if (!content) return 0; const extractText = (node: any): string => { if (typeof node === 'string') return node; if (node.text) return node.text; if (node.content) { return node.content.map(extractText).join(' '); } return ''; }; const text = extractText(content); return text.trim().split(/\s+/).filter(word => word.length > 0).length; }; if (loading) { return ; } if (error || !document) { return (
📄

Document Not Found

{error || 'This document may not exist or may not be publicly shared.'}

); } const wordCount = getWordCount(document.content); return (
{/* Main Content */}
{/* Document Content */}
{/* Sidebar */}
{/* Document Info */}

Document Info

Author: {document.user.name}
Created: {new Date(document.createdAt).toLocaleDateString()}
Updated: {new Date(document.updatedAt).toLocaleDateString()}
{/* Footer */}
); }