local addonName, ZLAUTO = ...
local ZL = ZLAUTO.mainFrame
local ZLCreateFrame = ZL.ZLCreateFrame
local CreateEditBox = ZL.CreateEditBox
local CreateButton = ZL.CreateButton
local ScrollFrame_OnMouseWheel = ZL.ScrollFrame_OnMouseWheel
local GameTooltipShow = ZL.GameTooltipShow
local GameTooltipShowAnchor = ZL.GameTooltipShowAnchor
local GetClassColorName = ZL.GetClassColorName
local ParseClassColorName = ZL.ParseClassColorName
local cGetItemInfo = C_Item and C_Item.GetItemInfo or GetItemInfo
local cGetItemIcon = C_Item and C_Item.GetItemIconByID or GetItemIcon
local cGetItemInfoInstant = C_Item and C_Item.GetItemInfoInstant or GetItemInfoInstant


local subsidyParentTypeList = {
    "RL补", "T补", "N补", "DPS补", "食补", "工具人补", "其它补"
}
--双休T：T和DPS
--双休：DPS和N
local subsidyTypeList = {
    "RL", "T", "主T", "副T", "双休T", "N", "NQ", "DPS", "DPS1", "DPS2", "DPS3",
    "DPS4", "DPS5", "DPS6", "DPS7", "DPS8", "DPS9", "DPS10", "鱼", "猪", "修理机器人",
    "恶魔术", "战斗贼", "鸟德", "暗牧", "增强萨", "双休", "修星", "橙锤", "橙斧",
}

local function singleMoneyboxTextChanged(self)
    local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
    local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]
    local subsidyName = self:GetParent().subsidyName
    local text = self:GetText()
    if text and #text > 0 then
        local subsidyMoney
        if subsidyName == "RL" then
            subsidyMoney = text:match("(团双)")
            if not subsidyMoney then
                subsidyMoney = text:match("(%d+%%)")
                if not subsidyMoney then
                    subsidyMoney = tonumber(text:match("^(%d+)$"))
                end
            end
            subsidyMoney = subsidyMoney or 0
        else
            subsidyMoney = self:GetNumber()
        end
        subsidyData[subsidyName] = subsidyMoney
    end
    self:ClearFocus()
    ZL.SubsidyFrame:Update()
end

local subsidyTypeFunc = {
    ["RL"] = {
        icon = "|T132062:13|t",
        parentType = "RL补",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local tempList = {"固定", "团双", "提成"}
                local RL = select(4, ZL.GetWagesGroupMembers())
                if RL then
                    tinsert(menuList, {
                        text = RL,
                        checkable = 1,
                        checked = true,
                        func = function ()
                            
                        end,
                    })
                    tinsert(menuList, {isSeparator = true})
                end
                for _, value in ipairs(tempList) do
                    tinsert(menuList, {
                        text = value,
                        func = function ()
                            if value == "团双" then
                                local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                                local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]
                                local subsidyName = self:GetParent().subsidyName
                                subsidyData[subsidyName] = value
                                -- self.fontstring:SetText(value)
                                ZL.SubsidyFrame:Update()
                            end
                        end,
                        hasArrow = value ~= "团双" and true or false,
                        menuTable = function ()
                            local _menuList = {}
                            local _tempList
                            if value == "固定" then
                                _tempList = {100, 200, 500, 1000, 2000, 5000, 10000}
                            else
                                _tempList = {"1%", "2%", "3%", "4%", "5%"}
                            end
                            for _, _value in ipairs(_tempList) do
                                tinsert(_menuList, {
                                    text = _value,
                                    func = function ()
                                        local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                                        local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]
                                        local subsidyName = self:GetParent().subsidyName
                                        subsidyData[subsidyName] = _value
                                        -- self.fontstring:SetText(_value)
                                        ZL.SubsidyFrame:Update()
                                    end
                                })
                            end
                            return _menuList
                        end,
                    })
                end
                return menuList
            end
            ZL.GUI:ToggleMenu(self, tempfunc(self), 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
        toolTip = function (self)
            GameTooltipShow(self, "BOTTOMLEFT", "TOPRIGHT")
            GameTooltip:AddLine("团长补贴方式")
            GameTooltip:AddLine("固定：|cffffffff输入|r|cff4080FF不小于0的数|r")
            GameTooltip:AddLine("团双：|cffffffff输入|r|cff4080FF团双|r")
            GameTooltip:AddLine("提成：|cffffffff输入带%的数字，如|r|cff4080FF2%|r")
            GameTooltip:AddLine(" ")
            GameTooltip:AddLine("支持鼠标滚轮快速输入数字")
            GameTooltip:AddLine("手动输入需按|cff4080FFEnter|r或|cff4080FF右键|r保存！")
            GameTooltip:Show()
        end,
    },
    ["T"] = {
        icon = "|A:UI-LFG-RoleIcon-Tank:13:13|a",
        parentType = "T补",
    },
    ["主T"] = {
        icon = "|A:UI-LFG-RoleIcon-Tank:13:13|a",
        parentType = "T补",
    },
    ["副T"] = {
        icon = "|A:UI-LFG-RoleIcon-Tank:13:13|a",
        parentType = "T补",
    },
    ["双休T"] = {
        icon = "|A:UI-LFG-RoleIcon-Tank:13:13|a",
        parentType = "T补",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and
                            ZL_CURRENT.playerInfo[name]["T"] and ZL_CURRENT.playerInfo[name]["DPS"] then
                                tinsert(menuList, {
                                    text = colorName,
                                    checkable = 1,
                                    checked = true,
                                    isNotRadio = 1,
                                    func = function ()
                                        
                                    end,
                                })
                            end
                        end
                    end
                end
                return menuList
            end
            local menuList = tempfunc(self)
            if #menuList > 0 then
                tinsert(menuList, 1, {
                    text = "|A:UI-LFG-RoleIcon-Tank:13:13|a双休T：",
                    isTitle = true,
                })
            else
                tinsert(menuList, {
                    text = "没有数据",
                    isTitle = true,
                })
            end
            ZL.GUI:ToggleMenu(self, menuList, 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["N"] = {
        icon = "|A:UI-LFG-RoleIcon-Healer:13:13|a",
        parentType = "N补",
    },
    ["NQ"] = {
        icon = "|T135920:13|t",
        parentType = "N补",
    },
    ["DPS"] = {
        icon = "|A:UI-LFG-RoleIcon-DPS:13:13|a",
        parentType = "DPS补",

    },
    ["猪"] = {
        icon = "|T132184:13|t",
        parentType = "食补",
    },
    ["鱼"] = {
        icon = "|T237303:13|t",
        parentType = "食补",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                            and ZL_CURRENT.playerInfo[name]["鱼"] then
                                tinsert(menuList, {
                                    text = function ()
                                        local text = colorName .. " - " .. ZL_CURRENT.playerInfo[name].fishCount .. "次"
                                        if ZL_CURRENT.subsidyFishFirst == name then
                                            text = text .. " - First"
                                        end
                                        return text
                                    end,
                                    checkable = 1,
                                    checked = ZL_CURRENT.subsidyFishFirst == name,
                                    func = function ()
                                        ZL_CURRENT.subsidyFishFirst = name
                                        self:ClearFocus()
                                    end,
                                })
                            end
                        end
                    end
                end
                return menuList
            end
            local menuList = tempfunc(self)
            if #menuList > 0 then
                tinsert(menuList, 1, {
                    text = "|T237303:13|t鱼：",
                    isTitle = true,
                })
            else
                tinsert(menuList, {
                    text = "没有数据",
                    isTitle = true,
                })
            end
            ZL.GUI:ToggleMenu(self, menuList, 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["修理机器人"] = {
        icon = "|T132836:13|t",
        parentType = "其它补",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                            and ZL_CURRENT.playerInfo[name]["修理机器人"] then
                                tinsert(menuList, {
                                    text = function ()
                                        local text = colorName .. " - " .. ZL_CURRENT.playerInfo[name].xiuLiCount .. "次"
                                        if ZL_CURRENT.subsidyXiuLiFirst == name then
                                            text = text .. " - First"
                                        end
                                        return text
                                    end,
                                    checkable = 1,
                                    checked = ZL_CURRENT.subsidyXiuLiFirst == name,
                                    func = function ()
                                        ZL_CURRENT.subsidyXiuLiFirst = name
                                        self:ClearFocus()
                                    end,
                                })
                            end
                        end
                    end
                end
                return menuList
            end
            local menuList = tempfunc(self)
            if #menuList > 0 then
                tinsert(menuList, 1, {
                    text = "|T132836:13|t修理机器人：",
                    isTitle = true,
                })
            else
                tinsert(menuList, {
                    text = "没有数据",
                    isTitle = true,
                })
            end
            ZL.GUI:ToggleMenu(self, menuList, 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["恶魔术"] = {
        icon = "|T136172:13|t",
        parentType = "工具人补",
    },
    ["战斗贼"] = {
        icon = "|T132090:13|t",
        parentType = "工具人补",
    },
    ["鸟德"] = {
        icon = "|T136096:13|t",
        parentType = "工具人补",
    },
    ["暗牧"] = {
        icon = "|T136207:13|t",
        parentType = "工具人补",
    },
    ["增强萨"] = {
        icon = "|T136051:13|t",
        parentType = "工具人补",
    },
    ["双休"] = {
        icon = "|T236250:13|t",
        parentType = "N补",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and
                            ZL_CURRENT.playerInfo[name]["N"] and ZL_CURRENT.playerInfo[name]["DPS"] then
                                tinsert(menuList, {
                                    text = colorName,
                                    checkable = 1,
                                    checked = true,
                                    func = function ()
                                        
                                    end,
                                })
                            end
                        end
                    end
                end
                return menuList
            end
            local menuList = tempfunc(self)
            if #menuList > 0 then
                tinsert(menuList, 1, {
                    text = "T:13|t双休：",
                    isTitle = true,
                })
            else
                tinsert(menuList, {
                    text = "没有数据",
                    isTitle = true,
                })
            end
            ZL.GUI:ToggleMenu(self, menuList, 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["修星"] = {
        icon = "|T135753:13|t",
        parentType = "工具人补",
        OnLeftButtonMouseDown = function (self)
            local function tempfunc(self)
                local menuList = {}
                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    for _, data in ipairs(WagesGroupMembers) do
                        for _, colorName in ipairs(data) do
                            local name = ParseClassColorName(colorName)
                            if name and ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                            and ZL_CURRENT.playerInfo[name]["DPS"] then
                                tinsert(menuList, {
                                    text = colorName,
                                    checkable = 1,
                                    -- checked = 1,
                                    func = function ()
                                        
                                    end,
                                })
                            end
                        end
                    end
                end
                return menuList
            end
            local menuList = tempfunc(self)
            if #menuList > 0 then
                tinsert(menuList, 1, {
                    text = "|T135753:13|t修星：",
                    isTitle = true,
                })
            else
                tinsert(menuList, {
                    text = "没有数据",
                    isTitle = true,
                })
            end
            ZL.GUI:ToggleMenu(self, menuList, 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
        end,
    },
    ["橙锤"] = {
        icon = "|T253399:13|t",
        parentType = "其它补",
    },
    ["橙斧"] = {
        icon = "|T313914:13|t",
        parentType = "其它补",
    },
}

local talentInfo = {
    ["鲜血坦克"] = {"T"},
    ["冰霜"] = {"DPS"},
    ["邪恶"] = {"DPS"},
    ["野性坦克"] = {"T"},
    ["野性输出"] = {"DPS"},
    ["平衡"] = {"DPS", "鸟德"},
    ["恢复"] = {"N"},
    ["野兽控制"] = {"DPS"},
    ["射击"] = {"DPS"},
    ["生存"] = {"DPS"},
    ["奥术"] = {"DPS"},
    ["火焰"] = {"DPS"},
    ["神圣"] = {"N"},
    ["防护"] = {"T"},
    ["惩戒"] = {"DPS"},
    ["戒律"] = {"N"},
    ["暗影"] = {"DPS", "暗牧"},
    ["战斗"] = {"DPS", "战斗贼"},
    ["刺杀"] = {"DPS"},
    ["奇袭"] = {"DPS"},
    ["敏锐"] = {"DPS"},
    ["元素"] = {"DPS"},
    ["增强"] = {"DPS", "增强萨"},
    ["武器"] = {"DPS"},
    ["狂怒"] = {"DPS"},
    ["痛苦"] = {"DPS"},
    ["恶魔学识"] = {"DPS", "恶魔术"},
    ["毁灭"] = {"DPS"},
}

local function getSubsidyTypeFromTalentInfo(playerName, mainTalentName)
    if not mainTalentName then return end
    if talentInfo[mainTalentName] then
        for _, key in ipairs(talentInfo[mainTalentName]) do
            ZL_CURRENT.playerInfo = ZL_CURRENT.playerInfo or {}
            ZL_CURRENT.playerInfo[playerName] = ZL_CURRENT.playerInfo[playerName] or {}
            local playerData = ZL_CURRENT.playerInfo[playerName]
            playerData[key] = true
            if playerData["T"] and playerData["DPS"] then
                playerData["双休T"] = true
            elseif playerData["N"] and playerData["DPS"] then
                playerData["双休"] = true
            end
        end
    end
end

local function canInspect(unit)
    if not unit or UnitIsDeadOrGhost("player") or UnitIsDeadOrGhost(unit) or InCombatLockdown()
    or not CheckInteractDistance(unit, 1) or not CanInspect(unit) then
        return false
    end
    return true
end

local function getSubsidyProfileDropdownList()
    local subsidyProfileDropdownList = {}
    for index, profileName in ipairs(ZL.opt.subsidyProfileList.profileKeys) do
        tinsert(subsidyProfileDropdownList, {text=profileName, value=index})
    end
    return subsidyProfileDropdownList
end
function ZL:CreateSubsidyFrame()
    ZL.opt.subsidyProfileList = ZL.opt.subsidyProfileList or {
        ["profileKeys"] = {"默认"},
        ["profile"] = {
            ["默认"] = {
                ["RL"] = 0, ["T"] = 0, ["N"] = 0, ["DPS"] = 0,
            }
        }
    }
    ZL.SubsidyFrame = ZLCreateFrame("ZLSubsidyFrame", ZL, nil, nil, nil, true, true, "补贴设置")
    local SubsidyFrame = ZL.SubsidyFrame
    SubsidyFrame:Hide()
    SubsidyFrame:SetScript("OnMouseUp", function (self)
        self:StopMovingOrSizing()
        if not ZL.glb.ZLSubsidyFrame then ZL.glb.ZLSubsidyFrame = {} end
        ZL.glb.ZLSubsidyFrame.point, _, ZL.glb.ZLSubsidyFrame.relative, ZL.glb.ZLSubsidyFrame.x, ZL.glb.ZLSubsidyFrame.y = self:GetPoint()
    end)
    SubsidyFrame:SetScript("OnMouseDown", function (self)
        self:StartMoving()
    end)
    SubsidyFrame:SetScript("OnShow", function (self)
        SubsidyFrame:Update()
    end)
    local resizeButton = SubsidyFrame.resizeButton
    -- 设置鼠标按下时开始调整大小
    resizeButton:SetScript("OnMouseDown", function(self, button)
        if button == "LeftButton" then
            SubsidyFrame:StartSizing("BOTTOMRIGHT")
        end
    end)
    -- 鼠标松开时停止调整大小
    resizeButton:SetScript("OnMouseUp", function(self, button)
        SubsidyFrame:StopMovingOrSizing()
        ZL.db.global.ZLSubsidyFrame = ZL.db.global.ZLSubsidyFrame or {}
        ZL.db.global.ZLSubsidyFrame.Width,  ZL.db.global.ZLSubsidyFrame.Height= SubsidyFrame:GetSize()
    end)
    SubsidyFrame:ClearAllPoints()
    if ZL.glb.ZLSubsidyFrame and ZL.glb.ZLSubsidyFrame.point then
        SubsidyFrame:SetPoint(ZL.glb.ZLSubsidyFrame.point, UIParent, ZL.glb.ZLSubsidyFrame.relative, ZL.glb.ZLSubsidyFrame.x, ZL.glb.ZLSubsidyFrame.y)
    else
        SubsidyFrame:SetPoint("CENTER")
    end

    local subsidyTypeWidth, singleMoneyWidth, meetMembersWidth, actualMembersWidth, totalMoneyWidth, delWidth = 100, 80, 80, 80, 100, 20
    local totalWidth = subsidyTypeWidth + singleMoneyWidth + meetMembersWidth + actualMembersWidth + totalMoneyWidth + delWidth + 26
    SubsidyFrame:SetResizeBounds(totalWidth, 350, totalWidth, GetScreenHeight()-110)
    SubsidyFrame:SetWidth(totalWidth)
    if ZL.db.global.ZLSubsidyFrame and ZL.db.global.ZLSubsidyFrame.Height then
        SubsidyFrame:SetHeight(ZL.db.global.ZLSubsidyFrame.Height)
    end

    local lineHeight = 20
    local selectProfileFontString = SubsidyFrame:CreateFontString(nil, "OVERLAY")
    selectProfileFontString:SetPoint("TOPLEFT", SubsidyFrame.TitleBottom, "BOTTOMLEFT", 5, -8)
    selectProfileFontString:SetHeight(24)
    selectProfileFontString:SetFont(GameFontNormal:GetFont(), 14, "OUTLINE")
    selectProfileFontString:SetWordWrap(false)
    selectProfileFontString:SetJustifyH("LEFT")
    selectProfileFontString:SetTextColor(1, 0.82, 0, 1)
    selectProfileFontString:SetText("当前：")
    SubsidyFrame.historyProfileDropdown = CreateFrame("Button", nil, SubsidyFrame)
    local historyProfileDropdown = SubsidyFrame.historyProfileDropdown
    historyProfileDropdown:SetPoint("LEFT", selectProfileFontString, "RIGHT", 5, 0)
    historyProfileDropdown:SetSize(150, 24)
    ZL.GUI:GetClass('Dropdown'):Bind(historyProfileDropdown)
    historyProfileDropdown:SetMenuTable(getSubsidyProfileDropdownList())
    historyProfileDropdown:SetValue(ZL.opt.subsidyProfileSelect)
    historyProfileDropdown:SetCallback('OnSelectChanged', function (self)
        ZL.opt.subsidyProfileSelect = self.value
        SubsidyFrame:Update()
    end)
    SubsidyFrame.delProfileBtn = CreateButton(nil, SubsidyFrame, "删除", "LEFT", historyProfileDropdown, "RIGHT", 5, 0, 50, 24)
    local delProfileBtn = SubsidyFrame.delProfileBtn
    delProfileBtn:SetScript("OnClick", function (self)
        local profileName = historyProfileDropdown:GetText()
        if profileName == "默认" then
            ZL.Print("|cffff0000【默认】|r配置不可删除！")
            return
        end
        for index, value in ipairs(ZL.opt.subsidyProfileList["profileKeys"]) do
            if value == profileName then
                tremove(ZL.opt.subsidyProfileList["profileKeys"], index)
            end
        end
        ZL.opt.subsidyProfileList["profile"][profileName] = nil
        historyProfileDropdown:SetMenuTable(getSubsidyProfileDropdownList())
        ZL.opt.subsidyProfileSelect = 1
        historyProfileDropdown:SetValue(ZL.opt.subsidyProfileSelect)
        ZL.Print("已删除：|cffff0000【" .. profileName .. "】|r配置")
    end)
    SubsidyFrame.refreshBtn = CreateButton(nil, SubsidyFrame, "刷新天赋", "LEFT", delProfileBtn, "RIGHT", 5, 0, 80, 24)
    local refreshBtn = SubsidyFrame.refreshBtn
    refreshBtn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
    refreshBtn:SetScript("OnClick", function (self, button)
        if IsInRaid(1) then
            if button == "LeftButton" then
                self:Disable()
                local i = 1
                local delay
                local function tempfunc()
                    if i <= MAX_RAID_MEMBERS then
                        local name, _, _, _, _, fileName = GetRaidRosterInfo(i)
                        if name then
                            if canInspect(name) then
                                if ZL.inspectUnit == true then
                                    ZL.inspectUnit = nil
                                    i = i + 1
                                    delay = 0
                                else
                                    ZL.inspectUnit = name
                                    NotifyInspect(name)
                                    delay = 0.2
                                end
                            else
                                i = i + 1
                                delay = 0
                                print(GetClassColorName(name, fileName) .. "获取天赋信息|cffff0000失败|r。")
                            end
                        else
                            i = i + 1
                            delay = 0
                        end
                        C_Timer.After(delay, tempfunc)
                    else
                        self:Enable()
                        ZL.Print("天赋信息更新完成！", true)
                    end
                end
                tempfunc()
            elseif button == "RightButton" then
                local function tempfunc()
                    local function getPlayerTalent(colorName)
                        C_Timer.NewTicker(0.2, function (self)
                            local name = ParseClassColorName(colorName)
                            if canInspect(name) then
                                if ZL.inspectUnit == true then
                                    ZL.Print(colorName .. "天赋信息已更新。")
                                    ZL.inspectUnit = nil
                                    self:Cancel()
                                else
                                    ZL.inspectUnit = name
                                    NotifyInspect(name)
                                end
                            else
                                ZL.Print(colorName .. "获取天赋信息|cffff0000失败|r。")
                                self:Cancel()
                            end
                        end)
                    end
                    local menuList = {
                        {
                            text = "重置团队天赋信息",
                            func = function ()
                                ZL_CURRENT.playerInfo = {}
                                self:Click()
                            end
                        },
                        {isSeparator = true},
                    }
                    local WagesGroupMembers = ZL.GetWagesGroupMembers()
                    if WagesGroupMembers then
                        for _, data in ipairs(WagesGroupMembers) do
                            for _, colorName in ipairs(data) do
                                local name = ParseClassColorName(colorName)
                                local text = colorName
                                if ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name] and ZL_CURRENT.playerInfo[name].talentName then
                                    for key, value in pairs(ZL_CURRENT.playerInfo[name].talentName) do
                                        text = text .. " - |T" .. value .. ":12|t" .. key
                                    end
                                end
                                tinsert(menuList, {
                                    text = text,
                                    hasArrow = 1,
                                    menuTable = {
                                        {
                                            text = "刷新天赋",
                                            func = function ()
                                                getPlayerTalent(colorName)
                                                ZL.GUI:CloseMenu()
                                            end,
                                        },
                                        {
                                            text = "重置天赋",
                                            func = function ()
                                                ZL_CURRENT.playerInfo[name] = nil
                                                getPlayerTalent(colorName)
                                                ZL.GUI:CloseMenu()
                                            end,
                                        },
                                    },
                                })
                            end
                        end
                    end
                    return menuList
                end
                ZL.GUI:ToggleMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT")
            end
        else
            ZL.Print("不在团队中！")
        end
    end)
    refreshBtn:SetScript("OnEnter", function (self)
        GameTooltipShow(self, "BOTTOMLEFT", "TOPRIGHT")
        GameTooltip:AddLine("功能")
        GameTooltip:AddLine("左键：|cffffffff更新全团天赋|r")
        GameTooltip:AddLine("右键：|cffffffff更多功能|r")
        GameTooltip:Show()
    end)
    refreshBtn:SetScript("OnLeave", function (self)
        GameTooltip:Hide()
    end)
    local saveProfileFontString = SubsidyFrame:CreateFontString(nil, "OVERLAY")
    saveProfileFontString:SetPoint("TOPLEFT", selectProfileFontString, "BOTTOMLEFT", 0, -5)
    saveProfileFontString:SetHeight(24)
    saveProfileFontString:SetFont(GameFontNormal:GetFont(), 14, "OUTLINE")
    saveProfileFontString:SetWordWrap(false)
    saveProfileFontString:SetJustifyH("LEFT")
    saveProfileFontString:SetTextColor(1, 0.82, 0, 1)
    saveProfileFontString:SetText("新建：")
    local function saveProfileName()
        local profileName = SubsidyFrame.saveProfileEditBox:GetText()
        local isExist
        for _, value in ipairs(ZL.opt.subsidyProfileList["profileKeys"]) do
            if value == profileName then
                isExist = true
                break
            end
        end
        if isExist then
            ZL.Print("配置名称已存在，请重新输入！")
        else
            ZL.opt.subsidyProfileList["profile"][profileName] = {}
            for _, f in ipairs(SubsidyFrame.entries) do
                if f:IsShown() then
                    ZL.opt.subsidyProfileList["profile"][profileName][f.subsidyName] = f.subsidyMoney
                end
            end
            tinsert(ZL.opt.subsidyProfileList["profileKeys"], profileName)
            historyProfileDropdown:SetMenuTable(getSubsidyProfileDropdownList())
            ZL.opt.subsidyProfileSelect = #ZL.opt.subsidyProfileList["profileKeys"]
            historyProfileDropdown:SetValue(ZL.opt.subsidyProfileSelect)
            SubsidyFrame.saveProfileEditBox:SetText("")
            SubsidyFrame.saveProfileEditBox:ClearFocus()
            ZL.Print("已创建新的配置文件：|cffffffff" .. profileName .. "|r")
        end
    end
    local saveProfileEditBoxWidth = selectProfileFontString:GetWidth() + historyProfileDropdown:GetWidth() - saveProfileFontString:GetWidth()
    SubsidyFrame.saveProfileEditBox = CreateEditBox(SubsidyFrame, saveProfileEditBoxWidth, 24, 14, "RIGHT")
    local saveProfileEditBox = SubsidyFrame.saveProfileEditBox
    saveProfileEditBox:SetPoint("LEFT", saveProfileFontString, "RIGHT", 5, 0)
    saveProfileEditBox:SetScript("OnTextChanged", function (self)
        if #self:GetText() > 0 then
            SubsidyFrame.saveProfileBtn:Enable()
        else
            SubsidyFrame.saveProfileBtn:Disable()
        end
    end)
    saveProfileEditBox:SetScript("OnEnterPressed", function (self)
        if #self:GetText() > 0 then
            saveProfileName()
        end
    end)
    SubsidyFrame.saveProfileBtn = CreateButton(nil, SubsidyFrame, "保存", "LEFT", saveProfileEditBox, "RIGHT", 5, 0, 50, 24)
    local saveProfileBtn = SubsidyFrame.saveProfileBtn
    saveProfileBtn:Disable()
    saveProfileBtn:SetScript("OnClick", function (self)
        saveProfileName()
    end)

    SubsidyFrame.addBtn = CreateButton(nil, SubsidyFrame, "补贴类型", "LEFT", saveProfileBtn, "RIGHT", 5, 0, 80, 24)
    local addBtn = SubsidyFrame.addBtn
    addBtn:SetScript("OnClick", function (self)
        local function tempfunc()
            local menuList = {}
            local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
            local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]
            for _, subsidyName in ipairs(subsidyTypeList) do
                local subsidyNameGsub = subsidyName:gsub("%d+", "")
                if subsidyName == "主T" or subsidyName == "副T" or subsidyName == "双休T" then
                    subsidyNameGsub = "T"
                end
                local icon = subsidyTypeFunc[subsidyNameGsub].icon or "|T:13|t"
                tinsert(menuList, {
                    text = icon .. subsidyName,
                    checkable = 1,
                    isNotRadio = 1,
                    checked = subsidyData[subsidyName],
                    keepShownOnClick = 1,
                    func = function ()
                        if subsidyData[subsidyName] then
                            subsidyData[subsidyName] = nil
                        else
                            subsidyData[subsidyName] = 0
                            if subsidyName == "鱼" then
                                subsidyData["猪"] = nil
                            elseif subsidyName == "猪" then
                                subsidyData["鱼"] = nil
                            elseif subsidyName == "DPS" then
                                for i = 1, 10 do
                                    subsidyData["DPS" .. i] = nil
                                end
                            elseif subsidyName:match("^DPS%d+$") then
                                subsidyData["DPS"] = nil
                            -- elseif subsidyName == "T" then
                            --     subsidyData["主T"] = nil
                            --     subsidyData["副T"] = nil
                            --     subsidyData["双休T"] = nil
                            -- elseif subsidyName == "主T" or subsidyName == "副T" or subsidyName == "双休T" then
                            --     subsidyData["T"] = nil
                            end
                        end
                        SubsidyFrame:Update()
                        ZL.GUI:OpenMenu(self, tempfunc(), "TOPLEFT", self, "TOPRIGHT", 0, 0)
                    end
                })
            end
            return menuList
        end
        ZL.GUI:ToggleMenu(self, tempfunc(), "TOPLEFT", self, "TOPRIGHT", 0, 0)
    end)

    local btnTexture = [[Interface\ACHIEVEMENTFRAME\UI-Achievement-Parchment-Horizontal]] -------------
    SubsidyFrame.subsidyTypeBtn = CreateButton(nil, SubsidyFrame, "补贴类型", "TOPLEFT", saveProfileFontString, "BOTTOMLEFT", 0, -5, subsidyTypeWidth)
    local subsidyTypeBtn = SubsidyFrame.subsidyTypeBtn
    subsidyTypeBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    subsidyTypeBtn:SetNormalTexture(btnTexture)
    subsidyTypeBtn:ClearHighlightTexture()

    SubsidyFrame.singleMoneyBtn = CreateButton(nil, SubsidyFrame, "单个补贴", "LEFT", subsidyTypeBtn, "RIGHT", 0, 0, singleMoneyWidth)
    local singleMoneyBtn = SubsidyFrame.singleMoneyBtn
    singleMoneyBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    singleMoneyBtn:SetNormalTexture(btnTexture)
    singleMoneyBtn:ClearHighlightTexture()

    SubsidyFrame.meetMembersBtn = CreateButton(nil, SubsidyFrame, "符合人数", "LEFT", singleMoneyBtn, "RIGHT", 0, 0, meetMembersWidth)
    local meetMembersBtn = SubsidyFrame.meetMembersBtn
    meetMembersBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    meetMembersBtn:SetNormalTexture(btnTexture)
    meetMembersBtn:ClearHighlightTexture()

    SubsidyFrame.actualMembersBtn = CreateButton(nil, SubsidyFrame, "实际人数", "LEFT", meetMembersBtn, "RIGHT", 0, 0, actualMembersWidth)
    local actualMembersBtn = SubsidyFrame.actualMembersBtn
    actualMembersBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    actualMembersBtn:SetNormalTexture(btnTexture)
    actualMembersBtn:ClearHighlightTexture()

    SubsidyFrame.totalMoneyBtn = CreateButton(nil, SubsidyFrame, "合计补贴", "LEFT", actualMembersBtn, "RIGHT", 0, 0, totalMoneyWidth)
    local totalMoneyBtn = SubsidyFrame.totalMoneyBtn
    totalMoneyBtn:GetFontString():SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
    totalMoneyBtn:SetNormalTexture(btnTexture)
    totalMoneyBtn:ClearHighlightTexture()

    --创建滚动条
    SubsidyFrame.scrollFrame = CreateFrame("ScrollFrame", nil, SubsidyFrame, "UIPanelScrollFrameTemplate")
    SubsidyFrame.scrollFrame:SetFrameLevel(SubsidyFrame:GetFrameLevel() + 1) -- 设置为比父框架高1级
    SubsidyFrame.scrollFrame:SetPoint("TOPLEFT", subsidyTypeBtn, "BOTTOMLEFT", -3, 0)
    SubsidyFrame.scrollFrame:SetPoint("BOTTOMRIGHT", SubsidyFrame, "BOTTOMRIGHT", 0, 3)
    SubsidyFrame.scrollFrame:SetClipsChildren(true) --必须设置为true，scrollFrame所有的子元素才会被剪切
    SubsidyFrame.scrollFrame:SetScript("OnMouseWheel", ScrollFrame_OnMouseWheel) --重设滑动条鼠标滚轮事件
    --重设ScrollBar位置，放置到scrollFrame内，防止被剪切掉
    SubsidyFrame.scrollFrame.ScrollBar:ClearAllPoints()
    SubsidyFrame.scrollFrame.ScrollBar:SetPoint("TOPLEFT", SubsidyFrame.scrollFrame, "TOPRIGHT", -20, -17)
    SubsidyFrame.scrollFrame.ScrollBar:SetPoint("BOTTOMRIGHT", SubsidyFrame.scrollFrame, "BOTTOMRIGHT", 0, 16)
    SubsidyFrame.scrollFrame.content = CreateFrame("Frame", nil, SubsidyFrame.scrollFrame)
    local content = SubsidyFrame.scrollFrame.content
    content:SetPoint("TOPLEFT", SubsidyFrame.scrollFrame, "TOPLEFT", 0, 0)
    content:SetSize(SubsidyFrame.scrollFrame:GetWidth()-20, 100)
    SubsidyFrame.scrollFrame:SetScrollChild(content)
    SubsidyFrame.scrollFrame.ScrollBar:SetFrameLevel(content:GetFrameLevel()+100)

    local function OnEnter(self)
        self:GetParent():SetNormalTexture("Interface\\FriendsFrame\\UI-FriendsFrame-HighlightBar")
    end
    local function OnLeave(self)
        self:GetParent():ClearNormalTexture()
    end
    local board_r, board_g, board_b, board_a = 0.24, 0.25, 0.3, 1
    SubsidyFrame.entries = setmetatable({}, {
        __index = function (t, v)
            local f = CreateFrame("Button", nil, content)
            f:Hide()
            f:SetSize(totalWidth-26, lineHeight)
            if v == 1 then
                f:SetPoint("TOPLEFT", content, "TOPLEFT", 3, -1)
            else
                f:SetPoint("TOPLEFT", t[v-1], "BOTTOMLEFT")
            end
            f.Background = f:CreateTexture(nil,"BACKGROUND")
            f.Background:SetPoint("TOPLEFT")
            f.Background:SetPoint("BOTTOMRIGHT")
            f.Background:SetColorTexture(0.15, 0.15, 0.15, 1)
            f:SetScript("OnEnter", function (self)
                self:SetNormalTexture("Interface\\FriendsFrame\\UI-FriendsFrame-HighlightBar")
            end)
            f:SetScript("OnLeave", function (self)
                self:ClearNormalTexture()
            end)
            f.subsidyTypebox = CreateEditBox(f, subsidyTypeWidth, lineHeight, 13, "CENTER", nil, nil, board_r, board_g, board_b, board_a, "SubsidyFrameSubsidyTypeAddBoxChild" .. v)
            f.subsidyTypebox:SetPoint("LEFT", f, "LEFT", 0, 0)
            f.subsidyTypebox.Background:SetColorTexture(0,0,0,0)
            f.subsidyTypebox.fontstring = f.subsidyTypebox:CreateFontString(nil, "OVERLAY")
            f.subsidyTypebox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.subsidyTypebox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.subsidyTypebox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.subsidyTypebox.fontstring:SetWordWrap(false)
            f.subsidyTypebox.fontstring:SetJustifyH("LEFT")
            f.subsidyTypebox.fontstring:SetJustifyV("MIDDLE")
            f.subsidyTypebox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.subsidyTypebox:Disable()
            f.subsidyTypebox:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.subsidyTypebox:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)
            f.subsidyTypebox:SetScript("OnMouseDown", function (self, button)
                local function tempfunc()
                    local menuList = {}
                    local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                    local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]
                    local currentSubsidyName = self:GetParent().subsidyName
                    for _, subsidyName in ipairs(subsidyTypeList) do
                        if not subsidyData[subsidyName] then
                            local subsidyNameGsub = subsidyName:gsub("%d+", "")
                            if subsidyName == "主T" or subsidyName == "副T" or subsidyName == "双休T" then
                                subsidyNameGsub = "T"
                            end
                            local icon = subsidyTypeFunc[subsidyNameGsub].icon or "|T:13|t"
                            tinsert(menuList, {
                                text = icon .. subsidyName,
                                func = function ()
                                    subsidyData[subsidyName] = subsidyData[currentSubsidyName]
                                    subsidyData[currentSubsidyName] = nil
                                    if subsidyName == "鱼" then
                                        subsidyData["猪"] = nil
                                    elseif subsidyName == "猪" then
                                        subsidyData["鱼"] = nil
                                    elseif subsidyName == "DPS" then
                                        for i = 1, 10 do
                                            subsidyData["DPS" .. i] = nil
                                        end
                                    elseif subsidyName:match("^DPS%d+$") then
                                        subsidyData["DPS"] = nil
                                    -- elseif subsidyName == "T" then
                                    --     subsidyData["主T"] = nil
                                    --     subsidyData["副T"] = nil
                                    --     subsidyData["双休T"] = nil
                                    -- elseif subsidyName == "主T" or subsidyName == "副T" or subsidyName == "双休T" then
                                    --     subsidyData["T"] = nil
                                    end
                                    SubsidyFrame:Update()
                                end
                            })
                        end
                    end
                    return menuList
                end
                ZL.GUI:ToggleMenu(self, tempfunc(), "TOPLEFT", self, "BOTTOMRIGHT", 0, 0)
            end)

            f.singleMoneybox = CreateEditBox(f, singleMoneyWidth, lineHeight, 13, "CENTER", nil, nil, board_r, board_g, board_b, board_a, "SubsidyFrameSingleMoneyAddBoxChild" .. v)
            f.singleMoneybox:SetPoint("LEFT", f.subsidyTypebox, "RIGHT", 0, 0)
            f.singleMoneybox.Background:SetColorTexture(0,0,0,0)
            f.singleMoneybox.fontstring = f.singleMoneybox:CreateFontString(nil, "OVERLAY")
            f.singleMoneybox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.singleMoneybox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.singleMoneybox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.singleMoneybox.fontstring:SetWordWrap(false)
            f.singleMoneybox.fontstring:SetJustifyH("RIGHT")
            f.singleMoneybox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.singleMoneybox:SetScript("OnLeave", function(self)
                OnLeave(self)
                GameTooltip:Hide()
            end)
            f.singleMoneybox:SetScript("OnEditFocusGained", function (self)
                self.fontstring:Hide()
                local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]
                local subsidyName = f.subsidyName
                self:SetText(subsidyData[subsidyName])
                self:HighlightText()
            end)
            f.singleMoneybox:SetScript("OnEditFocusLost", function (self)
                self.fontstring:Show()
                local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]
                local subsidyName = f.subsidyName
                self.fontstring:SetText(subsidyData[subsidyName])
                self:SetText("")
                self:HighlightText(0, 0)
            end)
            f.singleMoneybox:SetScript("OnMouseWheel", function(self, delta)
                if self:HasFocus() then
                    local number = self:GetNumber()
                    if delta > 0 then
                        number = number + 100
                    else
                        number = number - 100
                    end
                    if number < 0 then
                        number = 0
                    end
                    self:SetNumber(number)
                end
            end)
            f.singleMoneybox:SetScript("OnEnterPressed", function (self)
                singleMoneyboxTextChanged(self)
            end)
            f.singleMoneybox:SetScript("OnMouseDown", function (self, button)
                if button == "RightButton"  and self:HasFocus() then
                    C_Timer.After(0.5, function ()
                        singleMoneyboxTextChanged(self)
                    end)
                end
            end)

            f.meetMembersbox = CreateEditBox(f, meetMembersWidth, lineHeight, 13, "CENTER", nil, nil, board_r, board_g, board_b, board_a, "SubsidyFramemeetMembersAddBoxChild" .. v)
            f.meetMembersbox:SetPoint("LEFT", f.singleMoneybox, "RIGHT", 0, 0)
            f.meetMembersbox.Background:SetColorTexture(0,0,0,0)
            f.meetMembersbox.fontstring = f.meetMembersbox:CreateFontString(nil, "OVERLAY")
            f.meetMembersbox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.meetMembersbox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.meetMembersbox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.meetMembersbox.fontstring:SetWordWrap(false)
            f.meetMembersbox.fontstring:SetJustifyH("RIGHT")
            f.meetMembersbox.fontstring:SetJustifyV("MIDDLE")
            f.meetMembersbox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.meetMembersbox:Disable()
            f.meetMembersbox:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.meetMembersbox:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)

            f.actualMembersbox = CreateEditBox(f, actualMembersWidth, lineHeight, 12, "CENTER", nil, nil, board_r, board_g, board_b, board_a, "SubsidyFrameactualMembersAddBoxChild" .. v)
            f.actualMembersbox:SetPoint("LEFT", f.meetMembersbox, "RIGHT", 0, 0)
            f.actualMembersbox.Background:SetColorTexture(0,0,0,0)
            f.actualMembersbox.fontstring = f.actualMembersbox:CreateFontString(nil, "OVERLAY")
            f.actualMembersbox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.actualMembersbox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.actualMembersbox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.actualMembersbox.fontstring:SetWordWrap(false)
            f.actualMembersbox.fontstring:SetJustifyH("RIGHT")
            f.actualMembersbox.fontstring:SetJustifyV("MIDDLE")
            f.actualMembersbox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.actualMembersbox:Disable()
            f.actualMembersbox:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.actualMembersbox:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)

            f.totalMoneybox = CreateEditBox(f, totalMoneyWidth, lineHeight, 12, "CENTER", true, nil, board_r, board_g, board_b, board_a, "SubsidyFrameTotalMoneyAddBoxChild" .. v)
            f.totalMoneybox:SetPoint("LEFT", f.actualMembersbox, "RIGHT", 0, 0)
            f.totalMoneybox.Background:SetColorTexture(0,0,0,0)
            f.totalMoneybox.fontstring = f.totalMoneybox:CreateFontString(nil, "OVERLAY")
            f.totalMoneybox.fontstring:SetPoint("TOPLEFT", 3, -1)
            f.totalMoneybox.fontstring:SetPoint("BOTTOMRIGHT", -3, 1)
            f.totalMoneybox.fontstring:SetFont(GameFontNormal:GetFont(), 13, "OUTLINE")
            f.totalMoneybox.fontstring:SetWordWrap(false)
            f.totalMoneybox.fontstring:SetTextColor(0.95, 0.95, 0.95, 1)
            f.totalMoneybox:Disable()
            f.totalMoneybox:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.totalMoneybox:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)
            --设置TAB事件
            do
                local editboxList = {"SubsidyFrameSubsidyTypeAddBoxChild" .. v, "SubsidyFrameSingleMoneyAddBoxChild" .. v, "SubsidyFrameTotalMoneyAddBoxChild" .. v}
                local function OnTabPressed(self)
                    EditBox_HandleTabbing(self, editboxList)
                end
                f.subsidyTypebox:SetScript("OnTabPressed", OnTabPressed)
                f.singleMoneybox:SetScript("OnTabPressed", OnTabPressed)
                f.totalMoneybox:SetScript("OnTabPressed", OnTabPressed)
            end

            f.delBtn = CreateButton(nil, f, "-", "LEFT", f.totalMoneybox, "RIGHT", 0, 0, delWidth, lineHeight)
            f.delBtn:SetScript("OnEnter", function(self)
                OnEnter(self)
            end)
            f.delBtn:SetScript("OnLeave", function(self)
                OnLeave(self)
            end)
            f.delBtn:SetScript("OnClick", function (self)
                local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]
                subsidyData[f.subsidyName] = nil
                SubsidyFrame:Update()
            end)

            t[v] = f
            return f
        end
    })
    function SubsidyFrame:Update()
        for _, f in ipairs(SubsidyFrame.entries) do f:Hide() end
        local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
        local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]
        local index = 1
        for _, subsidyName in ipairs(subsidyTypeList) do
            local subsidyMoney = subsidyData[subsidyName]
            if subsidyMoney then
                local f = SubsidyFrame.entries[index]
                f.subsidyName = subsidyName
                f.subsidyMoney = subsidyMoney
                local subsidyNameGsub = subsidyName:gsub("%d+", "")
                if subsidyName == "主T" or subsidyName == "副T" then
                    subsidyNameGsub = "T"
                end
                local icon = subsidyTypeFunc[subsidyNameGsub].icon or "|T:13|t"
                f.subsidyTypebox.fontstring:SetText(icon .. subsidyName)
                f.singleMoneybox.fontstring:SetText(subsidyMoney)
                if subsidyTypeFunc[subsidyNameGsub].OnLeftButtonMouseDown then
                    f.meetMembersbox:SetScript("OnMouseDown", function (self, button)
                        if button == "LeftButton" then
                            subsidyTypeFunc[subsidyNameGsub].OnLeftButtonMouseDown(self)
                        end
                    end)
                else
                    f.meetMembersbox:SetScript("OnMouseDown", function (self, button)
                        if button == "LeftButton" then
                            local function tempfunc(self)
                                local menuList = {}
                                local WagesGroupMembers = ZL.GetWagesGroupMembers()
                                if WagesGroupMembers then
                                    for _, data in ipairs(WagesGroupMembers) do
                                        for _, colorName in ipairs(data) do
                                            local name = ParseClassColorName(colorName)
                                            if name and ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                                            and ZL_CURRENT.playerInfo[name][subsidyNameGsub] then
                                                tinsert(menuList, {
                                                    text = colorName,
                                                    checkable = 1,
                                                    isNotRadio = 1,
                                                    keepShownOnClick = 1,
                                                    checked = true,
                                                    func = function ()
                                                        
                                                    end,
                                                })
                                            end
                                        end
                                    end
                                end
                                return menuList
                            end
                            local menuList = tempfunc(self)
                            if #menuList > 0 then
                                tinsert(menuList, 1, {
                                    text = icon .. subsidyName .. "：",
                                    isTitle = true,
                                })
                            else
                                tinsert(menuList, {
                                    text = "没有数据",
                                    isTitle = true,
                                })
                            end
                            ZL.GUI:ToggleMenu(self, menuList, 'TOPLEFT', self, 'BOTTOMRIGHT', 0, 0)
                        end
                    end)
                end
                if subsidyTypeFunc[subsidyNameGsub].toolTip then
                    f.singleMoneybox:SetScript("OnEnter", function (self)
                        OnEnter(self)
                        subsidyTypeFunc[subsidyNameGsub].toolTip(self)
                    end)
                else
                    f.singleMoneybox:SetScript("OnEnter", function (self)
                        OnEnter(self)
                        GameTooltipShow(self, "BOTTOMLEFT", "TOPRIGHT")
                        GameTooltip:AddLine("输入|cff4080FF不小于0的数|r")
                        GameTooltip:AddLine("支持鼠标滚轮快速输入数字")
                        GameTooltip:AddLine("需按|cff4080FFEnter|r或|cff4080FF右键|r保存！")
                        GameTooltip:Show()
                    end)
                end
                local subsidyNameNumbers = 0
                local WagesGroupMembers, _, _, RL = ZL.GetWagesGroupMembers()
                if WagesGroupMembers then
                    if subsidyName == "RL" then
                        if RL then
                            subsidyNameNumbers = subsidyNameNumbers + 1
                        end
                    elseif subsidyName == "修星" then
                        for _, data in ipairs(WagesGroupMembers) do
                            for _, colorName in ipairs(data) do
                                local name = ParseClassColorName(colorName)
                                if name and ZL_CURRENT.playerInfo and ZL_CURRENT.playerInfo[name]
                                and ZL_CURRENT.playerInfo[name]["DPS"] then
                                    subsidyNameNumbers = subsidyNameNumbers + 1
                                end
                            end
                        end
                    else
                        if ZL_CURRENT.playerInfo then
                            for playerName, data in pairs(ZL_CURRENT.playerInfo) do
                                local isExist
                                local isBreak
                                for _, _data in ipairs(WagesGroupMembers) do
                                    for _, colorName in ipairs(_data) do
                                        local name = ParseClassColorName(colorName)
                                        if name == playerName then
                                            isExist = true
                                            isBreak = true
                                            break
                                        end
                                    end
                                    if isBreak then break end
                                end
                                if isExist and data[subsidyNameGsub] then
                                    subsidyNameNumbers = subsidyNameNumbers + 1
                                end
                            end
                        end
                    end
                end
                f.meetMembersbox.fontstring:SetText(subsidyNameNumbers)
                f:Show()
                index = index + 1
            end
        end
    end

    SubsidyFrame:RegisterEvent("CHAT_MSG_SYSTEM")
    SubsidyFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
    SubsidyFrame:RegisterEvent("INSPECT_READY")
    SubsidyFrame:SetScript("OnEvent", function (self, event, ...)
        local arg = ZL.emptytable(...)
        if event == "COMBAT_LOG_EVENT_UNFILTERED" then -- and IsMasterLooter()
            if IsInRaid(1) and IsInInstance() and (select(2, IsInInstance()) == "raid") then --and IsMasterLooter() 
                local _, subevent, _, sourceGUID, _, _, _, _, _, _, _, spellId = CombatLogGetCurrentEventInfo()
                if subevent == "SPELL_CAST_SUCCESS" then
                    if spellId == 57426 or spellId == 57301 then
                        local _, englishClass, _, _, _, playerName = GetPlayerInfoByGUID(sourceGUID)
                        local colorPlayerName = GetClassColorName(playerName, englishClass)
                        ZL_CURRENT.playerInfo = ZL_CURRENT.playerInfo or {}
                        ZL_CURRENT.playerInfo[playerName] = ZL_CURRENT.playerInfo[playerName] or {}
                        ZL_CURRENT.playerInfo[playerName].classFile = englishClass
                        ZL_CURRENT.playerInfo[playerName].colorName = colorPlayerName
                        ZL_CURRENT.subsidyFoodFirst = ZL_CURRENT.subsidyFoodFirst or sourceGUID
                        local msgStr
                        local profileName = ZL.opt.subsidyProfileList["profileKeys"][ZL.opt.subsidyProfileSelect]
                        -- local subsidyData = ZL.opt.subsidyProfileList["profile"][profileName]
                        if spellId == 57426 then
                            ZL_CURRENT.playerInfo[playerName]["鱼"] = true
                            ZL_CURRENT.playerInfo[playerName].fishCount = (ZL_CURRENT.playerInfo[playerName].fishCount or 0) + 1
                            ZL_CURRENT.subsidyFishFirst = ZL_CURRENT.subsidyFishFirst or playerName
                            msgStr = format(
                                ">>>%s<<<释放了%s，记录次数%d，请大家文明就餐，不要遮挡。",
                                playerName, GetSpellLink(spellId), ZL_CURRENT.playerInfo[playerName].fishCount
                            )
                        elseif spellId == 57301 then
                            ZL_CURRENT.playerInfo[playerName]["猪"] = true
                            ZL_CURRENT.playerInfo[playerName].pigCount = (ZL_CURRENT.playerInfo[playerName].pigCount or 0) + 1
                            ZL_CURRENT.subsidyPigFirst = ZL_CURRENT.subsidyPigFirst or playerName
                            msgStr = format(
                                ">>>%s<<<释放了%s，记录次数%d，请大家文明就餐，不要遮挡。",
                                playerName, GetSpellLink(spellId), ZL_CURRENT.playerInfo[playerName].pigCount
                            )
                        elseif spellId == 22864 or spellId == 44389 then
                            ZL_CURRENT.playerInfo[playerName]["修理机器人"] = true
                            ZL_CURRENT.playerInfo[playerName].xiuLiCount = (ZL_CURRENT.playerInfo[playerName].xiuLiCount or 0) + 1
                            ZL_CURRENT.subsidyXiuLiFirst = ZL_CURRENT.subsidyXiuLiFirst or playerName
                            msgStr = format(
                                ">>>%s<<<释放了%s，记录次数%d，有需要修理的尽快修理。",
                                playerName, GetSpellLink(spellId), ZL_CURRENT.playerInfo[playerName].xiuLiCount
                            )
                        end
                        -- if IsMasterLooter() then
                        --     SendChatMessage(msgStr, "RAID")
                        -- end
                        SendChatMessage(msgStr, "RAID")
                        ZL.Print(msgStr, true)
                    end
                end
                subevent = nil
                sourceGUID = nil
                spellId = nil
            end
        elseif event == "INSPECT_READY" then
            local _, englishClass, _, _, _, playerName = GetPlayerInfoByGUID(arg[1])
            if ZL.inspectUnit and ZL.inspectUnit == playerName then
                ZL.inspectUnit = true
            end
            if not UnitInRaid(playerName) then return end
            local colorPlayerName = GetClassColorName(playerName, englishClass)
            ZL_CURRENT.playerInfo = ZL_CURRENT.playerInfo or {}
            ZL_CURRENT.playerInfo[playerName] = ZL_CURRENT.playerInfo[playerName] or {}
            ZL_CURRENT.playerInfo[playerName].classFile = englishClass
            ZL_CURRENT.playerInfo[playerName].colorName = colorPlayerName
            -- 获取装备
            local itemId = GetInventoryItemID(playerName, 16)
            if itemId == 46017 then  -- 瓦兰奈尔，远古王者之锤
                ZL_CURRENT.playerInfo[playerName]["橙锤"] = true
            elseif itemId == 49623 then
                ZL_CURRENT.playerInfo[playerName]["橙斧"] = true
            end
            -- 获取天赋
            local activeTalentIndex = GetActiveTalentGroup(true) --当前激活的天赋
            local mainTalentName
            local mainTalenPointsSpent = 0
            local mainTalenIcon
            for i = 1, GetNumTalentTabs(true) do --天赋种类，一般为3个，如戒律、神圣、暗影
                local _, talentName, _, talentIcon, pointsSpent = GetTalentTabInfo(i, true, nil, activeTalentIndex)
                if mainTalenPointsSpent >= pointsSpent then
                    mainTalentName = mainTalentName or talentName
                    mainTalenIcon = mainTalenIcon or talentIcon
                else
                    mainTalenPointsSpent = pointsSpent
                    mainTalentName = talentName
                    mainTalenIcon = talentIcon
                end
                if (mainTalentName == "鲜血" and talentName == "冰霜") or (mainTalentName == "野性战斗" and talentName == "野性战斗") then
                    for j = 1, GetNumTalents(i, true) do --当前天赋种类里面有多少个天赋技能
                        --名称, iconID, 行， 列, 点了几点技能， 最大可以点的技能
                        local _name, _, _, _, rank = GetTalentInfo(i, j, true, nil, activeTalentIndex)
                        if _name == "坚韧" then --鲜血DK
                            if rank == 5 then
                                mainTalentName = "鲜血坦克"
                            else
                                mainTalentName = "鲜血输出"
                            end
                            break
                        elseif _name == "厚皮" then --德鲁伊
                            if rank > 0 then
                                mainTalentName = "野性坦克"
                            else
                                mainTalentName = "野性输出"
                            end
                        end
                    end
                end
            end
            if mainTalentName then
                -- print(colorPlayerName .. "主天赋是：".. "|T" .. mainTalenIcon .. ":14|t" .. mainTalentName)
                ZL_CURRENT.playerInfo[playerName].talentName = ZL_CURRENT.playerInfo[playerName].talentName or {}
                ZL_CURRENT.playerInfo[playerName].talentName[mainTalentName] = mainTalenIcon
                getSubsidyTypeFromTalentInfo(playerName, mainTalentName)
                if englishClass == "PALADIN" and mainTalentName == "神圣" then
                    ZL_CURRENT.playerInfo[playerName]["NQ"] = true
                end
            end
            if SubsidyFrame:IsShown() then
                SubsidyFrame:Update()
            end
        end
        arg:Release()
    end)
end