local padding = system.narrowMode and 80 or 160

CarPuter = {
    ---@type ui.MediaPlayer
    turnSignalMediaPlayer = nil,
    chimeMediaPlayer = nil
}

function CarPuterSystem()
    if not CarPuter.turnSignalMediaPlayer then
        CarPuter.turnSignalMediaPlayer = ui.MediaPlayer():setAutoPlay(true)
        touchscreen.syncVolume(CarPuter.turnSignalMediaPlayer)
    end

    if not CarPuter.chimeMediaPlayer then
        CarPuter.chimeMediaPlayer = ui.MediaPlayer():setAutoPlay(true)
        touchscreen.syncVolume(CarPuter.chimeMediaPlayer)
    end

    local auto_headlights = false
    if auto_headlights then
        if ac.getSunAngle() > 85 then
            ac.setHeadlights(true)
        else
            ac.setHeadlights(false)
        end
    end

    if ((ac.getCar().turningLeftLights == true or ac.getCar().turningRightLights == true) and ac.isInteriorView() ==
        true) then
        -- if(carSounds:playing() ~= true) then
        CarPuter.turnSignalMediaPlayer:setSource('./sounds/turn_signals.mp3'):setAutoPlay(true)
        CarPuter.turnSignalMediaPlayer:setVolume(ac.getAudioVolume('main') * 0.3)
        CarPuter.turnSignalMediaPlayer:play()
        -- carSounds:setLooping(true)
        -- end
    else
        CarPuter.turnSignalMediaPlayer:pause()
        CarPuter.turnSignalMediaPlayer:setCurrentTime(0)
    end

    if ((ac.getCar().extraC == true) and ac.getCar().headlightsActive == true) and ac.isInteriorView() then
        -- if(carSounds2:playing() ~= true) then
        CarPuter.chimeMediaPlayer:setSource('./sounds/chime.mp3'):setAutoPlay(true)
        CarPuter.chimeMediaPlayer:setVolume(ac.getAudioVolume('main') * 0.3)
        CarPuter.chimeMediaPlayer:play()
        -- carSounds2:setLooping(true)
        -- end
    else
        CarPuter.chimeMediaPlayer:pause()
        CarPuter.chimeMediaPlayer:setCurrentTime(0)
    end
end

return function(dt)
    CarPuterSystem()
end
