@@ -147,35 +147,48 @@ export const BeautyAssistant = () => {
147147 { messages . length === 0 && (
148148 < div className = "text-center py-6" >
149149 < div className = "w-20 h-20 mx-auto mb-6 rounded-full bg-gradient-to-br from-polished-gold/20 to-transparent flex items-center justify-center border border-polished-gold/30 shadow-[0_4px_20px_-5px_rgba(212,175,55,0.3)]" >
150- < img src = { personaTheme . icon } className = "w-16 h-16 object-contain" alt = "Icon" />
150+ < img src = "/dr-bot-character.png" className = "w-16 h-16 object-contain" alt = "Dr. Sami Icon" />
151151 </ div >
152152 < h4 className = "text-asper-ink font-heading text-xl font-bold mb-2" >
153153 { activePersona === "dr_sami"
154154 ? ( isAr ? "استشارة طبية" : "Clinical Consultation" )
155155 : ( isAr ? "روتين الجمال" : "Beauty Rituals" ) }
156156 </ h4 >
157157 < p className = "text-asper-ink/70 text-sm max-w-xs mx-auto leading-relaxed mb-6" >
158- { activePersona === "dr_sami"
159- ? ( isAr ? "أنا هنا لمساعدتك في اختيار الروتين الطبي الأمثل لبشرتك." : "I am here to guide you through medical-grade skincare protocols." )
160- : ( isAr ? "أهلاً بكِ. دعينا نكتشف أفضل منتجات المكياج والعناية اليومية." : "Welcome. Let's find your perfect daily style and glow essentials." ) }
158+ { isAr
159+ ? "أهلاً بكِ في عيادتنا الرقمية. صفي لي حالة بشرتكِ أو اختاري مما يلي:"
160+ : "Welcome to our digital clinic. Tell me about your skin concerns or select an option below:" }
161161 </ p >
162162
163163 < div className = "flex flex-col gap-2 px-4" >
164- { ( activePersona === "dr_sami"
165- ? [ 'Routine for acne-prone skin' , 'Best anti-aging protocol' , 'Barrier repair for sensitive skin' ]
166- : [ 'Natural everyday makeup' , 'Long-lasting lipstick shades' , 'Morning spa routine steps' ]
167- ) . map ( ( suggestion , idx ) => (
164+ { [ 'Routine for acne-prone skin' , 'Best anti-aging serum' , 'Daily hydration for sensitive skin' ] . map ( ( suggestion , idx ) => (
168165 < button
169166 key = { idx }
170- onClick = { ( ) => handleSend ( suggestion ) }
167+ onClick = { ( ) => {
168+ setInput ( suggestion ) ;
169+ // We wait a tick to ensure state is updated before sending
170+ setTimeout ( ( ) => {
171+ const userMsg = { role : "user" , content : suggestion } ;
172+ setMessages ( prev => [ ...prev , userMsg ] ) ;
173+ setInput ( "" ) ;
174+ setIsLoading ( true ) ;
175+ supabase . functions . invoke ( 'beauty-assistant' , { body : { messages : [ userMsg ] , language } } )
176+ . then ( ( { data, error} ) => {
177+ if ( error ) throw error ;
178+ setMessages ( prev => [ ...prev , { role : "assistant" , content : data . reply , trayProducts : data . products } ] ) ;
179+ } )
180+ . catch ( err => {
181+ console . error ( err ) ;
182+ toast . error ( ASPER_PROTOCOL . errorShort [ language === 'ar' ? 'ar' : 'en' ] ) ;
183+ } )
184+ . finally ( ( ) => setIsLoading ( false ) ) ;
185+ } , 50 ) ;
186+ } }
171187 className = "text-left px-4 py-3 text-sm bg-white border border-polished-gold/20 rounded-xl text-asper-ink/80 hover:bg-polished-gold/5 hover:border-polished-gold/40 hover:text-asper-ink transition-all shadow-sm active:scale-95"
172188 >
173- { isAr && activePersona === "dr_sami" && idx === 0 ? "روتين للبشرة المعرضة لحب الشباب" :
174- isAr && activePersona === "dr_sami" && idx === 1 ? "أفضل بروتوكول لمقاومة التجاعيد" :
175- isAr && activePersona === "dr_sami" && idx === 2 ? "إصلاح حاجز البشرة الحساسة" :
176- isAr && activePersona === "ms_zain" && idx === 0 ? "مكياج يومي طبيعي" :
177- isAr && activePersona === "ms_zain" && idx === 1 ? "ألوان أحمر شفاه تدوم طويلاً" :
178- isAr && activePersona === "ms_zain" && idx === 2 ? "خطوات روتين السبا الصباحي" : suggestion }
189+ { isAr && idx === 0 ? "روتين للبشرة المعرضة لحب الشباب" :
190+ isAr && idx === 1 ? "أفضل سيروم مقاوم للتجاعيد" :
191+ isAr && idx === 2 ? "ترطيب يومي للبشرة الحساسة" : suggestion }
179192 </ button >
180193 ) ) }
181194 </ div >
0 commit comments