HangarMapManager = HangarMapManager or class()

function HangarMapManager:init()
  self._workspace = managers.gui_data:create_fullscreen_workspace()
self._played_video = false
end

function HangarMapManager:PlaySpawnVideo()
   if self._played_video then
        return
    end

    local res = RenderSettings.resolution
    local src_width = 1920
    local src_height = 1080
    local dest_width, dest_height = nil

    if res.x / res.y < src_width / src_height then
        dest_width = res.x
        dest_height = (src_height * dest_width) / src_width
    else
        dest_height = res.y
        dest_width = (src_width * dest_height) / src_height
    end
    
    local x = (res.x - dest_width) / 2
    local y = (res.y - dest_height) / 2
    
    self.video_panel = managers.hangarmap._workspace:panel():video({
        video = "movies/faint",
        x = x,
        y = y,
        layer = -10
    })
    
    self._played_video = true

    self:wait(8, "hg_wait_video_reenable", function()
        managers.hangarmap._played_video = false
    end)
end

function HangarMapManager:wait(t, uniqid, ect)
    DelayedCalls:Add(uniqid, t, ect)
end

Hooks:Add("GameSetupUpdate", "VideoPanelUpdate", function(t, dt)
    if not alive(managers.hangarmap.video_panel) then
        return
    end

    if managers.hangarmap.video_panel and managers.hangarmap.video_panel:current_frame() >= managers.hangarmap.video_panel:frames() then
        managers.hangarmap.video_panel:parent():remove(managers.hangarmap.video_panel)
    end
end)