-- === Bags ===
hooksecurefunc("ContainerFrame_GenerateFrame", function()
    if BagItemAutoSortButton and BagItemSearchBox then
        BagItemAutoSortButton:Hide()
        -- prevent revivals
        BagItemAutoSortButton.Show = function() end
        BagItemSearchBox:SetWidth(124)
    end
end)

-- === Bank ===
local function HideBankCleanup()
    local panel = rawget(_G, "BankPanel")
    if panel and panel.AutoSortButton then
        panel.AutoSortButton:Hide()
        panel.AutoSortButton.Show = function() end -- nuke future Show() calls
        if BankItemSearchBox then
            BankItemSearchBox:ClearAllPoints()
            BankItemSearchBox:SetPoint("TOPRIGHT", panel, "TOPRIGHT", -15, -33)
        end
        return true
    end
end

local f = CreateFrame("Frame")
f:RegisterEvent("ADDON_LOADED")
f:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_SHOW") -- fires when talking to a banker
f:SetScript("OnEvent", function(self, event, ...)
    if event == "ADDON_LOADED" then
        local addon = ...
        if addon == "Blizzard_BankUI" then
            -- BankPanel now exists; hook its show
            if BankPanel then
                BankPanel:HookScript("OnShow", function() HideBankCleanup() end)
            end
            HideBankCleanup() -- in case it's already visible
        end
    elseif event == "PLAYER_INTERACTION_MANAGER_FRAME_SHOW" then
        local interactionType = ...
        if interactionType == Enum.PlayerInteractionType.Banker then
            HideBankCleanup()
        end
    end
end)
