--NOTE: Old source code from Bell 407 mod
--updated for Antonov, but not cleaned up
--(TLDR : Not an accurate representation of the rest of the mods quality)

local M = {}
M.testMode = false

--STROBE LIGHT SYSTEM STAGES--
local nullStage = {
    electric = nil,
    duration = 0.4
}

local stabilizerStage = {
    electric = "redlight_tail",
    duration = 0.2,
    value = 1,
    valueEnd = 0
}

local cargoStage = {
    electric = "redlight_cargo",
    duration = 0.2,
    value = 1,
    valueEnd = 0
}
--STROBE LIGHT SYSTEM STAGES END--
--STROBE LIGHT SYSETM DATA--
local currentStrobeStage = 1
local currentStrobeStageTime = 0
local strobeStages = {stabilizerStage, nullStage, cargoStage, nullStage, stabilizerStage, nullStage, nullStage, nullStage}
--STROBE LIGHT SYSETM DATA END--

local function init()
    for _,strb in ipairs(strobeStages) do
      if strb.electric ~= nil then electrics.values[strb.electric] = 0 end
    end
end

local function updateGFX(dt)
  --if M.testMode then
  --  currentStrobeStage = currentStrobeStage + 1
  --  if currentStrobeStage >= # strobeStages then currentStrobeStage = 1 end
  --end
  
  currentStrobeStageTime = currentStrobeStageTime + dt
  local lowbeamsOn = (electrics.values.lowhighbeam == 1)
  if lowbeamsOn then
    local curStage = strobeStages[currentStrobeStage]
    if currentStrobeStageTime > curStage.duration then
        --assign electric if applicable
        if curStage.electric ~= nil then
          electrics.values[curStage.electric] = curStage.valueEnd
        end
        
        --increment stage, loop if we're at the last one
        currentStrobeStage = currentStrobeStage + 1
        if currentStrobeStage > #strobeStages then currentStrobeStage = 1 end
        currentStrobeStageTime = 0
        curStage = strobeStages[currentStrobeStage]
        
        --assign value for next stage if applicable
        if curStage.electric ~= nil then 
          electrics.values[curStage.electric] = strobeStages[currentStrobeStage].value
        end
    end
  else
    --clear all values
    for _,strb in ipairs(strobeStages) do
        if strb.electric ~= nil then electrics.values[strb.electric] = 0 end
    end
  end
end

local function reset()
 init()
end

M.updateGFX = updateGFX
M.onReset = reset
M.onInit = init
return M