File size: 11,273 Bytes
e27c7f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b24ee0
e27c7f2
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
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>مساعد الذكاء الاصطناعي</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>
        /* Custom scrollbar */
        .custom-scrollbar::-webkit-scrollbar {
            width: 6px;
        }
        .custom-scrollbar::-webkit-scrollbar-track {
            background: #f1f1f1;
        }
        .custom-scrollbar::-webkit-scrollbar-thumb {
            background: #888;
            border-radius: 3px;
        }
        .custom-scrollbar::-webkit-scrollbar-thumb:hover {
            background: #555;
        }
        
        /* Chat bubble animation */
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }
        .chat-message {
            animation: fadeIn 0.3s ease-out;
        }
        
        /* Typing indicator animation */
        @keyframes blink {
            0%, 100% { opacity: 1; }
            50% { opacity: 0.5; }
        }
        .typing-dot {
            animation: blink 1.5s infinite;
        }
        .typing-dot:nth-child(2) {
            animation-delay: 0.2s;
        }
        .typing-dot:nth-child(3) {
            animation-delay: 0.4s;
        }
    </style>
</head>
<body class="bg-gray-50 h-screen flex flex-col">
    <!-- Header -->
    <header class="bg-white shadow-sm py-3 px-4 flex items-center justify-between">
        <div class="flex items-center space-x-2">
            <div class="w-8 h-8 rounded-full bg-gradient-to-r from-purple-500 to-blue-500 flex items-center justify-center text-white font-bold">AI</div>
            <h1 class="text-lg font-semibold text-gray-800">مساعد الذكاء الاصطناعي</h1>
        </div>
        <div class="flex items-center space-x-3">
            <button class="p-2 rounded-full hover:bg-gray-100 text-gray-600">
                <i class="fas fa-ellipsis-vertical"></i>
            </button>
        </div>
    </header>

    <!-- Chat container -->
    <div class="flex-1 overflow-hidden flex flex-col">
        <!-- Chat messages -->
        <div id="chat-messages" class="flex-1 overflow-y-auto custom-scrollbar p-4 space-y-4 rtl">
            <!-- Welcome message -->
            <div class="chat-message">
                <div class="flex items-start">
                    <div class="w-8 h-8 rounded-full bg-gradient-to-r from-purple-500 to-blue-500 flex items-center justify-center text-white font-bold ml-3">AI</div>
                    <div class="flex-1">
                        <div class="bg-white p-4 rounded-lg shadow-sm max-w-3xl">
                            <p class="text-gray-800">مرحبًا! أنا مساعدك الذكي. كيف يمكنني مساعدتك اليوم؟</p>
                            <div class="mt-2 flex flex-wrap gap-2">
                                <button class="suggestion-btn text-xs bg-gray-100 hover:bg-gray-200 text-gray-700 px-3 py-1 rounded-full transition">اقترح وصفة طعام</button>
                                <button class="suggestion-btn text-xs bg-gray-100 hover:bg-gray-200 text-gray-700 px-3 py-1 rounded-full transition">اشرح لي الذكاء الاصطناعي</button>
                                <button class="suggestion-btn text-xs bg-gray-100 hover:bg-gray-200 text-gray-700 px-3 py-1 rounded-full transition">ساعدني في البرمجة</button>
                            </div>
                        </div>
                        <div class="text-xs text-gray-500 mt-1 mr-1">اليوم على الساعة <span id="current-time"></span></div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Typing indicator (hidden by default) -->
        <div id="typing-indicator" class="hidden px-4 pb-3">
            <div class="flex items-start">
                <div class="w-8 h-8 rounded-full bg-gradient-to-r from-purple-500 to-blue-500 flex items-center justify-center text-white font-bold ml-3">AI</div>
                <div class="bg-white p-3 rounded-lg shadow-sm">
                    <div class="flex space-x-1">
                        <div class="typing-dot w-2 h-2 bg-gray-400 rounded-full"></div>
                        <div class="typing-dot w-2 h-2 bg-gray-400 rounded-full"></div>
                        <div class="typing-dot w-2 h-2 bg-gray-400 rounded-full"></div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Input area -->
        <div class="border-t border-gray-200 bg-white p-3">
            <form id="chat-form" class="flex items-end space-x-2">
                <button type="submit" id="send-button" class="w-10 h-10 rounded-full bg-gradient-to-r from-purple-500 to-blue-500 text-white flex items-center justify-center hover:opacity-90 transition disabled:opacity-50" disabled>
                    <i class="fas fa-paper-plane"></i>
                </button>
                <div class="flex-1 bg-gray-100 rounded-lg flex items-end">
                    <textarea id="message-input" rows="1" placeholder="اكتب رسالتك هنا..." class="flex-1 bg-transparent p-3 max-h-32 resize-none outline-none text-gray-700 rtl"></textarea>
                    <button type="button" class="p-2 text-gray-500 hover:text-gray-700">
                        <i class="fas fa-paperclip"></i>
                    </button>
                </div>
            </form>
            <p class="text-xs text-gray-500 mt-2 text-center">قد يقدم المساعد معلومات غير دقيقة عن الأشخاص، الأماكن أو الحقائق.</p>
        </div>
    </div>

    <script>
        // Set current time
        const now = new Date();
        const timeString = now.toLocaleTimeString('ar-EG', { hour: '2-digit', minute: '2-digit' });
        document.getElementById('current-time').textContent = timeString;

        // Auto-resize textarea
        const textarea = document.getElementById('message-input');
        textarea.addEventListener('input', function() {
            this.style.height = 'auto';
            this.style.height = (this.scrollHeight) + 'px';
            
            // Enable/disable send button
            document.getElementById('send-button').disabled = this.value.trim() === '';
        });

        // Handle form submission
        const chatForm = document.getElementById('chat-form');
        const chatMessages = document.getElementById('chat-messages');
        
        chatForm.addEventListener('submit', function(e) {
            e.preventDefault();
            const message = textarea.value.trim();
            if (message === '') return;
            
            // Add user message
            addMessage(message, 'user');
            textarea.value = '';
            textarea.style.height = 'auto';
            document.getElementById('send-button').disabled = true;
            
            // Show typing indicator
            document.getElementById('typing-indicator').classList.remove('hidden');
            chatMessages.scrollTop = chatMessages.scrollHeight;
            
            // Simulate AI response after a delay
            setTimeout(() => {
                document.getElementById('typing-indicator').classList.add('hidden');
                const responses = [
                    `أنا أفهم سؤالك حول "${message}". اسمح لي أن أقدم لك المعلومات التالية حول هذا الموضوع...`,
                    `سؤال مثير للاهتمام! دعني أفكر في "${message}" للحظة...`,
                    `سأكون سعيدًا بمساعدتك بخصوص "${message}". إليك بعض المعلومات التي قد تكون مفيدة...`,
                    `بخصوص "${message}"، لدي هذه التفاصيل التي قد تجيب على سؤالك...`,
                    `شكرًا لسؤالك عن "${message}". المعلومات المتوفرة لدي تشير إلى أن...`,
                    `لقد بحثت عن "${message}" وهذه هي النتائج التي توصلت إليها...`,
                    `سؤالك مهم. فيما يلي تحليلي لموضوع "${message}"...`,
                    `فهمت أنك تريد معرفة المزيد عن "${message}". اسمح لي أن أشرح لك...`
                ];
                const randomResponse = responses[Math.floor(Math.random() * responses.length)];
                addMessage(randomResponse, 'ai');
            }, 1500 + Math.random() * 2000);
        });

        // Handle suggestion buttons
        document.querySelectorAll('.suggestion-btn').forEach(button => {
            button.addEventListener('click', function() {
                textarea.value = this.textContent;
                textarea.dispatchEvent(new Event('input'));
                textarea.focus();
            });
        });

        // Add a new message to the chat
        function addMessage(content, sender) {
            const now = new Date();
            const timeString = now.toLocaleTimeString('ar-EG', { hour: '2-digit', minute: '2-digit' });
            
            const messageDiv = document.createElement('div');
            messageDiv.className = 'chat-message';
            
            if (sender === 'user') {
                messageDiv.innerHTML = `
                    <div class="flex items-start justify-end">
                        <div class="flex-1 max-w-3xl">
                            <div class="bg-blue-500 text-white p-4 rounded-lg shadow-sm mr-auto">
                                <p>${content}</p>
                            </div>
                            <div class="text-xs text-gray-500 mt-1 ml-1 text-left">${timeString}</div>
                        </div>
                    </div>
                `;
            } else {
                messageDiv.innerHTML = `
                    <div class="flex items-start">
                        <div class="w-8 h-8 rounded-full bg-gradient-to-r from-purple-500 to-blue-500 flex items-center justify-center text-white font-bold ml-3">AI</div>
                        <div class="flex-1">
                            <div class="bg-white p-4 rounded-lg shadow-sm max-w-3xl">
                                <p class="text-gray-800">${content}</p>
                            </div>
                            <div class="text-xs text-gray-500 mt-1 mr-1">${timeString}</div>
                        </div>
                    </div>
                `;
            }
            
            chatMessages.appendChild(messageDiv);
            chatMessages.scrollTop = chatMessages.scrollHeight;
        }

        // Allow Enter to send (Shift+Enter for new line)
        textarea.addEventListener('keydown', function(e) {
            if (e.key === 'Enter' && !e.shiftKey) {
                e.preventDefault();
                chatForm.dispatchEvent(new Event('submit'));
            }
        });
    </script>
</body>
</html>