local M = {}

local bvaluelight = false
local bvaluelight2 = false
local bvaluelight3 = false
local bvaluelight4 = false
local bvaluelight5 = false
local bvaluemesh1 = false
local bvaluemesh2 = false
local bvaluemesh3 = false
local bvaluemesh4 = false
local requireupdcolbohhu = false
local im = ui_imgui
local timer = 0



local function onClientStartMission()
  --light = scenetree.findObject('Mesh')
  --editor.deleteObject(light)
end

local function setMeshEnabledBohhu(group, visible)
  for i = 0, group.obj:getCount(), 1 do
      local id = group.obj:idAt(i)
      local objbohhu = scenetree.findObjectById(id)
      objbohhu.obj.hidden = ( visible )
  end
end

local function guiupdatebohhu()
  im.Begin("Parking Controller by bohhu")
  -- Текст
  im.Text("Lights On/Off")
  -- Кнопка
  if im.Button("Sector 1") then
    if bvaluelight then
      bvaluelight = false
    else
      bvaluelight = true
    end
  end
  im.SameLine()
  if im.Button("Sector 2") then
    if bvaluelight2 then
      bvaluelight2 = false
    else
      bvaluelight2 = true
    end
  end
  im.SameLine()
  if im.Button("Sector 3") then
    if bvaluelight3 then
      bvaluelight3 = false
    else
      bvaluelight3 = true
    end
  end
  im.SameLine()
  if im.Button("Sector 4") then
    if bvaluelight4 then
      bvaluelight4 = false
    else
      bvaluelight4 = true
    end
  end
  im.SameLine()
  if im.Button("Sector 5") then
    if bvaluelight5 then
      bvaluelight5 = false
    else
      bvaluelight5 = true
    end
  end
  im.Separator()
  im.Text("Objects On/Off")
  if im.Button("Parking Places Limiters") then
    if bvaluemesh1 then
      bvaluemesh1 = false
    else
      bvaluemesh1 = true
    end
    requireupdcolbohhu = true
  end
  im.SameLine()
  if im.Button("Parking Places Numbers") then
    if bvaluemesh2 then
      bvaluemesh2 = false
    else
      bvaluemesh2 = true
    end
    requireupdcolbohhu = true
  end
  if im.Button("Speed Bumps") then
    if bvaluemesh3 then
      bvaluemesh3 = false
    else
      bvaluemesh3 = true
    end
    requireupdcolbohhu = true
  end
  im.SameLine()
  if im.Button("Road Decals") then
    if bvaluemesh4 then
      bvaluemesh4 = false
    else
      bvaluemesh4 = true
    end
    requireupdcolbohhu = true
  end
  im.Separator()
  im.Text("https://t.me/dpngk - dpngk , https://t.me/bohhuworks - bohhu")
  im.End()
end

local function onUpdate(dt)
  timer = timer + dt
  guiupdatebohhu()
  if timer > 0.1 then
    if scenetree.bohhulight1 then
      setMeshEnabledBohhu(scenetree.bohhulight1, bvaluelight)
    end
    if scenetree.bohhulight2 then
      setMeshEnabledBohhu(scenetree.bohhulight2, bvaluelight2)
    end
    if scenetree.bohhulight3 then
      setMeshEnabledBohhu(scenetree.bohhulight3, bvaluelight3)
    end
    if scenetree.bohhulight4 then
      setMeshEnabledBohhu(scenetree.bohhulight4, bvaluelight4)
    end
    if scenetree.bohhulight5 then
      setMeshEnabledBohhu(scenetree.bohhulight5, bvaluelight5)
    end
    if scenetree.bohhufolder1 then
      setMeshEnabledBohhu(scenetree.bohhufolder1, bvaluemesh1)
    end
    if scenetree.bohhufolder2 then
      setMeshEnabledBohhu(scenetree.bohhufolder2, bvaluemesh2)
    end
    if scenetree.bohhufolder3 then
      setMeshEnabledBohhu(scenetree.bohhufolder3, bvaluemesh3)
    end
    if scenetree.bohhufolder4 then
      setMeshEnabledBohhu(scenetree.bohhufolder4, bvaluemesh4)
    end
    timer = 0
    if requireupdcolbohhu then
      requireupdcolbohhu = false
      be:reloadStaticCollision()
    end
  end
end



M.onUpdate = onUpdate
M.onClientStartMission = onClientStartMission


return M

