class AgenticChat extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
Hello! I'm your AI assistant. How can I help you today?
`;
const sendButton = this.shadowRoot.getElementById('sendButton');
const userInput = this.shadowRoot.getElementById('userInput');
const messagesContainer = this.shadowRoot.getElementById('messages');
sendButton.addEventListener('click', () => {
const message = userInput.value.trim();
if (message) {
// Add user message
const userMessage = document.createElement('div');
userMessage.className = 'p-4 mb-2 bg-indigo-50 rounded-lg shadow-sm text-right';
userMessage.textContent = message;
messagesContainer.appendChild(userMessage);
// Add typing indicator
const typingIndicator = document.createElement('div');
typingIndicator.className = 'p-4 mb-2 bg-white rounded-lg shadow-sm';
typingIndicator.innerHTML = `
`;
messagesContainer.appendChild(typingIndicator);
messagesContainer.scrollTop = messagesContainer.scrollHeight;
userInput.value = '';
// Simulate agent response after a delay
setTimeout(() => {
messagesContainer.removeChild(typingIndicator);
simulateAgentResponse(messagesContainer);
}, 1500);
}
});
userInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
sendButton.click();
}
});
}
}
customElements.define('agentic-chat', AgenticChat);