local luaCutscenesUtils = require("#Celeste.Mod.MaxHelpingHand.Module.LuaCutscenesUtils")

local function doFadeWipe(state)
    fadeWipe = celeste.FadeWipe(engine.Scene, state, nil) -- (state = "false" escurece ,"true" clareia)
    engine.Scene:Add(fadeWipe)
    fadeWipe.duration = 2
    fadeWipe.EndTimer = 21
  end


  function onTalk()
	disablePause()
    disableMovement()
	wait(0.5)
	setFlag("deepwell_apple_a")
	setFlag("deepwell_apple_og")
	wait(0.5)
	setFlag("deepwell_apple_b")
	setFlag("deepwell_apple_a", false)
	wait(0.5)
	setFlag("deepwell_apple_c")
	setFlag("deepwell_apple_b", false)
	wait(0.5)
	setFlag("deepwell_apple_d")
	setFlag("deepwell_apple_c", false)
	wait(0.5)
    coroutine.yield(luaCutscenesUtils.SayWithDifferentFont("OMORI_GAME", "CBR_DeeperWell_AppleTree"))

    coroutine.yield(luaCutscenesUtils.ChoiceWithDifferentFont("OMORI_GAME", "CBR_DeepWell_RoadEndchoice1", "CBR_DeepWell_RoadEndchoice2"))
    local appleeat = luaCutscenesUtils.GetChoice()
  
    if appleeat == 1 then
		doFadeWipe(false)
		wait(1)
		playSound("event:/game/WanderBDay/omori_eating", player.Position)
		wait(10)
		setFlag("deeperwell_appletreeend")
	  
    else
		wait(0.2)
		setFlag("deepwell_apple_c")
		setFlag("deepwell_apple_d", false)
		wait(0.2)
		setFlag("deepwell_apple_b")
		setFlag("deepwell_apple_c", false)
		wait(0.2)
		setFlag("deepwell_apple_a")
		setFlag("deepwell_apple_b", false)
		wait(0.2)
		setFlag("deepwell_apple_og", false)
		setFlag("deepwell_apple_a", false)
		enableMovement()
		enablePause()
    end
end