-- ============================================================
-- Decor Vendor Gallery
-- Constants.lua
-- Uses shared constants from DecorVendorData\SharedConstants.lua
-- ============================================================

local addonName, Gallery = ...

Gallery.C = Gallery.C or {}
local C = Gallery.C

local DVD = _G.DecorVendorData or _G.DecorVendor_Data
local Shared = DVD and DVD.Shared

Gallery.ActiveItems = DVD and DVD.ActiveItems or Gallery.ActiveItems or {}

-- Optional compatibility only
local dv = _G.DecorVendor or _G.Decorvendor
if dv then
    dv.Gallery = Gallery
end

-------------------------------------------------
-- Shared data constants
-------------------------------------------------

if Shared then
    C.CatalogSizing = Shared.CatalogSizing or C.CatalogSizing

    C.CARD_SIZE = (Shared.GalleryCard and Shared.GalleryCard.CARD_SIZE) or C.CARD_SIZE or 96
    C.CARD_GAP = (Shared.GalleryCard and Shared.GalleryCard.CARD_GAP) or C.CARD_GAP or 14
    C.GRID_PADDING = (Shared.GalleryCard and Shared.GalleryCard.GRID_PADDING) or C.GRID_PADDING or 18

    C.FILTER_SOURCE_OPTIONS = Shared.SourceFilterOptions or C.FILTER_SOURCE_OPTIONS
    C.SOURCE_LABELS = Shared.SourceLabels or C.SOURCE_LABELS
    C.SOURCE_ORDER = Shared.SourceOrder or C.SOURCE_ORDER

    C.SOURCE_ATLAS_ICONS = Shared.SourceAtlasIcons or C.SOURCE_ATLAS_ICONS or {}
    C.GOLD_ICON = Shared.GOLD_ICON or C.GOLD_ICON
    C.CURRENCY_ICONS = Shared.CurrencyIcons or C.CURRENCY_ICONS

    C.SOURCE_ACTIONS = Shared.SourceActions or C.SOURCE_ACTIONS or {}
    C.ExpansionColors = Shared.ExpansionColors or C.ExpansionColors

    -- Shared label colors/helpers
    C.LabelColors = Shared.LabelColors or C.LabelColors
    C.ColorizeLabel = Shared.ColorizeLabel or C.ColorizeLabel
else
    -------------------------------------------------
    -- Fallbacks if DecorVendorData is not loaded.
    -- You should normally use RequiredDeps: DecorVendorData.
    -------------------------------------------------

    C.CatalogSizing = C.CatalogSizing or {
        FrameWidth          = 1100,
        FrameHeight         = 750,
        SidebarWidth        = 200,
        FilterBarHeight     = 32,
        DetailPanelWidth    = 330,
        DropdownMaxHeight   = 400,
        ProgressBarHeight   = 10,
        GridItemSize        = 110,
        GridItemSpacing     = 10,
        GridColumns         = 4,
        GridRows            = 5,
        ItemsPerPage        = 20,
        SearchBoxWidth      = 260,
        ModelViewerHeight   = 240,
    }

    C.CARD_SIZE = C.CARD_SIZE or 96
    C.CARD_GAP = C.CARD_GAP or 14
    C.GRID_PADDING = C.GRID_PADDING or 18

    C.FILTER_SOURCE_OPTIONS = C.FILTER_SOURCE_OPTIONS or {
        { key = "all", text = "All Sources" },
        { key = "vendor", text = "Vendor" },
        { key = "shop", text = "In-Game Shop" },
        { key = "quest", text = "Quest" },
        { key = "achievement", text = "Achievement" },
        { key = "drop", text = "Drop" },
        { key = "promo", text = "Promo" },
        { key = "profession", text = "Profession" },
        { key = "catalog", text = "Housing Catalog" },
        { key = "unreleased", text = "Unreleased" },
        { key = "other", text = "Other" },
    }

    C.SOURCE_LABELS = C.SOURCE_LABELS or {
        all = "All Decor",
        vendor = "Vendor",
        shop = "In-Game Shop",
        quest = "Quest",
        achievement = "Achievement",
        drop = "Drop",
        promo = "Promo",
        profession = "Profession",
        catalog = "Housing Catalog",
        unreleased = "Unreleased",
        other = "Other",
        treasure = "Drop",
        boss = "Drop",
    }

    C.SOURCE_ORDER = C.SOURCE_ORDER or {
        "vendor",
        "shop",
        "quest",
        "achievement",
        "drop",
        "promo",
        "profession",
        "catalog",
        "unreleased",
        "other",
    }

    C.SOURCE_ATLAS_ICONS = C.SOURCE_ATLAS_ICONS or {
        shop = "hearthsteel-icon-32x32",
    }

    C.GOLD_ICON = C.GOLD_ICON or "Interface\\MoneyFrame\\UI-GoldIcon"
    C.CURRENCY_ICONS = C.CURRENCY_ICONS or {}
    C.SOURCE_ACTIONS = C.SOURCE_ACTIONS or {}
end

-- Absolute safety defaults.
C.CatalogSizing = C.CatalogSizing or {}
C.SOURCE_ATLAS_ICONS = C.SOURCE_ATLAS_ICONS or {}
C.CURRENCY_ICONS = C.CURRENCY_ICONS or {}
C.SOURCE_ACTIONS = C.SOURCE_ACTIONS or {}

C.LabelColors = C.LabelColors or {}

C.ColorizeLabel = C.ColorizeLabel or function(label, colorTable, key)
    label = tostring(label or "Unknown")
    key = key or label

    local hex =
        colorTable
        and (
            colorTable[key]
            or colorTable[string.lower(tostring(key))]
            or colorTable.unknown
            or colorTable.Unknown
        )
        or "888888"

    return "|cff" .. hex .. label .. "|r"
end
