local luaCutscenesUtils = require("#Celeste.Mod.MaxHelpingHand.Module.LuaCutscenesUtils")
 -- TODO: fix the bug where if strawberryJamQuestOngoing and TimeIsOut it still gives the berry.
 -- And a way to reset the counter
function onTalk()
    disableMovement()
	if getFlag("TheoBerry") then -- Dialog post-clear
		coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CC_omori_theo_GotBerry"))
		endCutscene()
	else
		if getFlag("TimeIsOut") then -- Resets quest
			engine.Scene.Session:SetCounter("strawberryJamPoints",0)
			setFlag("strawberryJamQuestOngoing",false)
			setFlag("TimeIsOut",false)
			coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CC_omori_theo_RanOutOfTime"))
			setFlag("DetachSilver",true)
			wait(0.25)
			playMusic("event:/ashleybl/citytheme",5)
			die({0,0},true,false)
			endCutscene()
			
		else
			if getFlag("strawberryJamQuestOngoing") then
				if engine.Scene.Session:GetCounter("strawberryJamPoints") < 30 then -- Hurry up dialog
					coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CC_omori_theo_HurryUp"))
					endCutscene()
				else -- Stops quest, gives berry
					coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CC_omori_theo_GivesBerry"))
					playSound("event:/ashleybl/SYS_quest_complete")
					setFlag("TheoBerry",true)
					endCutscene()
				end
			else -- Starts quest
				coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CC_omori_theo_StartQuest"))
				playSound("event:/ashleybl/SYS_quest_get")
				wait(0.1)
				playMusic("event:/ashleybl/CCjawbreaker",0)
				setFlag("strawberryJamQuestOngoing",true)
				setFlag("TimeIsOut",false)
				endCutscene()
			end
		end
	end
end

function onEnd()
    enableMovement()
end