1+ <!DOCTYPE html>
2+ < html >
3+ < head >
4+ < title > GHZHost AI Assistant</ title >
5+ < style >
6+ * {
7+ margin : 0 ;
8+ padding : 0 ;
9+ box-sizing : border-box;
10+ }
11+
12+ html , body {
13+ height : 100% ;
14+ width : 100% ;
15+ margin : 0 ;
16+ padding : 0 ;
17+ overflow : hidden;
18+ }
19+
20+ # app {
21+ display : flex;
22+ flex-direction : column;
23+ height : 100% ;
24+ width : 100% ;
25+ background-color : # 000a20 ;
26+ color : # ffffff ;
27+ font-family : Arial, sans-serif;
28+ position : relative;
29+ }
30+
31+ .chat-container {
32+ flex : 1 ;
33+ overflow-y : auto;
34+ background-color : # 00233f ;
35+ padding : 10px ;
36+ padding-bottom : 70px ; /* Maior que a altura do input-area para garantir espaço */
37+ }
38+
39+ .message {
40+ margin : 5px 0 ;
41+ padding : 10px ;
42+ border-radius : 4px ;
43+ max-width : 80% ;
44+ word-break : break-word;
45+ }
46+
47+ .user-message {
48+ background-color : # 00547f ;
49+ margin-left : auto;
50+ }
51+
52+ .ai-message {
53+ background-color : # 003366 ;
54+ margin-right : auto;
55+ }
56+
57+ .input-area {
58+ position : absolute;
59+ bottom : 0px ;
60+ left : 0 ;
61+ right : 0 ;
62+ background-color : # 00233f ;
63+ border-top : 1px solid # 003366 ;
64+ height : 100px ;
65+ padding : 10px ;
66+ z-index : 1000 ;
67+ }
68+
69+ .input-container {
70+ display : flex;
71+ align-items : center;
72+ gap : 10px ;
73+ height : 40px ; /* Reduzido para garantir que caiba dentro do input-area */
74+ max-width : calc (100% - 20px ); /* Considerando o padding do input-area */
75+ margin : 0 auto;
76+ }
77+
78+ # messageInput {
79+ flex : 1 ;
80+ height : 100% ;
81+ min-width : 100px ; /* Garante um tamanho mínimo */
82+ max-width : calc (100% - 100px ); /* Considera a largura do botão + gap */
83+ padding : 8px ;
84+ border : 1px solid # 00b2e8 ;
85+ border-radius : 4px ;
86+ background-color : # 001a2f ;
87+ color : # ffffff ;
88+ font-size : 14px ;
89+ }
90+
91+ # sendButton {
92+ width : 80px ;
93+ height : 100% ;
94+ background-color : # 00b2e8 ;
95+ color : # 000a20 ;
96+ border : none;
97+ border-radius : 4px ;
98+ cursor : pointer;
99+ font-weight : bold;
100+ flex-shrink : 0 ;
101+ white-space : nowrap;
102+ }
103+
104+ # sendButton : hover {
105+ background-color : # 00547f ;
106+ color : white;
107+ }
108+
109+ .typing-indicator {
110+ display : none;
111+ padding : 10px ;
112+ margin : 5px 0 ;
113+ }
114+
115+ .typing-animation {
116+ display : flex;
117+ gap : 4px ;
118+ background-color : # 003366 ;
119+ padding : 10px ;
120+ border-radius : 4px ;
121+ width : fit-content;
122+ }
123+
124+ .dot {
125+ width : 6px ;
126+ height : 6px ;
127+ background-color : # 00b2e8 ;
128+ border-radius : 50% ;
129+ animation : bounce 1.4s infinite;
130+ }
131+
132+ .dot : nth-child (2 ) { animation-delay : 0.2s ; }
133+ .dot : nth-child (3 ) { animation-delay : 0.4s ; }
134+
135+ @keyframes bounce {
136+ 0% , 100% { transform : translateY (0 ); }
137+ 50% { transform : translateY (-4px ); }
138+ }
139+ </ style >
140+ </ head >
141+ < body >
142+ < div id ="app ">
143+ < div class ="chat-container " id ="chatContainer ">
144+ < div class ="ai-message ">
145+ Olá! Eu sou o assistente AI da GHZHost. Como posso ajudar você hoje?
146+ </ div >
147+ < div class ="typing-indicator " id ="typingIndicator ">
148+ < div class ="typing-animation ">
149+ < div class ="dot "> </ div >
150+ < div class ="dot "> </ div >
151+ < div class ="dot "> </ div >
152+ </ div >
153+ </ div >
154+ </ div >
155+ < div class ="input-area ">
156+ < div class ="input-container ">
157+ < input type ="text " id ="messageInput " placeholder ="Digite sua mensagem... " />
158+ < button id ="sendButton "> Enviar</ button >
159+ </ div >
160+ </ div >
161+ </ div >
162+
163+ < script >
164+ const chatContainer = document . getElementById ( 'chatContainer' ) ;
165+ const messageInput = document . getElementById ( 'messageInput' ) ;
166+ const sendButton = document . getElementById ( 'sendButton' ) ;
167+ const typingIndicator = document . getElementById ( 'typingIndicator' ) ;
168+
169+ async function callGeminiAPI ( message ) {
170+ try {
171+ const response = await fetch ( 'http://localhost:3000/api/chat' , {
172+ method : 'POST' ,
173+ headers : {
174+ 'Content-Type' : 'application/json' ,
175+ } ,
176+ body : JSON . stringify ( { message } )
177+ } ) ;
178+
179+ if ( ! response . ok ) {
180+ throw new Error ( 'API request failed' ) ;
181+ }
182+
183+ const data = await response . json ( ) ;
184+ return data . response ;
185+ } catch ( error ) {
186+ console . error ( 'Erro ao chamar API:' , error ) ;
187+ throw error ;
188+ }
189+ }
190+
191+ async function sendMessage ( ) {
192+ const message = messageInput . value . trim ( ) ;
193+ if ( ! message ) return ;
194+
195+ // Adicionar mensagem do usuário
196+ addMessage ( message , 'user' ) ;
197+ messageInput . value = '' ;
198+
199+ // Mostrar indicador de digitação
200+ typingIndicator . style . display = 'block' ;
201+ chatContainer . scrollTop = chatContainer . scrollHeight ;
202+
203+ try {
204+ // Aqui será implementada a chamada para a API do Gemini
205+ const response = await callGeminiAPI ( message ) ;
206+
207+ // Esconder indicador de digitação
208+ typingIndicator . style . display = 'none' ;
209+
210+ // Adicionar resposta do AI
211+ addMessage ( response , 'ai' ) ;
212+ } catch ( error ) {
213+ console . error ( 'Erro ao chamar API:' , error ) ;
214+ typingIndicator . style . display = 'none' ;
215+ addMessage ( 'Desculpe, ocorreu um erro ao processar sua mensagem.' , 'ai' ) ;
216+ }
217+ }
218+
219+ function addMessage ( text , type ) {
220+ const messageDiv = document . createElement ( 'div' ) ;
221+ messageDiv . className = `message ${ type } -message` ;
222+ messageDiv . textContent = text ;
223+ chatContainer . insertBefore ( messageDiv , typingIndicator ) ;
224+ chatContainer . scrollTop = chatContainer . scrollHeight ;
225+ }
226+
227+ // Event listeners
228+ sendButton . addEventListener ( 'click' , sendMessage ) ;
229+ messageInput . addEventListener ( 'keypress' , ( e ) => {
230+ if ( e . key === 'Enter' ) {
231+ sendMessage ( ) ;
232+ }
233+ } ) ;
234+ </ script >
235+ </ body >
236+ </ html >
0 commit comments