*--------------------------------------------------------------------------------------------------------------------------------------------------------
* (EN) AUTOGENERATED - ATTENTION!! - NOT INTENDED FOR EXECUTION!! USE ONLY FOR MERGING CHANGES AND STORING WITH SCM TOOLS!!
*--------------------------------------------------------------------------------------------------------------------------------------------------------
*< FOXBIN2PRG: Version="1.21" SourceFile="frm_chatbot.scx" CPID="1252" /> (Solo para binarios VFP 9 / Only for VFP 9 binaries)
*
*
DEFINE CLASS _frmbase1 AS _frmbase OF "..\clase\_frm_base.vcx" 
 	*< CLASSDATA: Baseclass="form" Timestamp="" Scale="" Uniqueid="" />

	*-- OBJECTDATA items order determines ZOrder / El orden de los items OBJECTDATA determina el ZOrder 
	*< OBJECTDATA: ObjPath="Edit2" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="Cmd_executa1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="oleWebBrowser" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="But_reset1" UniqueID="" Timestamp="" />
	*< OBJECTDATA: ObjPath="cboChatBot" UniqueID="" Timestamp="" />

	*<DefinedPropArrayMethod>
		*m: addhtmltext
		*p: cchangelog
		*p: cchatbot
		*p: cchatid
		*p: chtmlbody
	*</DefinedPropArrayMethod>

	*<PropValue>
		BorderStyle = 3
		cchangelog = 
		cchatbot = Cezar
		cchatid = 
		chtmlbody = 
		DoCreate = .T.
		FontCharSet = 238
		Height = 521
		Name = "_frmbase1"
		Width = 678
		_memberdata = <VFPData>
			<memberdata name="addhtmltext" display="AddHtmlText"/>
			<memberdata name="cchatid" display="cChatId"/>
			<memberdata name="cchatbot" display="cChatBot"/>
		</VFPData>
		_shape1.Anchor = 10
		_shape1.Height = 29
		_shape1.Left = 0
		_shape1.Name = "_shape1"
		_shape1.Top = 0
		_shape1.Width = 684
		_shape2.Anchor = 8
		_shape2.Height = 29
		_shape2.Left = 642
		_shape2.Name = "_shape2"
		_shape2.Top = 0
		_shape2.Width = 36
		Lb_titlu_alb_b121.Caption = "Romfast Suport Chatbot"
		Lb_titlu_alb_b121.Name = "Lb_titlu_alb_b121"
		Lb_titlu_alb_b121.TabIndex = 3
		BUT_TERMIN1.Anchor = 8
		BUT_TERMIN1.Left = 647
		BUT_TERMIN1.Name = "BUT_TERMIN1"
		BUT_TERMIN1.TabIndex = 4
		BUT_TERMIN1.Top = 0
		Gridsort1.Name = "Gridsort1"
	*</PropValue>

	ADD OBJECT 'But_reset1' AS but_reset WITH ;
		Anchor = 8, ;
		Left = 615, ;
		Name = "But_reset1", ;
		Top = 0
		*< END OBJECT: ClassLib="..\clase\cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'cboChatBot' AS _combobox WITH ;
		Anchor = 12, ;
		BorderStyle = 0, ;
		Height = 24, ;
		Left = 581, ;
		Name = "cboChatBot", ;
		RowSource = "Maria,Cezar", ;
		RowSourceType = 1, ;
		SpecialEffect = 1, ;
		Top = 456, ;
		Value = Cezar, ;
		Width = 83
		*< END OBJECT: ClassLib="..\clase\_baza.vcx" BaseClass="combobox" />

	ADD OBJECT 'Cmd_executa1' AS cmd_executa WITH ;
		Anchor = 12, ;
		Caption = "...", ;
		FontCharSet = 1, ;
		FontSize = 20, ;
		ForeColor = 0,128,255, ;
		Height = 31, ;
		Left = 581, ;
		Name = "Cmd_executa1", ;
		TabIndex = 2, ;
		Top = 484, ;
		Width = 83
		*< END OBJECT: ClassLib="..\clase\cmd_butoane.vcx" BaseClass="commandbutton" />

	ADD OBJECT 'Edit2' AS editbox WITH ;
		Anchor = 14, ;
		ControlSource = "", ;
		FontSize = 12, ;
		Height = 60, ;
		Left = 7, ;
		Name = "Edit2", ;
		ReadOnly = .F., ;
		TabIndex = 1, ;
		Top = 452, ;
		Width = 569
		*< END OBJECT: BaseClass="editbox" />

	ADD OBJECT 'oleWebBrowser' AS _webbrowser4 WITH ;
		Anchor = 15, ;
		Height = 396, ;
		Left = 7, ;
		Name = "oleWebBrowser", ;
		Top = 48, ;
		Width = 663
		*< END OBJECT: ClassLib="..\utile\web\_webview.vcx" BaseClass="olecontrol" OLEObject="c:\windows\syswow64\ieframe.dll" Value="0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAAAAABAAAAAQAAAAAAAAAAEAAAAgAAAAEAAAD+////AAAAAAAAAAD////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////9/////v////7////+/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////1IAbwBvAHQAIABFAG4AdAByAHkAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWAAUA//////////8BAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGDDhqk9fdsBAwAAAEABAAAAAAAAAwBPAGwAZQBPAGIAagBlAGMAdABEAGEAdABhAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAB4AAgEDAAAAAgAAAP////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAArAAAAAAAAAADAEEAYwBjAGUAcwBzAE8AYgBqAFMAaQB0AGUARABhAHQAYQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJgACAP///////////////wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAA4AAAAAAAAAAMAQwBoAGEAbgBnAGUAZABQAHIAbwBwAHMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAcAAIA////////////////AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAQAAAAAAAAAAwAAAP7////+////BAAAAP7///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////9h+VaICjTQEalrAMBP1wWiTAAAAIZEAADuKAAAAQAAAAUAAAAAAAAAAAAAAAAAAAAAAAAATAAAAAAAAAAAAAAAOAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAA4NBXAHM1zxGuaQgAKy4SYggAAAAAAAAATAAAAAEUAgAAAAAAwAAAAAAAAEaAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==" />
	
	PROCEDURE addhtmltext
		LPARAMETERS tcText, tlUser
		* tcText: textul user/bot
		* tlUser: text trimis de user sau de bot
		
		lcClass = IIF(m.tlUser, "user", "assistant")
		lcText = IIF(m.tlUser, "I: ", "R: ") + m.tcText
		
		TEXT TO lcHtmlText TEXTMERGE NOSHOW 
		<div class="chat-bubble <<m.lcClass>>"><<m.lcText>></div>
		ENDTEXT 
		
		Thisform.cHtmlbody = Thisform.cHtmlbody + CHR(13) + m.lcHtmlText
		
		TEXT TO lcHtml TEXTMERGE NOSHOW 
		<!DOCTYPE html>
		<html lang="ro">
		<head>
		    <meta charset="UTF-8">
		    <meta name="viewport" content="width=device-width, initial-scale=1.0">
		    <title>Exemplu Bule de Chat</title>
		<style>
		        body {
		            font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
		            margin: 0;
		            padding: 20px;
		            background-color: #ffffff;
		        }
		        .chat-container {
		            max-width: 600px;
		            margin: 0 auto;
		        }
		        .chat-bubble {
		            border-radius: 18px;
		            padding: 12px 16px;
		            margin-bottom: 12px;
		            max-width: 80%;
		            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
		        }
		        .assistant {
		            background-color: #f0f0f0;
		            color: black;
		            align-self: flex-start;
		            border-bottom-left-radius: 4px;
		        }
		        .user {
		            background-color: #0084ff;
		            color: white;
		            align-self: flex-end;
		            margin-left: auto;
		            border-bottom-right-radius: 4px;
		            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
		        }
		    </style>
		</head>
		<body>
		    <div class="chat-container">
		<<Thisform.cHtmlbody>>
		 </div>
		</body>
		</html>
		ENDTEXT 
		
		lnLoadTimeout = 3       && seconds
		WITH Thisform.oleWebBrowser.object
		*!*		.Navigate("about:blank")
		*!*		* Wait for load completion
		*!*		lnStartSeconds = SECONDS()
		*!*		DO WHILE .ReadyState <> 4 ;
		*!*				AND (SECONDS()-lnStartSeconds <= lnLoadTimeout )
		*!*			DOEVENTS
		*!*		ENDDO
		
			* Load HTML into Web Browser Control
			.Document.Open()
			.Document.Write(m.lcHtml)
			.Document.Close()
			* Wait for load completion
			lnStartSeconds = SECONDS()
			DO WHILE .ReadyState <> 4 ;
					AND (SECONDS()-lnStartSeconds <= lnLoadTimeout )
				DOEVENTS
			ENDDO
		ENDWITH
		
	ENDPROC

	PROCEDURE do_reset
		Local lnLoadTimeout, lnStartSeconds
		
		lnLoadTimeout = 3       && seconds
		WITH Thisform.oleWebBrowser.object
			.Navigate("about:blank")
			* Wait for load completion
			lnStartSeconds = SECONDS()
			DO WHILE .ReadyState <> 4 ;
					AND (SECONDS()-lnStartSeconds <= lnLoadTimeout )
				DOEVENTS
			ENDDO
		
			.Document.Open()
			.Document.Write('')
			.Document.Close()
		
			Thisform.cHtmlbody = ''
			Thisform.AddHtmlText("Buna, cu ce pot sa te ajut?", .F.)
			
		ENDWITH 
		Thisform.cChatId = ""
		Thisform.edit2.SetFocus()
		 
	ENDPROC

	PROCEDURE Init
		this.Height = INT(_screen.Height*0.7)
		this.Width = INT(_screen.Width * 0.4)
		this.AutoCenter = .T.
		
		Thisform.do_reset()
		DODEFAULT()
	ENDPROC

	PROCEDURE cboChatBot.Valid
		IF this.Value <> Thisform.cChatBot
			Thisform.cChatBot = this.Value 
			Thisform.do_reset()
			thisform.edit2.SetFocus()
		ENDIF 
	ENDPROC

	PROCEDURE cboChatBot.When
		Thisform.cChatBot = this.Value 
	ENDPROC

	PROCEDURE Cmd_executa1.Click
		LOCAL lcQuestion, m.llMarkdown2Html
		Local lcChatId, lcRaspuns, llMarkdown2Html, lcChatBot
		m.llMarkdown2Html = .T.
		lcQuestion = thisform.edit2.Value
		lcChatBot = thisform.cboChatBot.Value 
		
		*!*	thisform.edit1.Value = thisform.edit1.Value + CHR(13) + CHR(10) + ;
		*!*		SPACE(20) + 'I: ' + m.lcQuestion
			 
		thisform.edit2.Value = ''
		Thisform.AddHtmlText(m.lcQuestion, .T.)
		Thisform.Refresh()	
		
		lcChatId = Thisform.cChatId
		lcRaspuns = chatbot(m.lcQuestion, @lcChatId, m.llMarkdown2Html, m.lcChatBot)
		Thisform.cChatId = m.lcChatId
		
		
		*!*	thisform.edit1.Value = thisform.edit1.Value + CHR(13) + CHR(10) + ;
		*!*		'R: ' + m.lcRaspuns
		
		Thisform.AddHtmlText(m.lcRaspuns, .F.)
			
		thisform.edit2.SetFocus()	
		
		Thisform.Refresh()	 
	ENDPROC

	PROCEDURE Edit2.KeyPress
		LPARAMETERS nKeyCode, nShiftAltCtrl
		IF nkeyCode = 13
			Thisform.cmd_executa1.Click()
		ENDIF 
	ENDPROC

ENDDEFINE

DEFINE CLASS dataenvironment AS dataenvironment 
 	*< CLASSDATA: Baseclass="dataenvironment" Timestamp="" Scale="" Uniqueid="" ClassIcon="1" />

	*<PropValue>
		DataSource = .NULL.
		Height = 0
		Left = 0
		Name = "Dataenvironment"
		Top = 0
		Width = 0
	*</PropValue>

ENDDEFINE
