local _,ns = ...
ns.tips("专业界面解锁所有材料按钮")

--来源https://wago.io/0FXluFV22/8
local BP,BPT = false,false
local _,ns = ...
ns.ADDUIEVENT("ADDON_LOADED", function(addons)
if addons == "Blizzard_Professions" then BP = true end
if addons == "Blizzard_ProfessionsTemplates" then BPT = true end
if not BP or not BPT then return end

--解锁材料
local GetCraftingReagentCount_original = _G['ItemUtil']['GetCraftingReagentCount']
_G['ItemUtil']['GetCraftingReagentCount'] = function(itemID)    
    local arb = _G["UnlockAllReagentsButton"]
    if arb and arb:IsVisible() and arb:GetChecked() then
        return arb.count
    end
    
    return GetCraftingReagentCount_original(itemID)
end

local function showCheckBox(self)         
    local arb = _G["UnlockAllReagentsButton"]
    arb:SetParent(self)
    arb:ClearAllPoints()
    arb:SetPoint("BOTTOMLEFT", 30, 0)
    arb:Show()
end

if not InCombatLockdown() then
    local arb = _G["UnlockAllReagentsButton"] 
    or CreateFrame("CheckButton", "UnlockAllReagentsButton", nil, "UICheckButtonTemplate")
    
    arb:ClearAllPoints()
    arb:SetSize(26,26)
    arb.text:SetText(LIGHTGRAY_FONT_COLOR:WrapTextInColorCode("解锁所有材料以方便查看星级"))
    arb:Hide()
    
    arb:SetScript("OnClick", function(self)   
            
            self.count = (self:GetChecked() and (self.countValue or 9999)) or nil
            
            local sf = self:GetParent()
            
            if sf then 
                if ProfessionsFrame.OrdersPage.OrderView:IsVisible() then
                    ProfessionsFrame.OrdersPage.OrderView:OnEvent("BAG_UPDATE")
                    
                else
                    sf:Refresh() 
                end
                
                local qd = sf.QualityDialog
                if qd and qd.recipeID then 
                    qd:Setup() 
                end    
            end            
        end
    )
    
    arb.countValue = 9999
    
    ProfessionsFrame.CraftingPage.SchematicForm:HookScript("OnShow", showCheckBox)
    ProfessionsFrame.OrdersPage.OrderView.OrderDetails.SchematicForm:HookScript("OnShow", showCheckBox)
    
end


end)