-- ============================================================
-- Komo Hold'Em — Sounds
-- All audio uses built-in Blizzard SOUNDKIT ids: nothing shipped.
-- /kh soundtest plays each with its name so kits can be auditioned
-- in-game and swapped by name.
-- ============================================================
local _, KH = ...
KH.Sounds = {}
local Sounds = KH.Sounds

-- Event name -> soundkit. Every entry guarded: SOUNDKIT constants
-- can shift between client versions, so a missing kit just skips.
local KIT = {
    -- in-hand
    CARD_DEAL    = SOUNDKIT.IG_ABILITY_PAGE_TURN,           -- quick page flick per card
    CARD_FLIP    = SOUNDKIT.IG_QUEST_LIST_OPEN,             -- showdown reveal
    CARD_FOLD    = SOUNDKIT.IG_QUEST_LIST_CLOSE,            -- soft muck
    CHIP_CALL    = SOUNDKIT.LOOT_WINDOW_COIN_SOUND,         -- check/call clink
    CHIP_RAISE   = SOUNDKIT.LOOT_WINDOW_COIN_SOUND,         -- raise (played twice, heavier)
    POT_WIN      = SOUNDKIT.LOOT_WINDOW_COIN_SOUND,         -- pot slides over

    -- turn flow
    YOUR_TURN    = SOUNDKIT.TELL_MESSAGE,                   -- whisper ping: cuts through gameplay
    TIMER_WARN   = SOUNDKIT.ALARM_CLOCK_WARNING_3,          -- last-seconds tick
    AUTO_FOLD    = SOUNDKIT.IG_QUEST_LOG_ABANDON_QUEST,     -- timer expired

    -- lobby / meta
    PLAYER_JOIN  = SOUNDKIT.IG_CHARACTER_INFO_OPEN,
    READY_CLICK  = SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON,
    UNREADY      = SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_OFF,
    GAME_START   = SOUNDKIT.GS_CHARACTER_SELECTION_ENTER_WORLD, -- shuffle-up whoosh (was READY_CHECK — confusing in raids)
    GOLD_NOTICE  = SOUNDKIT.RAID_WARNING,                   -- gold-stakes disclaimer shown
    DEBT_PAID    = SOUNDKIT.LOOT_WINDOW_COIN_SOUND,         -- settle-up mark paid
    UI_CLICK     = SOUNDKIT.GS_TITLE_OPTION_OK,
}

-- ordered list for the sound test
local TEST_ORDER = {
    "CARD_DEAL", "CARD_FLIP", "CARD_FOLD",
    "CHIP_CALL", "CHIP_RAISE", "POT_WIN",
    "YOUR_TURN", "TIMER_WARN", "AUTO_FOLD",
    "PLAYER_JOIN", "READY_CLICK", "UNREADY",
    "GAME_START", "GOLD_NOTICE", "DEBT_PAID", "UI_CLICK",
}

function Sounds:Play(name)
    if not KH.db.settings.sounds and name ~= "YOUR_TURN" then return end
    if name == "YOUR_TURN" and not KH.db.settings.turnAlert then return end
    local kit = KIT[name]
    if kit then
        PlaySound(kit)
        if name == "CHIP_RAISE" then
            C_Timer.After(0.12, function() PlaySound(kit) end)
        end
    end
end

-- /kh soundtest — plays every kit 1.5s apart, printing names,
-- so individual sounds can be swapped by name afterwards.
function Sounds:RunTest()
    KH:Print("Sound test — one every 1.5s. Note any you want swapped.")
    for i, name in ipairs(TEST_ORDER) do
        C_Timer.After((i - 1) * 1.5, function()
            local kit = KIT[name]
            if kit then
                PlaySound(kit)
                KH:Print(i .. "/" .. #TEST_ORDER .. "  " .. name)
            else
                KH:Print(i .. "/" .. #TEST_ORDER .. "  " .. name .. " |cfff08a80(kit missing on this client)|r")
            end
        end)
    end
end
