---@class Moonwell
local Moonwell = QuestieLoader:CreateModule("Moonwell")

---@type l10n
local l10n = QuestieLoader:ImportModule("l10n")
---@type QuestieMap
local QuestieMap = QuestieLoader:ImportModule("QuestieMap")

--- COMPATIBILITY ---
local WOW_PROJECT_ID = QuestieCompat.WOW_PROJECT_ID
local WOW_PROJECT_BURNING_CRUSADE_CLASSIC = QuestieCompat.WOW_PROJECT_BURNING_CRUSADE_CLASSIC

---@type table<number, boolean>
Moonwell.dataClassic = {
    -- Teldrassil Moonwells
    [19549] = true, -- Shadowglen moonwell
    [19550] = true, -- Starbreeze Village moonwell
    [19551] = true, -- Pools of Arlithrien moonwell
    [19552] = true, -- Oracle Glade moonwell
    -- Ashenvale Moonwells
    [20806] = true, -- Central Ashenvale moonwell
    -- Felwood Moonwells
    [148501] = true, -- Felwood cave moonwell
    -- Darkshore Moonwells
    [174795] = true, -- Auberdine (Main moonwell)
    [175337] = true, -- Auberdine (Secondary moonwell)
    -- Moonglade Moonwells
    [400010] = true, -- Moonglade moonwell
    -- Generic/Multi-location Moonwells
    [177232] = true,
    [177272] = true,
    [177273] = true,
    [177274] = true,
    [177275] = true,
    [177276] = true,
    [177277] = true,
    [177278] = true,
    [177279] = true,
    [177280] = true,
    [177281] = true,
}

---@type table<number, boolean>
Moonwell.dataTBC = {
    [410021] = true, -- Cenarion Thicket moonwell
    [410022] = true, -- Evergrove moonwell
    [410023] = true, -- Ghostlands moonwell
}

local function _GetActiveMoonwellData()
    local data = {}
    for objectId in pairs(Moonwell.dataClassic) do
        data[objectId] = true
    end

    if WOW_PROJECT_ID >= WOW_PROJECT_BURNING_CRUSADE_CLASSIC then
        for objectId in pairs(Moonwell.dataTBC) do
            data[objectId] = true
        end
    end

    return data
end

function Moonwell:ShowMoonwell(objectID, icon, scale)
    icon = icon or "Interface\\Icons\\inv_fabric_moonrag_01.blp"
    scale = scale or 0.6
    local title = Questie:Colorize(l10n("Moonwell"), "white")
    QuestieMap:ShowObject(objectID, icon, scale, title, nil, true, "moonwell")
end

function Moonwell:ShowAll()
    for objectID in pairs(_GetActiveMoonwellData()) do
        Moonwell:ShowMoonwell(objectID)
    end
end

function Moonwell:HideAll()
    for objectID in pairs(_GetActiveMoonwellData()) do
        QuestieMap:UnloadManualFrames(objectID, "moonwell")
    end
end
