local _, ns = ...
local L = ns.L or {}

local UI = ns.UI
if type(UI) ~= "table" then
    return
end

local UIMythicPlusView = ns.UIMythicPlusView or {}
local buildMythicPlusSeasonOneView = UIMythicPlusView.BuildSeasonOneView or function()
    return {
        available = false,
        message = L.MYTHIC_PLUS_UNAVAILABLE or "Mythic+ data is not available yet.",
    }
end

local UIHousingView = ns.UIHousingView or {}
local buildHousingEndeavorsView = UIHousingView.BuildEndeavorsView or function()
    return {
        available = false,
        message = L.HOUSING_UNAVAILABLE or "Housing data is not available yet.",
    }
end

function UI:CaptureCurrentMythicPlusSnapshot()
    local currentCharacter = ns.GetCurrentCharacterInfo and ns:GetCurrentCharacterInfo() or nil
    if not currentCharacter then
        return nil
    end

    local view = buildMythicPlusSeasonOneView(currentCharacter)
    return view and view.available and view or nil
end

function UI:IsHousingViewActive()
    if not self.frame or not self.frame:IsShown() or self.wishlistPanelOpen == true then
        return false
    end

    local selectedMainTab = ns.GetSelectedMainTab and ns:GetSelectedMainTab() or nil
    if selectedMainTab ~= "housing" then
        return false
    end

    local selectedSubTab = ns.GetSelectedSubTab and ns:GetSelectedSubTab(selectedMainTab) or nil
    return selectedSubTab == "endeavors"
end

function UI:CaptureCurrentHousingSnapshot(forceRefresh)
    if not forceRefresh and not self:IsHousingViewActive() then
        return nil
    end

    local currentCharacter = ns.GetCurrentCharacterInfo and ns:GetCurrentCharacterInfo() or nil
    if not currentCharacter then
        return nil
    end

    local view = buildHousingEndeavorsView(currentCharacter)
    return view and view.available and view or nil
end
