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

local frame = dv.frame

if not frame then
    print("|cffff4040DecorVendor Commands:|r dv.frame is missing. Make sure UI\\MainFrame.lua loads first.")
    return
end

-------------------------------------------------
-- Slash Commands
-------------------------------------------------

SLASH_DECORVENDOR1 = "/decor"
SLASH_DECORVENDOR2 = "/dv"
SLASH_DECORVENDOR3 = "/decorvendor"

SlashCmdList["DECORVENDOR"] = function()
    if frame and frame:IsShown() then
        frame:Hide()
    else
        if dv.OpenMainUI then
            dv.OpenMainUI()
        end
    end
end

-------------------------------------------------
-- Addon Compartment
-------------------------------------------------

function DecorVendor_OnAddonCompartmentClick(addonName, button)
    local mainAddon = _G.DecorVendor or _G.Decorvendor or dv
    local mainFrame = (mainAddon and mainAddon.frame) or frame or _G.DV_MainFrame

    if button == "LeftButton" then
        if mainFrame and mainFrame:IsShown() then
            mainFrame:Hide()
            return
        end

        -- Use the real opener so Home dashboard / hidden sidebar / content state works.
        if mainAddon and mainAddon.OpenMainUI then
            mainAddon.OpenMainUI()
            return
        end

        -- Fallback if OpenMainUI is missing.
        if mainFrame then
            mainFrame:Show()

            if mainAddon and mainAddon.ShowMainHomePanel then
                mainAddon.ShowMainHomePanel()
            elseif mainAddon and mainAddon.CreateMainHomePanel then
                mainAddon:CreateMainHomePanel(mainFrame)

                if mainFrame.homePanel then
                    mainFrame.homePanel:Show()
                end
            end

            return
        end

        print("|cffff4040Decor Vendor:|r Main frame is not loaded.")

    elseif button == "RightButton" then
        if Settings and mainAddon and mainAddon.optionsCategory then
            Settings.OpenToCategory(mainAddon.optionsCategory:GetID())
        elseif Settings and dv and dv.optionsCategory then
            Settings.OpenToCategory(dv.optionsCategory:GetID())
        end
    end
end

function DecorVendor_OnAddonCompartmentEnter(addonName, button)
    GameTooltip:SetOwner(button, "ANCHOR_LEFT")
    GameTooltip:SetText("Decor Vendor", 1, 0.82, 0)
    GameTooltip:AddLine("Left-click: Open Decor Vendor", 1, 1, 1)
    GameTooltip:AddLine("Right-click: Open Settings", 1, 1, 1)
    GameTooltip:Show()
end

function DecorVendor_OnAddonCompartmentLeave(addonName, button)
    GameTooltip:Hide()
end