
; -------------------------------MeWe-------------------------------
PostToMeWe:
CurrentSite := "MeWe"



SaveOrPostProgress(Message:="Navigating to Post Creation Page",PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile")

URLAttempt := NavigateFromBaseURLTo("https://www.mewe.com/myworld")
if(URLAttempt = "Failed")
Return

Status := CheckCurrentTabForCurrentSite()
if(Status){
	Return
}

; Click out of try MeWe Premium popup if it appears
SaveOrPostProgress(Message:="Checking for Popups and closing them",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = //button[normalize-space()='Skip Trial']
try driver.FindElementByXPath(Xpath).click()

sleep, 1000

; Click on Tell your contacts what's happening button
SaveOrPostProgress(Message:="Clicking into Start Post Box",PostType:="Tooltip,ErrorLoggingTextFile")

Xpath = //div[@data-testid='post-placeholder']
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000)
if(Status){
	SaveOrPostProgress(Message:="Post Failed: Check Login Status",PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}

; DevModeMsgBox("popup activated?")


; click into popup box to make sure it's activated
/*xpath = //div[@class='ql-editor ql-blank']//div
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000)
DevModeMsgBox(Status)
*/
; DevModeMsgBox("inputting post now after clickng")

; input post title and body with javascript
JsToExecute = document.querySelector(".ql-editor").innerText = '%JSPostTitleAndBody%';
try Status := driver.executeScript(JsToExecute)


; check that the input box contains text
JsToExecute = return document.querySelector(".ql-editor").innerText
try Status := driver.executeScript(JsToExecute)
if(StrLen(Status) < 5){
	Message = Failed to input post into popup box
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}


/*
Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=1000,SendKeysContent:=PostTitleAndBody)
if(Status){
	Message = Failed to input text into page.
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}
*/

; DevModeMsgBox("input worked?")


if(ImageAttachmentFilepath != ""){
	; Click "Image" button
	SaveOrPostProgress(Message:="Attaching Image",PostType:="Tooltip,ErrorLoggingTextFile")

	Xpath = //input[@id='fake-upload-photo']
	Status := Selenium_LoopToSendValueToXpath(Xpath:=Xpath,NumOfLoops:=2,SleepLength:=1000,StringTextContent:=ImageAttachmentFilepath)
/*
	; Xpath = /html/body/div[2]/div/div[1]/div[2]/div[1]/div/div[2]/div/div[4]/div[1]/button[1]
	Xpath = //button[@data-tooltip='Photo']
	Status := Selenium_LoopToClickXpathAndWaitForOpenWindow(Xpath:=Xpath,NumOfLoops:=10,SleepLength:=1000)
	if(Status){
		Message = Failed to click "Attach Photo" button
		SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
		Return
	}

	InputStatus := InputFilePathIntoOpenWindow(ImageAttachmentFilepath)
	if(InputStatus = "Failed")
	{
		Message = Upload Failed:`nUnable to Find "Open File" window to input filepath into
		SaveOrPostProgress(Message:=Message,PostType:=",ErrorLoggingTextFile,DiscordErrorLogging")
		Return
	}
	*/
	SaveOrPostProgress(Message:="Waiting 10 seconds for Image to finish uploading",PostType:="Tooltip,ErrorLoggingTextFile")

	sleep, 10000
}


; Click the "Post" button
SaveOrPostProgress(Message:="Submitting Post",PostType:="Tooltip,ErrorLoggingTextFile")
Xpath = (//button[normalize-space()='Post'])[1]
Status := Selenium_LoopToClickXpath(Xpath:=Xpath,NumOfLoops:=5,SleepLength:=2000)
if(Status){
	Message = Failed to Submit Post
	SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,ErrorSummaryVar,DiscordErrorLogging")
	SaveDriverURLOFErrorPage()
	Return
}

IniWrite, Successful, %StatusFileFilePath%, Status, MeWe
AddToTotalPostsPostedCount()



PauseBetweenPosts()
DevModeMsgBox("done!")


Message = Post Publish Successful
SaveOrPostProgress(Message:=Message,PostType:="Tooltip,ErrorLoggingTextFile,DiscordErrorLogging")


Return
; -------------------------------/MeWe-------------------------------
