-- Rack & Ruin: Menu.lua
-- Main entry frame with slash command, launches Blackjack or Poker.

RackAndRuin = RackAndRuin or {}

local BORDER_COLOR = { 1, 0.55, 0.1 }

local menuFrame = CreateFrame("Frame", "RackAndRuinMenuFrame", UIParent, "BackdropTemplate")
menuFrame:SetSize(320, 520)
menuFrame:SetPoint("CENTER")
menuFrame:SetMovable(true)
menuFrame:EnableMouse(true)
menuFrame:RegisterForDrag("LeftButton")
menuFrame:SetScript("OnDragStart", menuFrame.StartMoving)
menuFrame:SetScript("OnDragStop", menuFrame.StopMovingOrSizing)
menuFrame:SetBackdrop({
    bgFile = "Interface\\Buttons\\WHITE8x8",
    edgeFile = "Interface\\Buttons\\WHITE8x8",
    edgeSize = 2,
})
menuFrame:SetBackdropColor(0, 0, 0, 0.95)
menuFrame:SetBackdropBorderColor(unpack(BORDER_COLOR))
menuFrame:SetFrameStrata("HIGH")
menuFrame:SetToplevel(true)
menuFrame:Hide()

local logo = menuFrame:CreateTexture(nil, "ARTWORK")
logo:SetSize(150, 150)
logo:SetPoint("TOP", 0, -24)
logo:SetTexture(RackAndRuin.GetLogoTexture())

local function StyledButton(parent, text, width)
    local btn = CreateFrame("Button", nil, parent, "BackdropTemplate")
    btn:SetSize(width or 220, 32)
    btn:SetBackdrop({
        bgFile = "Interface\\Buttons\\WHITE8x8",
        edgeFile = "Interface\\Buttons\\WHITE8x8",
        edgeSize = 1,
    })
    btn:SetBackdropColor(0, 0, 0, 1)
    btn:SetBackdropBorderColor(unpack(BORDER_COLOR))

    local label = btn:CreateFontString(nil, "OVERLAY", "GameFontNormal")
    label:SetPoint("CENTER")
    label:SetText(text)
    label:SetTextColor(1, 0.85, 0.6)
    btn.label = label

    btn:SetScript("OnEnter", function(self) self:SetBackdropColor(0.2, 0.1, 0, 1) end)
    btn:SetScript("OnLeave", function(self) self:SetBackdropColor(0, 0, 0, 1) end)

    return btn
end

local bjButton = StyledButton(menuFrame, "Blackjack")
bjButton:SetPoint("TOP", logo, "BOTTOM", 0, -16)
bjButton:SetScript("OnClick", function()
    menuFrame:Hide()
    RackAndRuin.ShowBlackjack()
end)

local pokerButton = StyledButton(menuFrame, "Poker")
pokerButton:SetPoint("TOP", bjButton, "BOTTOM", 0, -14)
pokerButton:SetScript("OnClick", function()
    menuFrame:Hide()
    RackAndRuin.ShowPoker()
end)

local rouletteButton = StyledButton(menuFrame, "Roulette")
rouletteButton:SetPoint("TOP", pokerButton, "BOTTOM", 0, -14)
rouletteButton:SetScript("OnClick", function()
    menuFrame:Hide()
    RackAndRuin.ShowRoulette()
end)

local dartsButton = StyledButton(menuFrame, "Darts")
dartsButton:SetPoint("TOP", rouletteButton, "BOTTOM", 0, -14)
dartsButton:SetScript("OnClick", function()
    menuFrame:Hide()
    RackAndRuin.ShowDarts()
end)

local lucky7Button = StyledButton(menuFrame, "Lucky 7")
lucky7Button:SetPoint("TOP", dartsButton, "BOTTOM", 0, -14)
lucky7Button:SetScript("OnClick", function()
    menuFrame:Hide()
    RackAndRuin.ShowLucky7()
end)

local closeButton = StyledButton(menuFrame, "Close", 100)
closeButton:SetPoint("TOP", lucky7Button, "BOTTOM", 0, -20)
closeButton:SetScript("OnClick", function() menuFrame:Hide() end)

function RackAndRuin.ShowMenu()
    menuFrame:Show()
end

RackAndRuin.MenuFrame = menuFrame

SLASH_RACKANDRUIN1 = "/rackandruin"
SLASH_RACKANDRUIN2 = "/rr"
SlashCmdList["RACKANDRUIN"] = function()
    RackAndRuin.ShowMenu()
end
