File size: 32,353 Bytes
80c8f26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CodeSearch AI - Programming Knowledge Engine</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <style>
        .code-container {
            background-color: #1e293b;
            border-radius: 0.5rem;
            padding: 1rem;
            position: relative;
        }
        .copy-btn {
            position: absolute;
            top: 0.5rem;
            right: 0.5rem;
            background-color: #3b82f6;
            color: white;
            border: none;
            border-radius: 0.25rem;
            padding: 0.25rem 0.5rem;
            cursor: pointer;
            font-size: 0.75rem;
        }
        .copy-btn:hover {
            background-color: #2563eb;
        }
        .knowledge-item {
            transition: all 0.2s ease;
        }
        .knowledge-item:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
        .tab-content {
            display: none;
        }
        .tab-content.active {
            display: block;
            animation: fadeIn 0.3s ease;
        }
        @keyframes fadeIn {
            from { opacity: 0; }
            to { opacity: 1; }
        }
        .search-box {
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }
        .result-card {
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body class="bg-gray-50 min-h-screen">
    <div class="container mx-auto px-4 py-8">
        <!-- Header -->
        <header class="mb-8 text-center">
            <h1 class="text-4xl font-bold text-blue-600 mb-2">CodeSearch AI</h1>
            <p class="text-gray-600">Your intelligent programming knowledge engine</p>
        </header>

        <!-- Main Content -->
        <div class="flex flex-col lg:flex-row gap-8">
            <!-- Search Section -->
            <div class="lg:w-2/3">
                <div class="search-box bg-white rounded-xl p-6 mb-6">
                    <div class="flex items-center mb-4">
                        <div class="w-full relative">
                            <input type="text" id="searchInput" placeholder="Ask anything about programming... (e.g. 'How to sort an array in JavaScript?' or 'What's the best way to handle user authentication?')" class="w-full px-4 py-3 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500">
                            <button id="searchBtn" class="absolute right-2 top-1/2 transform -translate-y-1/2 bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600 transition">
                                <i class="fas fa-search"></i> Search
                            </button>
                        </div>
                    </div>
                    <div class="flex flex-wrap gap-2 mb-4">
                        <span class="text-sm text-gray-500">Try:</span>
                        <button class="quick-query text-xs bg-gray-100 hover:bg-gray-200 px-3 py-1 rounded-full">array sorting methods</button>
                        <button class="quick-query text-xs bg-gray-100 hover:bg-gray-200 px-3 py-1 rounded-full">Python web frameworks</button>
                        <button class="quick-query text-xs bg-gray-100 hover:bg-gray-200 px-3 py-1 rounded-full">React hooks examples</button>
                        <button class="quick-query text-xs bg-gray-100 hover:bg-gray-200 px-3 py-1 rounded-full">SQL joins explained</button>
                    </div>
                </div>

                <!-- Results Section -->
                <div id="resultsContainer" class="space-y-6">
                    <!-- Sample result (will be populated by JavaScript) -->
                    <div class="result-card bg-white rounded-xl p-6 hidden" id="sampleResult">
                        <div class="flex justify-between items-start mb-4">
                            <h2 class="text-xl font-semibold text-gray-800">Result Title</h2>
                            <div class="flex gap-2">
                                <button class="simplify-btn text-xs bg-blue-100 text-blue-600 hover:bg-blue-200 px-3 py-1 rounded-full">
                                    <i class="fas fa-simplify mr-1"></i> Simplify
                                </button>
                                <button class="detail-btn text-xs bg-green-100 text-green-600 hover:bg-green-200 px-3 py-1 rounded-full">
                                    <i class="fas fa-info-circle mr-1"></i> Details
                                </button>
                                <button class="examples-btn text-xs bg-purple-100 text-purple-600 hover:bg-purple-200 px-3 py-1 rounded-full">
                                    <i class="fas fa-code mr-1"></i> Examples
                                </button>
                            </div>
                        </div>
                        
                        <div class="tab-content active" id="basicInfo">
                            <p class="text-gray-700 mb-4">Basic information about the concept...</p>
                        </div>
                        
                        <div class="tab-content" id="detailedInfo">
                            <div class="space-y-4">
                                <div>
                                    <h3 class="font-medium text-gray-800 mb-1">1. What it is</h3>
                                    <p class="text-gray-700">Detailed definition...</p>
                                </div>
                                <div>
                                    <h3 class="font-medium text-gray-800 mb-1">2. How it's used</h3>
                                    <p class="text-gray-700">Usage information...</p>
                                </div>
                                <div>
                                    <h3 class="font-medium text-gray-800 mb-1">3. Why it's important</h3>
                                    <p class="text-gray-700">Importance explanation...</p>
                                </div>
                                <div>
                                    <h3 class="font-medium text-gray-800 mb-1">4. When it's used</h3>
                                    <p class="text-gray-700">Hierarchy and relational info...</p>
                                </div>
                            </div>
                        </div>
                        
                        <div class="tab-content" id="examplesInfo">
                            <div class="space-y-4">
                                <div>
                                    <h3 class="font-medium text-gray-800 mb-2">Live Web Examples</h3>
                                    <div class="space-y-4">
                                        <div class="code-container">
                                            <button class="copy-btn"><i class="fas fa-copy mr-1"></i> Copy</button>
                                            <pre><code class="language-javascript text-white">// Example code will appear here</code></pre>
                                        </div>
                                        <div class="code-container">
                                            <button class="copy-btn"><i class="fas fa-copy mr-1"></i> Copy</button>
                                            <pre><code class="language-python text-white"># Another example in different language</code></pre>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div class="mt-4 flex justify-between items-center">
                            <div class="text-sm text-gray-500">
                                <span>Source: </span>
                                <span class="text-blue-500">MDN Web Docs</span>
                            </div>
                            <button class="send-it-btn bg-blue-500 hover:bg-blue-600 text-white px-4 py-2 rounded-lg flex items-center">
                                <i class="fas fa-paper-plane mr-2"></i> Send to My Codebase
                            </button>
                        </div>
                    </div>
                </div>
            </div>

            <!-- Knowledge Base Section -->
            <div class="lg:w-1/3">
                <div class="bg-white rounded-xl p-6 sticky top-4">
                    <div class="flex justify-between items-center mb-4">
                        <h2 class="text-xl font-semibold text-gray-800">My Codebase Knowledge</h2>
                        <button id="clearKnowledge" class="text-xs text-red-500 hover:text-red-700">
                            <i class="fas fa-trash-alt mr-1"></i> Clear All
                        </button>
                    </div>
                    
                    <div class="tabs flex border-b mb-4">
                        <button class="tab-btn active px-4 py-2 text-blue-600 border-b-2 border-blue-500">Saved Items</button>
                        <button class="tab-btn px-4 py-2 text-gray-500 hover:text-gray-700">History</button>
                    </div>
                    
                    <div id="knowledgeContent" class="space-y-4">
                        <div class="tab-content active" id="savedItems">
                            <div id="knowledgeList" class="space-y-3">
                                <!-- Sample knowledge item -->
                                <div class="knowledge-item bg-gray-50 p-4 rounded-lg border border-gray-200 cursor-pointer">
                                    <div class="flex justify-between items-start">
                                        <h3 class="font-medium text-gray-800">Array.prototype.map()</h3>
                                        <button class="delete-knowledge text-red-400 hover:text-red-600 text-xs">
                                            <i class="fas fa-times"></i>
                                        </button>
                                    </div>
                                    <p class="text-sm text-gray-600 mt-1">Asked: "How to transform array elements in JavaScript?"</p>
                                    <div class="mt-2 flex justify-between items-center">
                                        <span class="text-xs text-gray-500">Saved: 2 days ago</span>
                                        <button class="view-btn text-xs text-blue-500 hover:text-blue-700">
                                            <i class="fas fa-eye mr-1"></i> View
                                        </button>
                                    </div>
                                </div>
                            </div>
                            <p id="emptyKnowledge" class="text-center text-gray-500 py-4 hidden">Your knowledge base is empty. Save items from search results to build your personal library.</p>
                        </div>
                        
                        <div class="tab-content" id="historyItems">
                            <div id="historyList" class="space-y-3">
                                <!-- Sample history item -->
                                <div class="knowledge-item bg-gray-50 p-4 rounded-lg border border-gray-200 cursor-pointer">
                                    <h3 class="font-medium text-gray-800">Promise.all()</h3>
                                    <p class="text-sm text-gray-600 mt-1">Searched: "How to handle multiple promises in JavaScript?"</p>
                                    <div class="mt-2 flex justify-between items-center">
                                        <span class="text-xs text-gray-500">2 hours ago</span>
                                        <button class="save-btn text-xs text-green-500 hover:text-green-700">
                                            <i class="fas fa-save mr-1"></i> Save
                                        </button>
                                    </div>
                                </div>
                            </div>
                            <p id="emptyHistory" class="text-center text-gray-500 py-4 hidden">Your search history is empty.</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // Tab functionality
            const tabButtons = document.querySelectorAll('.tab-btn');
            tabButtons.forEach(button => {
                button.addEventListener('click', () => {
                    const tabType = button.textContent.trim();
                    tabButtons.forEach(btn => btn.classList.remove('active', 'text-blue-600', 'border-blue-500'));
                    button.classList.add('active', 'text-blue-600', 'border-blue-500');
                    
                    // Show corresponding content
                    if (tabType === 'Saved Items') {
                        document.querySelector('#savedItems').classList.add('active');
                        document.querySelector('#historyItems').classList.remove('active');
                    } else {
                        document.querySelector('#historyItems').classList.add('active');
                        document.querySelector('#savedItems').classList.remove('active');
                    }
                });
            });

            // Result tab functionality
            function setupResultTabs(resultElement) {
                const simplifyBtn = resultElement.querySelector('.simplify-btn');
                const detailBtn = resultElement.querySelector('.detail-btn');
                const examplesBtn = resultElement.querySelector('.examples-btn');
                
                const basicInfo = resultElement.querySelector('#basicInfo');
                const detailedInfo = resultElement.querySelector('#detailedInfo');
                const examplesInfo = resultElement.querySelector('#examplesInfo');
                
                simplifyBtn.addEventListener('click', () => {
                    [basicInfo, detailedInfo, examplesInfo].forEach(tab => tab.classList.remove('active'));
                    basicInfo.classList.add('active');
                });
                
                detailBtn.addEventListener('click', () => {
                    [basicInfo, detailedInfo, examplesInfo].forEach(tab => tab.classList.remove('active'));
                    detailedInfo.classList.add('active');
                });
                
                examplesBtn.addEventListener('click', () => {
                    [basicInfo, detailedInfo, examplesInfo].forEach(tab => tab.classList.remove('active'));
                    examplesInfo.classList.add('active');
                });
                
                // Copy button functionality
                const copyButtons = resultElement.querySelectorAll('.copy-btn');
                copyButtons.forEach(button => {
                    button.addEventListener('click', () => {
                        const codeBlock = button.parentElement.querySelector('code');
                        navigator.clipboard.writeText(codeBlock.textContent);
                        button.innerHTML = '<i class="fas fa-check mr-1"></i> Copied!';
                        setTimeout(() => {
                            button.innerHTML = '<i class="fas fa-copy mr-1"></i> Copy';
                        }, 2000);
                    });
                });
                
                // Send to codebase button
                const sendItBtn = resultElement.querySelector('.send-it-btn');
                sendItBtn.addEventListener('click', () => {
                    // In a real app, this would save to local storage or a database
                    alert('This item has been added to your codebase knowledge!');
                    addToKnowledgeBase(resultElement);
                });
            }

            // Quick query buttons
            document.querySelectorAll('.quick-query').forEach(button => {
                button.addEventListener('click', () => {
                    document.getElementById('searchInput').value = button.textContent;
                    performSearch(button.textContent);
                });
            });

            // Search functionality
            document.getElementById('searchBtn').addEventListener('click', () => {
                const query = document.getElementById('searchInput').value.trim();
                if (query) {
                    performSearch(query);
                }
            });

            // Also trigger search on Enter key
            document.getElementById('searchInput').addEventListener('keypress', (e) => {
                if (e.key === 'Enter') {
                    const query = document.getElementById('searchInput').value.trim();
                    if (query) {
                        performSearch(query);
                    }
                }
            });

            // Clear knowledge base
            document.getElementById('clearKnowledge').addEventListener('click', () => {
                if (confirm('Are you sure you want to clear your entire knowledge base?')) {
                    document.getElementById('knowledgeList').innerHTML = '';
                    document.getElementById('emptyKnowledge').classList.remove('hidden');
                }
            });

            // Sample data for demonstration
            const sampleData = {
                "array sorting methods": {
                    title: "Array Sorting Methods",
                    basic: "Array sorting methods allow you to order elements in an array based on specific criteria.",
                    details: {
                        what: "Array sorting refers to the process of arranging elements in an array in a particular order (ascending, descending, or based on custom criteria).",
                        how: "In JavaScript, arrays have a built-in sort() method. Other languages like Python use sorted() function or list.sort() method.",
                        why: "Sorting is fundamental for efficient data retrieval, presentation, and many algorithms rely on sorted data.",
                        when: "Used when you need ordered data for display, searching (binary search), or when preparing data for algorithms that require sorted input."
                    },
                    examples: [
                        {
                            language: "JavaScript",
                            code: "// Basic sort\nconst numbers = [3, 1, 4, 1, 5, 9];\nnumbers.sort((a, b) => a - b); // [1, 1, 3, 4, 5, 9]\n\n// Sort objects\nconst users = [{name: 'John', age: 30}, {name: 'Jane', age: 25}];\nusers.sort((a, b) => a.age - b.age); // Sorted by age"
                        },
                        {
                            language: "Python",
                            code: "# Basic sort\nnumbers = [3, 1, 4, 1, 5, 9]\nsorted_numbers = sorted(numbers)  # [1, 1, 3, 4, 5, 9]\n\n# Sort with key\nusers = [{'name': 'John', 'age': 30}, {'name': 'Jane', 'age': 25}]\nsorted_users = sorted(users, key=lambda x: x['age'])"
                        }
                    ],
                    source: "MDN Web Docs, Python Documentation"
                },
                "Python web frameworks": {
                    title: "Python Web Frameworks",
                    basic: "Python offers several web frameworks for building web applications of varying complexity.",
                    details: {
                        what: "Python web frameworks are collections of modules that help developers build web applications faster by providing common functionality.",
                        how: "Popular frameworks include Django (batteries-included), Flask (microframework), FastAPI (async), and Pyramid. They're used by importing their modules and following their patterns.",
                        why: "Frameworks handle common tasks (routing, templating, DB interaction) so developers can focus on application logic.",
                        when: "Used when building web applications, APIs, or any HTTP-based service in Python. Choice depends on project size and requirements."
                    },
                    examples: [
                        {
                            language: "Python (Flask)",
                            code: "from flask import Flask\napp = Flask(__name__)\n\n@app.route('/')\ndef hello():\n    return 'Hello, World!'\n\nif __name__ == '__main__':\n    app.run()"
                        },
                        {
                            language: "Python (Django)",
                            code: "# Django view example\nfrom django.http import HttpResponse\nfrom django.shortcuts import render\n\ndef index(request):\n    return HttpResponse('Hello, World!')\n\n# In urls.py\nfrom django.urls import path\nfrom . import views\n\nurlpatterns = [\n    path('', views.index, name='index'),\n]"
                        }
                    ],
                    source: "Flask Documentation, Django Documentation"
                }
            };

            function performSearch(query) {
                const resultsContainer = document.getElementById('resultsContainer');
                resultsContainer.innerHTML = '';
                
                // Show loading
                const loadingDiv = document.createElement('div');
                loadingDiv.className = 'text-center py-8';
                loadingDiv.innerHTML = '<i class="fas fa-spinner fa-spin text-3xl text-blue-500"></i><p class="mt-2 text-gray-600">Analyzing your query...</p>';
                resultsContainer.appendChild(loadingDiv);
                
                // Simulate API call with timeout
                setTimeout(() => {
                    resultsContainer.innerHTML = '';
                    
                    // Check if we have sample data for this query
                    const lowerQuery = query.toLowerCase();
                    let resultData = null;
                    
                    for (const key in sampleData) {
                        if (lowerQuery.includes(key)) {
                            resultData = sampleData[key];
                            break;
                        }
                    }
                    
                    if (!resultData) {
                        // Default response if no sample data matches
                        resultData = {
                            title: "Understanding Your Query",
                            basic: "I've analyzed your query about '" + query + "'. While I don't have a specific response for this exact question, here's how I would typically structure information about programming concepts.",
                            details: {
                                what: "A programming concept would be defined here, explaining its purpose and functionality.",
                                how: "This section would detail how to implement or use the concept, including language specifics.",
                                why: "Here we'd explain the importance and problems this concept solves.",
                                when: "This part would describe typical use cases and architectural placement."
                            },
                            examples: [
                                {
                                    language: "JavaScript",
                                    code: "// Example code would appear here\nfunction example() {\n  console.log('This is a sample implementation');\n}"
                                },
                                {
                                    language: "Python",
                                    code: "# Another example in a different language\ndef example():\n    print('This is a sample implementation')"
                                }
                            ],
                            source: "General Programming Knowledge"
                        };
                    }
                    
                    // Clone the sample result template
                    const resultElement = document.getElementById('sampleResult').cloneNode(true);
                    resultElement.classList.remove('hidden');
                    
                    // Populate with data
                    resultElement.querySelector('h2').textContent = resultData.title;
                    resultElement.querySelector('#basicInfo p').textContent = resultData.basic;
                    
                    const detailedInfo = resultElement.querySelector('#detailedInfo');
                    detailedInfo.querySelector('div:nth-child(1) p').textContent = resultData.details.what;
                    detailedInfo.querySelector('div:nth-child(2) p').textContent = resultData.details.how;
                    detailedInfo.querySelector('div:nth-child(3) p').textContent = resultData.details.why;
                    detailedInfo.querySelector('div:nth-child(4) p').textContent = resultData.details.when;
                    
                    const examplesContainer = resultElement.querySelector('#examplesInfo .space-y-4');
                    examplesContainer.innerHTML = '<h3 class="font-medium text-gray-800 mb-2">Live Web Examples</h3><div class="space-y-4">';
                    
                    resultData.examples.forEach((example, index) => {
                        examplesContainer.innerHTML += `
                            <div class="code-container">
                                <button class="copy-btn"><i class="fas fa-copy mr-1"></i> Copy</button>
                                <pre><code class="language-${example.language.toLowerCase()} text-white">${example.code}</code></pre>
                                <div class="text-xs text-gray-400 mt-1">${example.language} Example ${index + 1}</div>
                            </div>
                        `;
                    });
                    
                    examplesContainer.innerHTML += '</div>';
                    resultElement.querySelector('.text-blue-500').textContent = resultData.source;
                    
                    // Set up the tabs and buttons for this result
                    setupResultTabs(resultElement);
                    
                    // Add to results container
                    resultsContainer.appendChild(resultElement);
                    
                    // Add to history
                    addToHistory(query, resultData.title);
                    
                }, 1500);
            }

            // Knowledge base functionality
            function addToKnowledgeBase(resultElement) {
                const title = resultElement.querySelector('h2').textContent;
                const query = document.getElementById('searchInput').value.trim();
                
                const knowledgeList = document.getElementById('knowledgeList');
                const emptyKnowledge = document.getElementById('emptyKnowledge');
                
                // Create new knowledge item
                const knowledgeItem = document.createElement('div');
                knowledgeItem.className = 'knowledge-item bg-gray-50 p-4 rounded-lg border border-gray-200 cursor-pointer';
                knowledgeItem.innerHTML = `
                    <div class="flex justify-between items-start">
                        <h3 class="font-medium text-gray-800">${title}</h3>
                        <button class="delete-knowledge text-red-400 hover:text-red-600 text-xs">
                            <i class="fas fa-times"></i>
                        </button>
                    </div>
                    <p class="text-sm text-gray-600 mt-1">Asked: "${query}"</p>
                    <div class="mt-2 flex justify-between items-center">
                        <span class="text-xs text-gray-500">Saved: Just now</span>
                        <button class="view-btn text-xs text-blue-500 hover:text-blue-700">
                            <i class="fas fa-eye mr-1"></i> View
                        </button>
                    </div>
                `;
                
                // Add delete functionality
                knowledgeItem.querySelector('.delete-knowledge').addEventListener('click', (e) => {
                    e.stopPropagation();
                    knowledgeItem.remove();
                    if (knowledgeList.children.length === 0) {
                        emptyKnowledge.classList.remove('hidden');
                    }
                });
                
                // Add view functionality
                knowledgeItem.querySelector('.view-btn').addEventListener('click', () => {
                    // In a real app, this would show the full saved result
                    alert('Viewing saved item: ' + title);
                });
                
                // Add to knowledge list
                knowledgeList.prepend(knowledgeItem);
                emptyKnowledge.classList.add('hidden');
            }

            // History functionality
            function addToHistory(query, title) {
                const historyList = document.getElementById('historyList');
                const emptyHistory = document.getElementById('emptyHistory');
                
                // Create new history item
                const historyItem = document.createElement('div');
                historyItem.className = 'knowledge-item bg-gray-50 p-4 rounded-lg border border-gray-200 cursor-pointer';
                historyItem.innerHTML = `
                    <h3 class="font-medium text-gray-800">${title}</h3>
                    <p class="text-sm text-gray-600 mt-1">Searched: "${query}"</p>
                    <div class="mt-2 flex justify-between items-center">
                        <span class="text-xs text-gray-500">Just now</span>
                        <button class="save-btn text-xs text-green-500 hover:text-green-700">
                            <i class="fas fa-save mr-1"></i> Save
                        </button>
                    </div>
                `;
                
                // Add save functionality
                historyItem.querySelector('.save-btn').addEventListener('click', () => {
                    // In a real app, this would save to knowledge base
                    alert('Saved to knowledge base: ' + title);
                });
                
                // Add to history list
                historyList.prepend(historyItem);
                emptyHistory.classList.add('hidden');
            }

            // Initialize with some sample knowledge if empty
            if (document.getElementById('knowledgeList').children.length === 0) {
                document.getElementById('emptyKnowledge').classList.remove('hidden');
            }
            if (document.getElementById('historyList').children.length === 0) {
                document.getElementById('emptyHistory').classList.remove('hidden');
            }
        });
    </script>
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Its3sticks/codesearch" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
</html>