--[[
============================================================
Decor Vendor Addon
© 2026 MidniteDestiny. All Rights Reserved.
============================================================

This file is part of the Decor Vendor addon.

All code, structure, and design are the intellectual
property of MidniteDestiny unless otherwise stated.

You may NOT:
• Copy, reproduce, or redistribute this code
• Modify and redistribute this code
• Use this code in other addons or projects

without explicit permission from the author.

This addon is distributed for personal use only.

============================================================
]]

local addonName, dv = ...

dv.CONSTANTS = dv.CONSTANTS or {}
local C = dv.CONSTANTS

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

-------------------------------------------------
-- Addon-local version/prefix
-------------------------------------------------

C.VERSION_TEXT = "Current Working Version %s"
C.VERSION = "2.03"

dv.ADDON_PREFIX = "|cff00ccff[Decor Vendor]|r "

-------------------------------------------------
-- Shared data constants from DecorVendorData
-------------------------------------------------

if Shared then
    dv.EXPANSION_ORDER = Shared.EXPANSION_ORDER or dv.EXPANSION_ORDER
    dv.rareEvents = Shared.RareEvents or dv.rareEvents
    dv.SOURCE_ACTIONS = Shared.SourceActions or dv.SOURCE_ACTIONS

    dv.Profession_Order = Shared.ProfessionOrder or dv.Profession_Order
    dv.ProfessionIcons = Shared.ProfessionIcons or dv.ProfessionIcons

    dv.reputationRanks = Shared.ReputationRanks or dv.reputationRanks
    dv.renownFactionIDs = Shared.RenownFactionIDs or dv.renownFactionIDs
    dv.subfactionIDs = Shared.SubfactionIDs or dv.subfactionIDs
    dv.subfactionRanks = Shared.SubfactionRanks or dv.subfactionRanks
    dv.friendshipRanks = Shared.FriendshipRanks or dv.friendshipRanks
    dv.friendshipFactionIDs = Shared.FriendshipFactionIDs or dv.friendshipFactionIDs

    dv.ExpansionColors = Shared.ExpansionColors or dv.ExpansionColors
    dv.ContinentExpansion = Shared.ContinentExpansion or dv.ContinentExpansion
    dv.ContinentColors = Shared.ContinentColors or dv.ContinentColors
    dv.ZidormiZones = Shared.ZidormiZones or dv.ZidormiZones

    dv.SourceIcons = Shared.SourceIcons or dv.SourceIcons
    dv.SourceColors = Shared.SourceColors or dv.SourceColors

    -- Shared label colors/helpers
    dv.LabelColors = Shared.LabelColors or dv.LabelColors
    dv.ColorizeLabel = Shared.ColorizeLabel or dv.ColorizeLabel

    C.COLORS = Shared.Colors or C.COLORS
    C.CAMERA = Shared.Camera or C.CAMERA
    C.SCENE_PRESETS = Shared.ScenePresets or C.SCENE_PRESETS
    C.DEFAULT_SCENE_ID = Shared.DefaultSceneID or C.DEFAULT_SCENE_ID
    C.MODEL_SCENE_ID = Shared.ModelSceneID or C.MODEL_SCENE_ID
    C.CatalogSizing = Shared.CatalogSizing or C.CatalogSizing
end

-------------------------------------------------
-- Fallbacks if DecorVendorData is not loaded.
-- You should normally use RequiredDeps: DecorVendorData.
-------------------------------------------------

dv.EXPANSION_ORDER = dv.EXPANSION_ORDER or {
    "Classic",
    "The Burning Crusade",
    "Wrath of the Lich King",
    "Cataclysm",
    "Mists of Pandaria",
    "Warlords of Draenor",
    "Legion",
    "Battle for Azeroth",
    "Shadowlands",
    "Dragonflight",
    "The War Within",
    "Midnight",
}

dv.rareEvents = dv.rareEvents or {}
dv.SOURCE_ACTIONS = dv.SOURCE_ACTIONS or {}

dv.Profession_Order = dv.Profession_Order or {
    "Alchemy",
    "Blacksmithing",
    "Cooking",
    "Enchanting",
    "Engineering",
    "Inscriptions",
    "Jewelcrafting",
    "Junkyard Tinkering",
    "Leatherworking",
    "Tailoring",
}

dv.reputationRanks = dv.reputationRanks or {
    [1] = "Neutral",
    [2] = "Friendly",
    [3] = "Honored",
    [4] = "Revered",
    [5] = "Exalted",
}

dv.renownFactionIDs = dv.renownFactionIDs or {}
dv.subfactionIDs = dv.subfactionIDs or {}
dv.subfactionRanks = dv.subfactionRanks or {}
dv.friendshipRanks = dv.friendshipRanks or {}
dv.friendshipFactionIDs = dv.friendshipFactionIDs or {}

-------------------------------------------------
-- Colors
-------------------------------------------------

C.COLORS = C.COLORS or {
    ALLIANCE = {0.3, 0.6, 1},
    HORDE = {1, 0.2, 0.2},
    NEUTRAL = {0.2, 0.8, 0.3},
    GOLD = {1, 0.82, 0},
    GOLD_DIM = { 0.8, 0.66, 0, 1 },
    TITLE = { 0.9, 0.85, 0.5, 1 },
    SIDEBAR_BG = { 0.05, 0.05, 0.08, 0.9 },
    CONTENT_BG = { 0, 0, 0, 0.8 },
    TAB_NORMAL = { 0.1, 0.1, 0.12, 0.8 },
    TAB_HOVER = { 0.15, 0.15, 0.17, 0.9 },
    TAB_SELECTED = { 0.12, 0.12, 0.14, 1 },
    TAB_TEXT_INACTIVE = { 0.56, 0.56, 0.56, 1 },
    TAB_ICON_ALPHA_INACTIVE = 0.75,
    TEXT_PRIMARY = { 1, 1, 1, 1 },
    TEXT_SECONDARY = { 0.9, 0.9, 0.9, 1 },
    TEXT_TERTIARY = { 0.7, 0.7, 0.7, 1 },
    TEXT_DISABLED = { 0.5, 0.5, 0.5, 1 },
    BORDER = { 0.3, 0.3, 0.3, 1 },
    PROGRESS_COMPLETE = { 0.2, 1, 0.2, 1 },
    PROGRESS_NEAR_COMPLETE = { 0.6, 0.9, 0.1, 1 },
    PROGRESS_MID = { 0.75, 0.65, 0.35, 1 },
    PROGRESS_LOW_DIM = { 0.6, 0.6, 0.6, 1 },
    PANEL_NORMAL = { 0.14, 0.14, 0.16, 0.9 },
    PANEL_HOVER = { 0.19, 0.19, 0.21, 1 },
    PANEL_NORMAL_ALT = { 0.12, 0.12, 0.14, 0.95 },
    PANEL_HOVER_ALT = { 0.16, 0.16, 0.18, 1 },
    ROW_BG = { 0.08, 0.08, 0.10, 0.9 },
    ROW_BG_SOLID = { 0.08, 0.08, 0.10, 1 },
    SOURCE_NAME_GOLD = { 0.92, 0.76, 0, 1 },
    ROW_SELECTED = { 0.20, 0.20, 0.22, 1 },
}

-------------------------------------------------
-- Spacing
-------------------------------------------------

local SharedSpacing = Shared and Shared.Spacing

C.SPACING_SMALL = C.SPACING_SMALL or (SharedSpacing and SharedSpacing.SMALL) or 4
C.SPACING_NORMAL = C.SPACING_NORMAL or (SharedSpacing and SharedSpacing.NORMAL) or 8
C.SPACING_LARGE = C.SPACING_LARGE or (SharedSpacing and SharedSpacing.LARGE) or 16

-------------------------------------------------
-- Camera / Scene
-------------------------------------------------

C.CAMERA = C.CAMERA or {
    TRANSITION_IMMEDIATE = CAMERA_TRANSITION_TYPE_IMMEDIATE or 1,
    MODIFICATION_DISCARD = CAMERA_MODIFICATION_TYPE_DISCARD or 1,
    MODIFICATION_MAINTAIN = CAMERA_MODIFICATION_TYPE_MAINTAIN or 1,
    ORBIT_MOUSE_NOTHING = ORBIT_CAMERA_MOUSE_MODE_NOTHING or 0,
    ORBIT_MOUSE_YAW = ORBIT_CAMERA_MOUSE_MODE_YAW_ROTATION or 1,
    ORBIT_MOUSE_PITCH = ORBIT_CAMERA_MOUSE_MODE_PITCH_ROTATION or 2,
    ORBIT_MOUSE_ZOOM = ORBIT_CAMERA_MOUSE_MODE_ZOOM or 6,
    ORBIT_MOUSE_PAN_HORIZONTAL = ORBIT_CAMERA_MOUSE_PAN_HORIZONTAL or 7,
    ORBIT_MOUSE_PAN_VERTICAL = ORBIT_CAMERA_MOUSE_PAN_VERTICAL or 8,
    PREVIEW_MIN_ZOOM_SCALE = 0.5,
    ROTATION_SPEED = 0.5,
    ZOOM_STEP = 0.02,
}

C.SCENE_PRESETS = C.SCENE_PRESETS or {
    [0]  = Enum and Enum.HousingCatalogEntryModelScenePresets and Enum.HousingCatalogEntryModelScenePresets.DecorDefault or 0,
    [65] = Enum and Enum.HousingCatalogEntryModelScenePresets and Enum.HousingCatalogEntryModelScenePresets.DecorTiny or 65,
    [66] = Enum and Enum.HousingCatalogEntryModelScenePresets and Enum.HousingCatalogEntryModelScenePresets.DecorSmall or 66,
    [67] = Enum and Enum.HousingCatalogEntryModelScenePresets and Enum.HousingCatalogEntryModelScenePresets.DecorMedium or 67,
    [68] = Enum and Enum.HousingCatalogEntryModelScenePresets and Enum.HousingCatalogEntryModelScenePresets.DecorLarge or 68,
    [69] = Enum and Enum.HousingCatalogEntryModelScenePresets and Enum.HousingCatalogEntryModelScenePresets.DecorHuge or 69,
}

C.DEFAULT_SCENE_ID =
    C.DEFAULT_SCENE_ID
    or (Enum and Enum.HousingCatalogEntryModelScenePresets and Enum.HousingCatalogEntryModelScenePresets.DecorDefault)
    or 0

C.MODEL_SCENE_ID = C.MODEL_SCENE_ID or 1317

-------------------------------------------------------------------------------
-- Shared Layout / Catalog-style UI Sizing
-------------------------------------------------------------------------------

C.CatalogSizing = C.CatalogSizing or {
    FrameWidth          = 1100,
    FrameHeight         = 750,

    SidebarWidth        = 200,
    DetailPanelWidth    = 330,
    BottomBarHeight     = 44,
    FilterBarHeight     = 32,

    ModelViewerHeight   = 240,

    DropdownMaxHeight   = 400,
    ProgressBarHeight   = 10,

    GridItemSize        = 110,
    GridItemSpacing     = 10,
    GridColumns         = 4,
    GridRows            = 5,
    ItemsPerPage        = 20,

    SearchBoxWidth      = 260,
}

local CatSizing = C.CatalogSizing
local LegacySizing = (Shared and Shared.LegacySizing) or {}

-------------------------------------------------------------------------------
-- Legacy aliases
-------------------------------------------------------------------------------

C.DEFAULT_FRAME_WIDTH  = CatSizing.FrameWidth
C.DEFAULT_FRAME_HEIGHT = CatSizing.FrameHeight
C.MIN_FRAME_WIDTH      = CatSizing.FrameWidth
C.MIN_FRAME_HEIGHT     = CatSizing.FrameHeight

C.SIDEBAR_WIDTH         = CatSizing.SidebarWidth
C.PREVIEW_WIDTH         = CatSizing.DetailPanelWidth
C.PREVIEW_DEFAULT_WIDTH = CatSizing.DetailPanelWidth

C.MODELCONTAINER_HEIGHT = CatSizing.ModelViewerHeight
C.SCROLLCHILD_WIDTH     = 1

C.SEARCHBOX_WIDTH       = CatSizing.SearchBoxWidth
C.SEARCHBOX_HEIGHT      = LegacySizing.SEARCHBOX_HEIGHT or 22

C.HEADER_HEIGHT         = LegacySizing.HEADER_HEIGHT or CatSizing.FilterBarHeight
C.TITLEBG_HEIGHT        = LegacySizing.TITLEBG_HEIGHT or CatSizing.FilterBarHeight

C.DIVIDER_HEIGHT        = LegacySizing.DIVIDER_HEIGHT or 2
C.TITLESEPERATOR_HEIGHT = LegacySizing.TITLESEPERATOR_HEIGHT or 2

C.VENDOR_HEADER_HEIGHT  = LegacySizing.VENDOR_HEADER_HEIGHT or 22
C.LINE_HEIGHT           = LegacySizing.LINE_HEIGHT or 20

C.RESETBTN_WIDTH        = LegacySizing.RESETBTN_WIDTH or 120
C.RESETBTN_HEIGHT       = LegacySizing.RESETBTN_HEIGHT or 22

C.RESETCACHE_WIDTH      = LegacySizing.RESETCACHE_WIDTH or 170
C.RESETCACHE_HEIGHT     = LegacySizing.RESETCACHE_HEIGHT or 22

C.INFOSIZE_WIDTH        = LegacySizing.INFOSIZE_WIDTH or 22
C.INFOSIZE_HEIGHT       = LegacySizing.INFOSIZE_HEIGHT or 22

C.CLOSE_WIDTH           = LegacySizing.CLOSE_WIDTH or 28
C.CLOSE_HEIGHT          = LegacySizing.CLOSE_HEIGHT or 28

C.CHECKTOGGLE_WIDTH     = LegacySizing.CHECKTOGGLE_WIDTH or 28
C.CHECKTOGGLE_HEIGHT    = LegacySizing.CHECKTOGGLE_HEIGHT or 28

C.PREVBTN_WIDTH         = LegacySizing.PREVBTN_WIDTH or 24
C.PREVBTN_HEIGHT        = LegacySizing.PREVBTN_HEIGHT or 24
C.NEXTBTN_WIDTH         = LegacySizing.NEXTBTN_WIDTH or 24
C.NEXTBTN_HEIGHT        = LegacySizing.NEXTBTN_HEIGHT or 24

C.RECIPEFRAME_WIDTH     = LegacySizing.RECIPEFRAME_WIDTH or 300
C.RECIPEFRAME_HEIGHT    = LegacySizing.RECIPEFRAME_HEIGHT or 40
C.RECIPEICON_WIDTH      = LegacySizing.RECIPEICON_WIDTH or 40
C.RECIPEICON_HEIGHT     = LegacySizing.RECIPEICON_HEIGHT or 40
C.RECIPETEXT_WIDTH      = LegacySizing.RECIPETEXT_WIDTH or 200

C.MODEL_ROTATION_SENSITIVITY = LegacySizing.MODEL_ROTATION_SENSITIVITY or 0.01
C.MODEL_ZOOM_SCALE           = LegacySizing.MODEL_ZOOM_SCALE or 1.2
C.MODEL_ZOOM_MIN             = LegacySizing.MODEL_ZOOM_MIN or 0.5
C.MODEL_ZOOM_MAX             = LegacySizing.MODEL_ZOOM_MAX or 3.0
C.MODEL_ZOOM_STEP            = LegacySizing.MODEL_ZOOM_STEP or 0.1
C.MODEL_VERTICAL_OFFSET      = LegacySizing.MODEL_VERTICAL_OFFSET or -0.1

-------------------------------------------------
-- Shared icon/color lookups
-------------------------------------------------

dv.SourceIcons = dv.SourceIcons or {}
dv.SourceColors = dv.SourceColors or {}
dv.ExpansionColors = dv.ExpansionColors or {}
dv.ContinentExpansion = dv.ContinentExpansion or {}
dv.ZidormiZones = dv.ZidormiZones or {}
dv.ContinentColors = dv.ContinentColors or {}
dv.ProfessionIcons = dv.ProfessionIcons or {}

dv.LabelColors = dv.LabelColors or {}

dv.ColorizeLabel = dv.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
