File size: 6,562 Bytes
4470195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
class ChatbotComponent extends HTMLElement {
  connectedCallback() {
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.innerHTML = `
      <style>
        :host {
          display: block;
          position: fixed;
          bottom: 20px;
          right: 20px;
          width: 400px;
          max-height: 600px;
          background: white;
          border-radius: 12px;
          box-shadow: 0 10px 25px rgba(0,0,0,0.1);
          z-index: 1000;
          overflow: hidden;
          font-family: 'Inter', sans-serif;
        }
        
        .chatbot-header {
          background: #21223a;
          color: white;
          padding: 16px;
          display: flex;
          justify-content: space-between;
          align-items: center;
        }
        
        .chatbot-title {
          font-weight: 600;
          font-size: 18px;
        }
        
        .chatbot-close {
          background: none;
          border: none;
          color: white;
          cursor: pointer;
        }
        
        .chatbot-body {
          padding: 16px;
          height: 400px;
          overflow-y: auto;
        }
        
        .message {
          margin-bottom: 12px;
          max-width: 80%;
          padding: 8px 12px;
          border-radius: 8px;
          font-size: 14px;
        }
        
        .bot-message {
          background: #f3f4f6;
          margin-right: auto;
          border-top-left-radius: 0;
        }
        
        .user-message {
          background: #ff580f;
          color: white;
          margin-left: auto;
          border-top-right-radius: 0;
        }
        
        .chatbot-footer {
          display: flex;
          padding: 16px;
          border-top: 1px solid #e5e7eb;
          background: #f9fafb;
        }
        
        .chatbot-input {
          flex: 1;
          padding: 10px 12px;
          border: 1px solid #e5e7eb;
          border-radius: 8px;
          outline: none;
          margin-right: 8px;
        }
        
        .chatbot-submit {
          background: #21223a;
          color: white;
          border: none;
          border-radius: 8px;
          padding: 0 16px;
          cursor: pointer;
          display: flex;
          align-items: center;
        }
        
        .action-buttons {
          display: flex;
          gap: 8px;
          padding: 8px 16px;
          background: #f9fafb;
          border-top: 1px solid #e5e7eb;
        }
        
        .action-btn {
          background: white;
          border: 1px solid #e5e7eb;
          border-radius: 20px;
          padding: 6px 12px;
          font-size: 12px;
          display: flex;
          align-items: center;
          cursor: pointer;
          transition: all 0.2s;
        }
        
        .action-btn:hover {
          background: #21223a;
          color: white;
        }
        
        .action-btn i {
          margin-right: 4px;
          font-size: 12px;
        }
      </style>
      
      <div class="chatbot-header">
        <div class="chatbot-title">Android Test Assistant</div>
        <button class="chatbot-close" id="closeChatbot">
          <i data-feather="x"></i>
        </button>
      </div>
      
      <div class="chatbot-body" id="chatbotMessages">
        <div class="message bot-message">
          Welcome! How can I help you test your Android application today?
        </div>
      </div>
      
      <div class="action-buttons">
        <button class="action-btn" id="installBtn">
          <i data-feather="download"></i> Install
        </button>
        <button class="action-btn" id="testBtn">
          <i data-feather="activity"></i> Run Tests
        </button>
        <button class="action-btn" id="evidenceBtn">
          <i data-feather="image"></i> Evidence
        </button>
        <button class="action-btn" id="clearBtn">
          <i data-feather="trash-2"></i> Clear
        </button>
        <button class="action-btn" id="settingsBtn">
          <i data-feather="settings"></i> Settings
        </button>
      </div>
      
      <div class="chatbot-footer">
        <input type="text" class="chatbot-input" id="chatbotInput" placeholder="Type your command...">
        <button class="chatbot-submit" id="chatbotSubmit">
          <i data-feather="send"></i>
        </button>
      </div>
    `;

    // Initialize feather icons
    feather.replace();
    
    // Add event listeners
    this.shadowRoot.getElementById('chatbotSubmit').addEventListener('click', this.sendMessage.bind(this));
    this.shadowRoot.getElementById('chatbotInput').addEventListener('keypress', (e) => {
      if (e.key === 'Enter') this.sendMessage();
    });
    
    this.shadowRoot.getElementById('closeChatbot').addEventListener('click', () => {
      this.style.display = 'none';
    });
    
    // Action buttons
    this.shadowRoot.getElementById('installBtn').addEventListener('click', () => {
      this.addMessage('Installing application...', 'bot');
    });
    
    this.shadowRoot.getElementById('testBtn').addEventListener('click', () => {
      this.addMessage('Running automated tests...', 'bot');
    });
    
    this.shadowRoot.getElementById('evidenceBtn').addEventListener('click', () => {
      this.addMessage('Opening test evidence...', 'bot');
    });
    
    this.shadowRoot.getElementById('clearBtn').addEventListener('click', () => {
      this.shadowRoot.getElementById('chatbotMessages').innerHTML = '';
      this.addMessage('Chat cleared. How can I help?', 'bot');
    });
    
    this.shadowRoot.getElementById('settingsBtn').addEventListener('click', () => {
      this.addMessage('Opening settings panel...', 'bot');
    });
  }
  
  sendMessage() {
    const input = this.shadowRoot.getElementById('chatbotInput');
    const message = input.value.trim();
    if (message) {
      this.addMessage(message, 'user');
      input.value = '';
      
      // Simulate bot response
      setTimeout(() => {
        this.addMessage('I can help you with that. What exactly would you like to test?', 'bot');
      }, 1000);
    }
  }
  
  addMessage(text, sender) {
    const messagesDiv = this.shadowRoot.getElementById('chatbotMessages');
    const messageDiv = document.createElement('div');
    messageDiv.className = `message ${sender}-message`;
    messageDiv.textContent = text;
    messagesDiv.appendChild(messageDiv);
    messagesDiv.scrollTop = messagesDiv.scrollHeight;
    
    // Refresh feather icons
    feather.replace();
  }
}

customElements.define('custom-chatbot', ChatbotComponent);