Spaces:
Running

File size: 3,227 Bytes
a7f5574
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

    <!-- Chat Initiation Button -->
    <div id="chat-starter" class="fixed bottom-6 right-6 bg-blue-500 text-white p-4 rounded-full shadow-lg cursor-pointer hover:bg-blue-600 transition-all">
      <i data-feather="message-circle"></i>
    </div>

    <!-- Chat Modal -->
    <div id="chat-modal" class="hidden fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50">
      <div class="bg-white rounded-lg shadow-xl w-full max-w-md max-h-[80vh] flex flex-col">
        <div class="p-4 border-b flex justify-between items-center">
          <h3 class="text-lg font-semibold">ChattyCodeCanvas Assistant</h3>
          <button id="close-chat" class="text-gray-500 hover:text-gray-700">
            <i data-feather="x"></i>
          </button>
        </div>
        <div id="chat-messages" class="flex-1 p-4 overflow-y-auto">
          <div class="text-center text-gray-500 py-4">How can I help you with your project today?</div>
        </div>
        <div class="p-4 border-t">
          <div class="flex gap-2">
            <input id="chat-input" type="text" placeholder="Type your message..." class="flex-1 border rounded-lg px-4 py-2 focus:outline-none focus:ring-2 focus:ring-blue-500">
            <button id="send-chat" class="bg-blue-500 text-white px-4 py-2 rounded-lg hover:bg-blue-600 transition-all">
              <i data-feather="send"></i>
            </button>
          </div>
        </div>
      </div>
    </div>

    <script>
      document.addEventListener('DOMContentLoaded', function() {
        feather.replace();
        
        const chatStarter = document.getElementById('chat-starter');
        const chatModal = document.getElementById('chat-modal');
        const closeChat = document.getElementById('close-chat');
        const chatInput = document.getElementById('chat-input');
        const sendChat = document.getElementById('send-chat');
        const chatMessages = document.getElementById('chat-messages');

        chatStarter.addEventListener('click', () => {
          chatModal.classList.remove('hidden');
        });

        closeChat.addEventListener('click', () => {
          chatModal.classList.add('hidden');
        });

        sendChat.addEventListener('click', sendMessage);
        chatInput.addEventListener('keypress', (e) => {
          if (e.key === 'Enter') sendMessage();
        });

        function sendMessage() {
          const message = chatInput.value.trim();
          if (message) {
            addMessage(message, 'user');
            chatInput.value = '';
            // Here you would typically send to a backend or process
            setTimeout(() => {
              addMessage("I'm just a frontend demo! In a real app, this would connect to a backend.", 'bot');
            }, 800);
          }
        }

        function addMessage(text, sender) {
          const messageDiv = document.createElement('div');
          messageDiv.className = `mb-4 p-3 rounded-lg max-w-[80%] ${sender === 'user' ? 'bg-blue-100 ml-auto' : 'bg-gray-100'}`;
          messageDiv.textContent = text;
          chatMessages.appendChild(messageDiv);
          chatMessages.scrollTop = chatMessages.scrollHeight;
        }
      });
    </script>