File size: 12,084 Bytes
f6df39b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
"""
Document Viewer UI - Gradio interface for document preview and download
Shows generated documents with full preview and download capabilities
"""

import os
from typing import Tuple, List, Optional, Dict, Any
import json
from pathlib import Path
import logging

logger = logging.getLogger(__name__)


def create_document_preview_section(
    doc_id: str,
    title: str,
    preview_text: str,
    available_formats: List[str],
    file_sizes: Dict[str, float]
) -> str:
    """
    Create a formatted document preview section.

    Args:
        doc_id: Document ID
        title: Document title
        preview_text: Preview of document content
        available_formats: List of available formats
        file_sizes: Dict of format -> size in MB

    Returns:
        Formatted preview text
    """
    preview = f"""
╔════════════════════════════════════════════════════════════════╗
β•‘                    πŸ“„ DOCUMENT PREVIEW                         β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

πŸ“‹ DOCUMENT: {title}
πŸ†” ID: {doc_id}

πŸ“ PREVIEW CONTENT:
{'─' * 65}
{preview_text[:800]}
{'...' if len(preview_text) > 800 else ''}
{'─' * 65}

πŸ“₯ DOWNLOAD OPTIONS:
"""

    for fmt in available_formats:
        size = file_sizes.get(fmt, 0)
        preview += f"  βœ“ {fmt:12} ({size:.2f} MB)\n"

    preview += f"""
{'─' * 65}

πŸ’‘ TIP: You can download in any format above.
   They all contain the same content!
"""

    return preview


def create_full_document_viewer(
    doc_id: str,
    title: str,
    full_content: str,
    available_formats: List[str],
    file_paths: Dict[str, str]
) -> Tuple[str, str, str]:
    """
    Create a full document viewer interface.

    Args:
        doc_id: Document ID
        title: Document title
        full_content: Full document content
        available_formats: List of available formats
        file_paths: Dict of format -> file path

    Returns:
        Tuple of (content_view, download_info, status)
    """
    # Create content view
    content_view = f"""
╔════════════════════════════════════════════════════════════════╗
β•‘                    πŸ“– FULL DOCUMENT VIEW                       β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

πŸ“„ {title}

{full_content}
"""

    # Create download info
    download_info = f"""
πŸ“₯ DOWNLOAD THIS DOCUMENT

Available Formats:
"""

    for fmt in available_formats:
        if fmt in file_paths:
            size_mb = os.path.getsize(file_paths[fmt]) / (1024 * 1024)
            download_info += f"  {fmt}: {size_mb:.2f} MB\n"

    download_info += f"""

Document ID: {doc_id}
Share this ID to allow others to access your document!
"""

    # Create status
    status = f"βœ… Document ready for download. {len(available_formats)} formats available."

    return content_view, download_info, status


def format_download_instructions(doc_id: str, formats: List[str]) -> str:
    """Format download instructions for users."""
    return f"""
πŸŽ‰ YOUR DOCUMENT IS READY!

πŸ“„ Document ID: {doc_id}

πŸ“₯ DOWNLOAD OPTIONS:
{chr(10).join(f"  βœ“ {fmt}" for fmt in formats)}

HOW TO ACCESS:
  1. Click on any format above to download
  2. Or copy the Document ID and share it with others
  3. Use "View Document" tab to see full content
  4. Use "Download" section to get files

πŸ’Ύ All formats contain identical content - choose what you need!
"""


def create_document_info_card(
    doc_id: str,
    title: str,
    doc_type: str,
    word_count: int,
    quality_score: int,
    formats_available: List[str],
    file_sizes: Dict[str, float]
) -> str:
    """
    Create an information card about the document.

    Args:
        doc_id: Document ID
        title: Document title
        doc_type: Type of document
        word_count: Word count
        quality_score: Quality score (0-100)
        formats_available: Available formats
        file_sizes: File sizes in MB

    Returns:
        Formatted info card
    """
    quality_bar = "β–ˆ" * (quality_score // 10) + "β–‘" * (10 - quality_score // 10)

    card = f"""
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                  πŸ“Š DOCUMENT INFORMATION               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Title:        {title[:45]:45} β”‚
β”‚ ID:           {doc_id[:45]:45} β”‚
β”‚ Type:         {doc_type[:45]:45} β”‚
β”‚ Word Count:   {str(word_count)[:45]:45} β”‚
β”‚ Quality:      [{quality_bar}] {quality_score}%       β”‚
β”‚ Formats:      {', '.join(formats_available[:2])[:35]}... β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
"""

    card += "β”‚ FILE SIZES:                                            β”‚\n"
    for fmt, size in file_sizes.items():
        card += f"β”‚   {fmt:12} {size:8.2f} MB                            β”‚\n"

    card += "β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜\n"

    return card


def create_tabbed_document_view(
    doc_id: str,
    title: str,
    content: str,
    formats: List[str],
    file_paths: Dict[str, str],
    metadata: Dict[str, Any]
) -> Tuple[str, str, str, str]:
    """
    Create a multi-tabbed document view interface.

    Returns:
        Tuple of (overview, content, download, metadata_view)
    """
    # Overview tab
    word_count = metadata.get("word_count", 0)
    quality = metadata.get("quality_score", 0)
    reading_time = metadata.get("reading_time", 0)

    overview = f"""
{'═' * 60}
πŸ“„ DOCUMENT OVERVIEW
{'═' * 60}

Title: {title}
Document ID: {doc_id}

πŸ“Š STATISTICS:
  β€’ Word Count: {word_count:,} words
  β€’ Quality Score: {quality}%
  β€’ Estimated Reading Time: {reading_time} minutes
  β€’ Available Formats: {len(formats)}

πŸ”— DOWNLOAD: Choose a format below
πŸ” VIEW: Check the "Content" tab for full document
πŸ“‹ INFO: See metadata in the "Info" tab
"""

    # Content tab
    content_view = f"""
{'═' * 60}
πŸ“– {title}
{'═' * 60}

{content}

{'═' * 60}
End of document
"""

    # Download tab
    download_view = f"""
{'═' * 60}
πŸ“₯ DOWNLOAD OPTIONS
{'═' * 60}

Document: {title}
ID: {doc_id}

AVAILABLE FORMATS:
"""

    for fmt in formats:
        if fmt in file_paths:
            size_mb = os.path.getsize(file_paths[fmt]) / (1024 * 1024)
            download_view += f"\nβœ“ {fmt}\n  Size: {size_mb:.2f} MB\n  [Click to download above]\n"

    download_view += f"""

All formats contain the same content.
Choose based on your preference:
  β€’ PDF: Best for sharing and printing
  β€’ Word: Best for editing
  β€’ Markdown: Best for version control
  β€’ HTML: Best for web viewing
"""

    # Metadata tab
    metadata_view = f"""
{'═' * 60}
ℹ️ DOCUMENT METADATA
{'═' * 60}

{json.dumps(metadata, indent=2, default=str)}
"""

    return overview, content_view, download_view, metadata_view


def create_quick_download_html(doc_id: str, formats: List[str]) -> str:
    """Create quick download HTML with buttons."""
    html = f"""
    <div style="padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); 
                border-radius: 10px; color: white; text-align: center;">
        <h2 style="margin-top: 0;">βœ… Document Generated Successfully!</h2>
        <p style="font-size: 18px; margin: 10px 0;">
            Download your document now:
        </p>
        <div style="display: flex; gap: 15px; justify-content: center; flex-wrap: wrap; margin-top: 20px;">
    """

    format_icons = {
        "PDF": "πŸ“„",
        "WORD": "πŸ“",
        "MARKDOWN": "πŸ“‹",
        "HTML": "🌐",
        "LATEX": "πŸ“"
    }

    for fmt in formats:
        icon = format_icons.get(fmt.upper(), "πŸ“₯")
        html += f"""
            <div style="background: rgba(255,255,255,0.2); padding: 15px 20px; 
                       border-radius: 8px; cursor: pointer; transition: all 0.3s;
                       border: 2px solid transparent;">
                <div style="font-size: 24px;">{icon}</div>
                <div style="font-weight: bold; margin-top: 5px;">{fmt}</div>
                <div style="font-size: 12px; margin-top: 3px;">Document ID: {doc_id}</div>
            </div>
        """

    html += """
        </div>
        <div style="margin-top: 20px; padding-top: 15px; border-top: 1px solid rgba(255,255,255,0.3);">
            <p style="margin: 0; font-size: 14px;">
                πŸ’‘ Tip: All formats contain the same content. Choose what works best for you!
            </p>
        </div>
    </div>
    """

    return html


def get_document_view_instructions() -> str:
    """Get instructions for viewing documents."""
    return """
### πŸ“₯ View & Download Generated Documents

Your documents are automatically saved and available for download in multiple formats.

#### πŸ“‹ How to Access Your Documents:

1. **Immediate Download** - Download links appear right after generation
2. **Document ID** - Use the document ID to access it later
3. **Multiple Formats** - Choose the format that works best for you
4. **Preview** - View content before downloading

#### πŸ“‚ Available Formats:

- **PDF** πŸ“„ - Professional format, great for sharing and printing
- **Word** πŸ“ - Editable format (DOCX), perfect for further editing
- **Markdown** πŸ“‹ - Plain text format, great for version control
- **HTML** 🌐 - Web format, view in any browser
- **LaTeX** πŸ“ - Scientific format for academic papers

#### πŸ’Ύ Where Files Are Stored:

- All generated documents are saved in the `generated_documents/` folder
- Files are named after your document title
- Each format is saved separately but contains identical content

#### πŸ”— Sharing Documents:

- Use the **Document ID** to share with others
- Recipients can access the preview and download options
- All files are stored locally for privacy

#### βš™οΈ Technical Info:

- Document ID: Unique identifier for your document
- File Size: Varies by format (HTML usually smallest, PDF largest)
- Quality Score: Indicates content quality (0-100%)
- Word Count: Total words in the document
"""


def create_access_history_display(documents: Dict[str, Dict[str, Any]]) -> str:
    """Create a display of document access history."""
    if not documents:
        return "No documents generated yet."

    display = """
╔════════════════════════════════════════════════════════════════╗
β•‘                    πŸ“œ YOUR DOCUMENTS                           β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

"""

    for i, (doc_id, info) in enumerate(documents.items(), 1):
        display += f"""
{i}. {info.get('title', 'Untitled')}
   πŸ“† Created: {info.get('created_at', 'Unknown')}
   πŸ†” ID: {doc_id}
   πŸ“Š Formats: {', '.join(info.get('file_paths', {}).keys())}
   πŸ‘οΈ  Accessed: {info.get('access_count', 0)} times

"""

    return display