--[[
============================================================
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 = ...

-------------------------------------------------
-- Addon Globals
-------------------------------------------------

_G.DecorVendor = dv
_G.Decorvendor = dv
_G[addonName] = dv

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

-------------------------------------------------
-- Optional Addon Detection
-------------------------------------------------

local function IsLoaded(addon)
    if C_AddOns and C_AddOns.IsAddOnLoaded then
        return C_AddOns.IsAddOnLoaded(addon)
    end

    if IsAddOnLoaded then
        return IsAddOnLoaded(addon)
    end

    return false
end

hasTomTom = IsLoaded("TomTom")
hasWaypointUI = IsLoaded("WaypointUI")

-------------------------------------------------
-- Saved Variables
-------------------------------------------------

vendorSettings = vendorSettings or {
    useTomTom = true,
    scale = 1.0,
    closeOnEsc = true,
    showMinimapButton = true,
    showVendorCheckmarks = true,
    showMerchantCheckmarks = false,
    showWaypointButton = false,

    visited = {},
    completedAchievs = {},
    completedDrop = {},
    completedDropNoXP = {},

    markCompletedThings = false,
    markFoundVendors = false,
    hideCompletedThings = false,
    hideCollectedBossDrops = false,
    openAchievementFrame = true,
}

dbDV = dbDV or {}
dbDV.minimap = dbDV.minimap or { hide = false }

-------------------------------------------------
-- Runtime State
-------------------------------------------------

dv.searchQuery = dv.searchQuery or ""
dv.decorItem = dv.decorItem or {}

dv.waitingForMarketData = false
dv.catalogReady = false
dv.currentTab = dv.currentTab or "vendors"

vendorFilteredItems = vendorFilteredItems or {}
currentVendorPage = currentVendorPage or 1

dv.activeWowheadBox = dv.activeWowheadBox or nil
dv.collapsedHeaders = dv.collapsedHeaders or {}
dv.activeWidgets = dv.activeWidgets or {}
dv.questTitleCache = dv.questTitleCache or {}
dv.collectionCache = dv.collectionCache or {}

dv.vendorSessionCache = dv.vendorSessionCache or {}

-------------------------------------------------
-- Active Item Lookups
-------------------------------------------------

if dv.BuildActiveItemLookups then
    dv:BuildActiveItemLookups()
else
    print("|cffff4040DecorVendor:|r BuildActiveItemLookups is missing. Check Core\\ActiveItemLookups.lua load order.")
end