local addonName, ZLAUTO = ...

local ZL = ZLAUTO.mainFrame
local autoBid = ZL.autoBid
local GameTooltipShow = ZL.GameTooltipShow
local GameTooltipShowAnchor = ZL.GameTooltipShowAnchor
local LoadItemDataByID = ZL.LoadItemDataByID
local InportToStatistics = ZL.InportToStatistics
local cGetItemInfo = C_Item and C_Item.GetItemInfo or GetItemInfo
local cGetItemIcon = C_Item and C_Item.GetItemIconByID or GetItemIcon
local DisableAddOn = C_AddOns and C_AddOns.DisableAddOn or DisableAddOn
local MyAddon = ZL.MyAddon

--定义静态弹出对话框
--重置当前拍卖记录
StaticPopupDialogs["ZL_RESETCURRENT"] = {
	text = "%s",
	button1 = "重置|cffffff00并保存|r",
	button2 = "重置|cffff0000不保存|r",
    button3 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent():GetButton1():Click() end,
    OnShow = function(self)
		self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)
        self:GetEditBox():SetText(ZL_CURRENT.name or GetInstanceInfo())
    end,
	OnAccept = function(self)
        ZL.AuctionFrame2.auctionModeDropdown:SetValue(1)
        if ZL_CURRENT["auctionlist"] then
            for num, data in ipairs(ZL_CURRENT["auctionlist"]) do
                local f = ZL.AuctionFrame2.entries[num]
                if data.state == "auctioning" then
                    ZL_CURRENT.auctionlist[num].state = "waiting"
                    ZL_CURRENT.auctionlist[num].endTime = nil
                    ZL_CURRENT.auctionlist[num].isPaused = nil
                    ZL_CURRENT.auctionlist[num].bidderlist = {}
                    f:SetValues(num)
                end
                f:Hide()
            end
        end
        --将收入导入到Statistics
        InportToStatistics(ZL_CURRENT)
        local _, _, totalincome = ZL.GetAveWages()
        ZL_CURRENT.totalincome = totalincome
        if (not ZL_CURRENT.name) and (strlen(self:GetEditBox():GetText()) == 0) then
            ZL_CURRENT.name = GetInstanceInfo()
        elseif strlen(self:GetEditBox():GetText()) > 0 then
            ZL_CURRENT.name = self:GetEditBox():GetText()
        end
        if not ZL_CURRENT.auctiondate then ZL_CURRENT.auctiondate = date("%Y-%m-%d %H:%M:%S", GetServerTime()) end
        local index
        local auctionGUID = (ZL_CURRENT.globalConfig and ZL_CURRENT.globalConfig.auctionGUID) and ZL_CURRENT.globalConfig.auctionGUID or ZL_CURRENT.auctionGUID
        if auctionGUID then
            for _index, _data in ipairs(ZL_HISTORY) do
                local _acutionGUID = (_data.globalConfig and _data.globalConfig.auctionGUID) and _data.globalConfig.auctionGUID or _data.auctionGUID
                if auctionGUID == _acutionGUID then
                    index = _index
                    break
                end
            end
        end
        if index then
            ZL_HISTORY[index] = ZL_CURRENT
        else
            table.insert(ZL_HISTORY, ZL_CURRENT)
        end
        ZL_PLAYERLIST = {}
        ZL_CURRENT = {}
        ZL.CreateAuctionInfo()
        ZL.AuctionFrame2:Update()
        ZL.AuctionRecordFrame.historyFrame:Update()
        ZL.AuctionRecordFrame.currentIncomeFrame:Update()
        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
        if not ZL.PlayerIsML() and ZL.GetMLname() then
            MyAddon:TransmitAddonInfo2("AUTOAUC REQ", "auctioning", "WHISPER", ZL.GetMLname())
        end
        local chatType
        if IsInRaid(1) then
            chatType = "RAID"
        elseif IsInGroup(1) then
            chatType = "PARTY"
        elseif IsInGuild() then
            chatType = "GUILD"
        end
        if chatType then
            --获取团队版本号
            local data = {type="request", ver=ZL.addonVersion}
            MyAddon:TransmitAddonInfo2("AUTOAUC VER", data, chatType, nil, "BULK")
        end
        ZL.TransmitAddonInfo_Pro()
        local link = format("|cff87CEEB|Hgarrmission:%s:%s|h[%s]|h|r", "AutoAuction", "历史记录", "历史记录")
        ZL.Print("已重置当前记录，可到" .. link .. "中恢复", true)
	end,
	OnCancel = function(self)
        ZL.AuctionFrame2.auctionModeDropdown:SetValue(1)
        if ZL_CURRENT["auctionlist"] then
            for num, data in ipairs(ZL_CURRENT["auctionlist"]) do
                local f = ZL.AuctionFrame2.entries[num]
                if data.state == "auctioning" then
                    ZL_CURRENT.auctionlist[num].state = "waiting"
                    ZL_CURRENT.auctionlist[num].endTime = nil
                    ZL_CURRENT.auctionlist[num].isPaused = nil
                    ZL_CURRENT.auctionlist[num].bidderlist = {}
                    f:SetValues(num)
                end
                f:Hide()
            end
        end
        --将收入导入到Statistics
        InportToStatistics(ZL_CURRENT)
        ZL_PLAYERLIST = {}
        ZL_CURRENT = {}
        ZL.CreateAuctionInfo()
        ZL.AuctionFrame2:Update()
        ZL.AuctionRecordFrame.historyFrame:Update()
        ZL.AuctionRecordFrame.currentIncomeFrame:Update()
        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
        if not ZL.PlayerIsML() and ZL.GetMLname() then
            MyAddon:TransmitAddonInfo2("AUTOAUC REQ", "auctioning", "WHISPER", ZL.GetMLname())
        end
        local chatType
        if IsInRaid(1) then
            chatType = "RAID"
        elseif IsInGroup(1) then
            chatType = "PARTY"
        elseif IsInGuild() then
            chatType = "GUILD"
        end
        if chatType then
            --获取团队版本号
            local data = {type="request", ver=ZL.addonVersion}
            MyAddon:TransmitAddonInfo2("AUTOAUC VER", data, chatType, nil, "BULK")
        end
        ZL.TransmitAddonInfo_Pro()
        ZL.Print("拍卖记录已清空", true)
	end,
	OnAlt = function(self, data)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
}

--流拍物品申请重拍确认
StaticPopupDialogs["ZL_RETAKE"] = {
	text = "%s",
	button1 = "重拍",
	button2 = "取消",
    hasEditBox = false,
	OnAccept = function(self, data)
		if ZL.retake and #ZL.retake > 0 then
            local retake = ZL.retake
            local function linshi()
                if #retake > 0 then
                    local AuctioningCount = ZL.GetAuctioningCount()
                    if (not ZL_CURRENT.globalConfig.allowMultipleAuctions) and AuctioningCount > 0 then
                        C_Timer.After(2, linshi)
                    else
                        local fdata = retake[1]
                        local _, _index = ZL.FetchDataFromItemId(fdata.itemlink, fdata.itemindex)
                        if _index then
                            local curAuctionList = ZL_CURRENT.auctionlist[_index]
                            --如果是流拍的物品重新拍卖，检测流拍物品是否在流拍包里，如果在移动到其他包里
                            if curAuctionList.state == "failed" and ZL.opt.liupaiToggle and curAuctionList["spawnUID"] and next(curAuctionList["spawnUID"], nil) then
                                local itemList = {}
                                for _, value in pairs(curAuctionList["spawnUID"]) do
                                    if value["itemGUID"] and next(value["itemGUID"], nil) then
                                        for key, _ in pairs(value["itemGUID"]) do
                                            local bagID, slotIndex = ZL.FindItemInBag(key)
                                            if bagID and (bagID == ZL.opt.liupaiBagId or bagID == ZL.opt.liupaiBagId2) then
                                                --从第一个背包开始查询空闲的格子，如果不是流拍背包，也不是自己拍到的背包，则放进去
                                                local targetBagID, targetslotIndex
                                                local currentInfo
                                                for _bagID = 0, NUM_BAG_SLOTS do
                                                    if _bagID ~= ZL.opt.liupaiBagId and _bagID ~= ZL.opt.liupaiBagId and _bagID ~= ZL.opt.selfBagId then
                                                        for _slotIndex = 1, C_Container.GetContainerNumSlots(_bagID) do
                                                            currentInfo = C_Container.GetContainerItemInfo(_bagID, _slotIndex)
                                                            if not currentInfo then
                                                                targetBagID = _bagID
                                                                targetslotIndex = _slotIndex
                                                                break
                                                            end
                                                        end
                                                    end
                                                end
                                                currentInfo = nil
                                                if targetBagID then
                                                    table.insert(itemList, {
                                                        bagID = bagID, slotIndex = slotIndex,
                                                        targetBagID = targetBagID, targetslotIndex = targetslotIndex,
                                                    })
                                                end
                                            end
                                        end
                                    end
                                end

                                if #itemList > 0 then
                                    local index = 1
                                    local function _linshi()
                                        if index <= #itemList then
                                            if not (InCombatLockdown() or UnitIsDeadOrGhost("player")) then
                                                C_Container.PickupContainerItem(itemList[index]["bagID"], itemList[index]["slotIndex"])
                                                C_Container.PickupContainerItem(itemList[index]["targetBagID"], itemList[index]["targetslotIndex"])
                                                index = index + 1
                                                C_Timer.After(1, _linshi)
                                            else
                                                C_Timer.After(0.2, _linshi)
                                            end
                                        end
                                    end
                                    _linshi()
                                end
                            end
                            curAuctionList.bidderlist = {}
                            table.insert(ZL_CURRENT.auctionlist[_index].bidderlist, {
                                bidder = ZL.GetClassColorName(fdata.sender),
                                bidamount = curAuctionList.startbidamount,
                                bidCount = 1,
                                time = GetTime()*1000,
                            })
                            local _data = {
                                type = "开始拍卖",
                                isRestart = curAuctionList.state,
                                data2 = curAuctionList,
                                syncIndex = _index,
                                globalConfigData = ZL.globalConfigData(),
                            }
                            MyAddon:TransmitAddonInfo("AUTOAUC SYNC1", _data)
                            local Frame1 = ZL.AuctionFrame2.entries[_index]
                            Frame1.sync = true
                            Frame1.MLframe.functionFrame.CancelBtn:Disable()
                            C_Timer.After(10, function ()
                                Frame1.sync = nil
                                Frame1.MLframe.functionFrame.CancelBtn:Enable()
                            end)
                            tremove(ZL.retake, 1)
                            C_Timer.After(2, linshi)
                        end
                    end
                end
            end
            linshi()
        end
	end,
	OnCancel = function(self, data)
        SendChatMessage("因暂时不方便拍卖，请稍后重新提交重拍申请", "WHISPER", nil, data)
        ZL.retake = {}
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
}

--拾取绑定物品加入到打包拍卖确认提醒
StaticPopupDialogs["ZL_ISPACKAGE"] = {
	text = "%s",
	button1 = "打包拍卖",
	button2 = "取消",
    hasEditBox = false,
	OnAccept = function(self, data)
		ZL.AddToPackage(data)
	end,
	OnCancel = function(self)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
}
--更改拍卖模式警告提醒
StaticPopupDialogs["ZL_CHANGEAUCTIONMODE"] = {
	text = "%s",
	button1 = "确定",
    button2 = "取消",
	OnAccept = function(self, data)
        if data.type == "匿名" then
            local fdata = {
                type = "开始投票",
                totalMembers = data.totalMembers,
            }
            MyAddon:TransmitAddonInfo("AUTOAUC VOTE", fdata)
        end
        ZL.AuctionFrame2.auctionModeDropdown:Disable()
	end,
	OnCancel = function(self)
        ZL.AuctionFrame2.auctionModeDropdown:SetValue(1)
	end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = true,
}

--切换为匿名拍卖模式投票
StaticPopupDialogs["ZL_CHANGEAUCTIONMODEVOTE"] = {
	text = "%s",
    timeout = 31,
	button1 = "同意",
	button2 = "反对",
    OnShow = function(self)
        self.text:SetFormattedText(self.data .. "正在进行|cffff0000【匿名】|r拍卖投票\n请选择(%d)", 30)
        self.ticker = C_Timer.NewTicker(1, function()
            if self.timeleft > 0 then
                self.text:SetFormattedText(self.data .. "正在进行|cffff0000【匿名】|r拍卖投票\n请选择(%d)", self.timeleft)
                if self.timeleft <= 0 then
                    self:Hide()
                end
            end
        end)
        if ZL.voteTimer then
            if not ZL.voteTimer:IsCancelled() then
                ZL.voteTimer:Cancel()
            end
            ZL.voteTimer = nil
        end
        ZL.voteTimer = C_Timer.NewTimer(32, function ()
            local pass = ZL.voteAgree*100/ZL.voteTotalMembers
            local msgStr = "|cff00ff00同意：|r" .. ZL.voteAgree .. " |cffff0000反对：|r" .. ZL.voteRefuse .. " |cff0070dd总人数：|r" .. ZL.voteTotalMembers
            ZL.Print(msgStr, true)
            if pass > 50 then
                if ZL.PlayerIsML() then
                    ZL.opt.auctionMode = ZL.AuctionFrame2.auctionModeDropdown:GetText()
                    ZL.TransmitAddonInfo_Pro()
                    ZL.AuctionFrame2.auctionModeDropdown:Enable()
                    SendChatMessage("通过！通过率：" .. format("%.2f%%", pass) .. "，大于50%，拍卖模式已切换为【匿名】拍卖！", "RAID")
                end
                msgStr = "|cff00ff00通过！|r通过率：" .. format("%.2f%%", pass) .. "，大于50%，拍卖模式已切换为【|cffff0000匿名|r】拍卖！"
                ZL.Print(msgStr, true)
            else
                msgStr = "|cffff0000失败！|r通过率：" .. format("%.2f%%", pass) .. "，没有大于50%，拍卖模式已切换为【团队】模式！"
                ZL.Print(msgStr, true)
                if ZL.PlayerIsML() then
                    ZL.AuctionFrame2.auctionModeDropdown:SetValue(1)
                    ZL.AuctionFrame2.auctionModeDropdown:Enable()
                end
            end
        end)
        self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)
    end,
	OnAccept = function(self, data)
        local fdata = {
            type = "同意",
        }
        MyAddon:TransmitAddonInfo2("AUTOAUC VOTE", fdata)
	end,
    OnCancel = function(self, data)
        local fdata = {
            type = "反对",
        }
        MyAddon:TransmitAddonInfo2("AUTOAUC VOTE", fdata)
    end,
    OnHide = function(self)
        if ( self.timeleft > 0 ) then
            self:Hide();
        end
        if self.ticker then
            self.ticker:Cancel()
            self.ticker = nil
        end
    end,
    whileDead = true,
    hideOnEscape = false,
}
--进入全新副本时提醒是否重置拍卖记录
StaticPopupDialogs["ZL_RESETCURRENTINFO"] = {
	text = "%s",
	button1 = "确定",
    button2 = "取消",
	OnAccept = function(self)
        ZL.resetAuction()
	end,
    OnCancel = function (self, data)
        if data then
            if data.type == "更新日期" then
                ZL_CURRENT.auctiondate =  date("%Y-%m-%d %H:%M:%S", GetServerTime())
            elseif data.type == "更新副本" then
                ZL_CURRENT.instanceID = data.instanceID
                ZL_CURRENT.maxPlayers = data.maxPlayers
                ZL_CURRENT.name = data.name
            end
        end
    end,
    timeout = 0,
    whileDead = true,
    hideOnEscape = false,
}
--手动添加收支记录
StaticPopupDialogs["ZL_ADDINCOME"] = {
    text = "【|cffffd100%s|r】请输入必填项目",
    button1 = "确定",
    button2 = "取消",
    OnShow = function(dialog, data)
		dialog:GetButton1():Disable()
        local relativeTo = select(2, dialog.ButtonContainer:GetPoint())
        ZL.AddIncomeEditboxs:ClearAllPoints()
        ZL.AddIncomeEditboxs:SetPoint("TOP", relativeTo, "BOTTOM", 0, -15)
        ZL.AddIncomeEditboxs:Show()
        dialog.ButtonContainer:ClearAllPoints()
        dialog.ButtonContainer:SetPoint("TOP", ZL.AddIncomeEditboxs, "BOTTOM", 0, -9)
        local editBox2 = ZL.AddIncomeEditboxs.editBox2
        local editBox3 = ZL.AddIncomeEditboxs.editBox3
        local editBox4 = ZL.AddIncomeEditboxs.editBox4
        local editBox7 = ZL.AddIncomeEditboxs.editBox7
        editBox2:SetScript("OnTextChanged", function (self)
            if data.type == "收入" or data.type == "指定人员" or data.type == "罚款" then
                if strlen(editBox2:GetText()) > 0 and editBox3:GetNumber() > 0 and strlen(editBox4:GetText()) > 0 then
                    dialog:GetButton1():Enable()
                else
                    dialog:GetButton1():Disable()
                end
            elseif data.type == "支出" then
                if editBox3:GetNumber() > 0 and strlen(editBox4:GetText()) > 0 then
                    dialog:GetButton1():Enable()
                else
                    dialog:GetButton1():Disable()
                end
            end
        end)
        editBox3:SetScript("OnTextChanged", function (self)
            if data.type == "收入" or data.type == "指定人员" or data.type == "罚款" then
                if strlen(editBox2:GetText()) > 0 and editBox3:GetNumber() > 0 and strlen(editBox4:GetText()) > 0 then
                    dialog:GetButton1():Enable()
                else
                    dialog:GetButton1():Disable()
                end
            elseif data.type == "支出" then
                if editBox3:GetNumber() > 0 and strlen(editBox4:GetText()) > 0 then
                    dialog:GetButton1():Enable()
                else
                    dialog:GetButton1():Disable()
                end
            end
        end)
        editBox4:SetScript("OnTextChanged", function (self)
            if data.type == "收入" or data.type == "指定人员" or data.type == "罚款" then
                if strlen(editBox2:GetText()) > 0 and editBox3:GetNumber() > 0 and strlen(editBox4:GetText()) > 0 then
                    dialog:GetButton1():Enable()
                else
                    dialog:GetButton1():Disable()
                end
            elseif data.type == "支出" then
                if editBox3:GetNumber() > 0 and strlen(editBox4:GetText()) > 0 then
                    dialog:GetButton1():Enable()
                else
                    dialog:GetButton1():Disable()
                end
            end
        end)
        editBox4:SetScript("OnEnter", function (self)
            GameTooltip:ClearAllPoints()
            GameTooltip:ClearLines()
            GameTooltip:SetOwner(self, "ANCHOR_NONE")
            if data.type == "收入" or data.type == "指定人员" or data.type == "罚款" then
                GameTooltip:AddLine("如：罚款，垃圾或其他收入")
            elseif data.type == "支出" then
                GameTooltip:AddLine("如：补贴，物资消耗支出等")
            end
            GameTooltip:AddLine("如需输入物品名，|cffffd100Shift+左键|r点击\n背包物品或拍卖图标", 1, 1, 1)
            GameTooltip:SetPoint("LEFT", self, "RIGHT")
            GameTooltip:Show()
        end)
        editBox2:SetText("")
		editBox3:SetText("")
        editBox4:SetText("")
        editBox7:SetNumber(1)
        dialog:SetHeight(dialog:GetHeight()+ZL.AddIncomeEditboxs:GetHeight()+15)
        if data.type == "收入" then
            editBox2.text2:SetText("(必填)")
            editBox7.text2:SetText("(必填)")
        elseif data.type == "支出" then
            editBox2.text2:SetText("(可选)")
            editBox7.text2:SetText("(可选)")
        elseif data.type == "指定人员" then
            local ddate = ZL_CURRENT.auctionlist[data.index]
            editBox2.text2:SetText("(必填)")
            editBox7.text2:SetText("(必填)")
            editBox3:SetNumber(ddate.startbidamount)
            editBox4:SetText(ddate.itemlink)
            editBox7:SetNumber(ddate.itemCount)
        elseif data.type == "罚款" then
            editBox2.text2:SetText("(必填)")
            editBox7.text2:SetText("(必填)")
            editBox2:SetText(ZL.GetClassColorName(data.name))
            editBox3:SetNumber(data.amount)
            editBox4:SetText("罚款")
        end
    end,
    OnAccept = function (dialog, data)
        local itemList
        local editBox2 = ZL.AddIncomeEditboxs.editBox2
        local editBox3 = ZL.AddIncomeEditboxs.editBox3
        local editBox4 = ZL.AddIncomeEditboxs.editBox4
        local editBox7 = ZL.AddIncomeEditboxs.editBox7
        local player = ZL.GetClassColorName(editBox2:GetText())
        local notes = editBox4:GetText()
        local amount = 0
        local itemCount = editBox7:GetNumber()
        if ((not itemCount) or itemCount <= 0) then
            itemCount = 1
        end
        if not ZL_CURRENT.IncomeList then ZL_CURRENT.IncomeList = {} end
        if data.type == "收入" or data.type == "支出" or data.type == "罚款" then
            if data.type == "收入" or data.type == "罚款" then
                amount = editBox3:GetNumber() * itemCount
            elseif data.type == "支出" then
                amount = -editBox3:GetNumber() * itemCount
            end
            table.insert(ZL_CURRENT.IncomeList, {
                player = player,
                amount = amount,
                notes = notes,
                itemCount = itemCount,
                itemList = itemList,
            })
            if ZL.PlayerIsML(player) and amount > 0 then
                --ML自己拍到的物品直接记录到已支付
                if not ZL_CURRENT.playerPayToML then ZL_CURRENT.playerPayToML = {} end
                local oldPayToML = ZL_CURRENT.playerPayToML[player] and ZL_CURRENT.playerPayToML[player] or 0
                ZL_CURRENT.playerPayToML[player] = oldPayToML + amount
                ZL.AuctionRecordFrame.playerBalanceFrame:Update()
            end
            ZL.AuctionRecordFrame.currentIncomeFrame:Update()
            ZL.AuctionRecordFrame.playerBalanceFrame:Update()
            local fdata = {
                type = "添加收支",
                data = ZL_CURRENT.IncomeList,
                globalConfigData = ZL.globalConfigData(),
            }
            MyAddon:TransmitAddonInfo("AUTOAUC SYNC11", fdata)
        elseif data.type == "指定人员" then
            local ddate = ZL_CURRENT.auctionlist[data.index]
            ddate.bidderlist = {}
            table.insert(ddate.bidderlist, {
                bidder = player,
                bidamount = editBox3:GetNumber(),
                bidCount = itemCount,
                time = GetTime()*1000,
            })
            ZL.startOrCanelAuction(data.index, true)
        end


    end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}
--清除所有历史记录警告
StaticPopupDialogs["ZL_CLEARHISTORYWARNING"] = {
	text = "警告！警告！将清空所有历史拍卖记录，并且无法恢复！是否确定清空？",
	button1 = "确定",
    button2 = "取消",
	OnAccept = function(self, data)
        for _, f in ipairs(ZL.AuctionRecordFrame.historyFrame.entries) do
            f:Hide()
        end
        ZL_HISTORY = {}
	end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}
--删除历史拍卖记录警告
StaticPopupDialogs["ZL_DELETEHISTORYWARNING"] = {
	text = "删除后无法恢复，确认删除该拍卖记录？",
	button1 = "确定",
    button2 = "取消",
	OnAccept = function(self, data)
        table.remove(ZL_HISTORY, data)
        ZL.AuctionRecordFrame.historyFrame:Update()
	end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}
--删除拍卖警告
StaticPopupDialogs["ZL_DELETEAUCTIONWARNING"] = {
	text = "%s",
	button1 = "确定",
    button2 = "取消",
	OnAccept = function(self, data)
        local curAuctionList = ZL_CURRENT.auctionlist[data]
        --将需要删除的拍卖物品发送给其他成员
        local fdata = {
            type = "删除拍卖物品",
            itemindex = curAuctionList.itemindex,
            itemlink = curAuctionList.itemlink,
        }
        MyAddon:TransmitAddonInfo("AUTOAUC SYNC10", fdata)
        ZL.AuctionFrame2.entries[data].sync = true
        C_Timer.After(10, function ()
            ZL.AuctionFrame2.entries[data].sync = nil
        end)
    end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}
--自动出价
StaticPopupDialogs["ZL_AUTOBID"] = {
    text = "输入%s的最大心里价位:",
    timeout = 31,
	button1 = "开始自动出价",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent():GetButton1():Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent():GetButton1():Enable()
		else
			self:GetParent():GetButton1():Disable()
		end
	end,
    OnShow = function(self)
        self:SetHyperlinksEnabled(true)
        self:SetScript("OnHyperlinkEnter", function(self, link, _, button)
            local itemID = GetItemInfoInstant(link)
            if itemID then
                GameTooltip:SetOwner(button, "ANCHOR_RIGHT", 0, 0)
                GameTooltip:ClearLines()
                GameTooltip:SetHyperlink(link)
                GameTooltip:Show()
            end
        end)
        self:SetScript("OnHyperlinkLeave", function(self)
            GameTooltip:Hide()
        end)
        self:GetButton1():Disable()
        self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)
        if self.data.targetAmount then self:GetEditBox():SetText(self.data.targetAmount) end
    end,
	OnAccept = function(self, data)
		data.f.maxAutoBid = self:GetEditBox():GetNumber() or 0
        if data.f.maxAutoBid > 0 then
            data.f.bidFrame.bidEditBox:Disable()
            data.f.bidFrame.bidBtn:SetText("停止")
            data.f.bidFrame.lgnoreBtn:Disable()
            local itemCount = ZL_CURRENT.auctionlist[data.index].itemCount
            local bidCount = data.f.bidFrame.bidCounts:GetNumber()
            bidCount = bidCount > 0 and bidCount or 1
            bidCount = bidCount > itemCount and itemCount or bidCount
            autoBid(data.index, data.f.maxAutoBid, bidCount)
            if data.f.autoBid then
                if (not data.f.autoBid:IsCancelled()) then
                    data.f.autoBid:Cancel()
                end
                data.f.autoBid = nil
            end
            data.f.autoBid = C_Timer.NewTicker(2, function (self)
                autoBid(data.index, data.f.maxAutoBid, bidCount)
            end)
        end
        self:GetEditBox():ClearFocus()
	end,
	OnCancel = function(self, data)
	end,
    whileDead = 1,
    hideOnEscape = 1,
}

--代交欠款名单确认
StaticPopupDialogs["ZL_CONFIRMTRADERNAME"] = {
    text = "【%s】没有欠款记录，如果是代交欠款，请先选择代交人，然后点记录\n如果不是，请选择不记录:",
	button1 = "记录",
	button2 = "不记录",
    OnShow = function(dialog)
        dialog:GetButton1():Disable()
        local relativeTo = select(2, dialog.ButtonContainer:GetPoint())
        ZL.GroupMembersDropdown:ClearAllPoints()
        ZL.GroupMembersDropdown:SetPoint("TOP", relativeTo, "BOTTOM", 0, -15)
        dialog.ButtonContainer:ClearAllPoints()
        dialog.ButtonContainer:SetPoint("TOP", ZL.GroupMembersDropdown, "BOTTOM", 0, -9)
        dialog:SetHeight(dialog:GetHeight()+ZL.GroupMembersDropdown:GetHeight()+15)
        ZL.GroupMembersDropdown:Show()
        ZL.GroupMembersDropdown:SetDefaultText("")
        local menuTable = {}
        if IsInRaid(1) then
            local WagesGroupMembers = ZL.GetCurrentRoster()
            if WagesGroupMembers then
                for i, data in ipairs(WagesGroupMembers) do
                    if #data > 0 then
                        local memberList = {}
                        for _, playerName in ipairs(data) do
                            tinsert(memberList, {text=playerName, func = function ()
                                dialog:GetButton1():Enable()
                            end})
                        end
                        tinsert(menuTable, {
                            text = i .. "队",
                            hasArrow = true,
                            disabled = true,
                            menuTable = memberList,
                        })
                    end
                end
            end
        end
        ZL.GroupMembersDropdown:SetMenuTable(menuTable)
    end,
    OnAccept = function(dialog, data)
        local playerName = ZL.GroupMembersDropdown:GetText()
        if playerName and playerName ~= "" then
            if not ZL_CURRENT.playerPayToML then ZL_CURRENT.playerPayToML = {} end
            ZL_CURRENT.playerPayToML[playerName] = (ZL_CURRENT.playerPayToML[playerName] or 0) + data.tradeMoneyOther
            ZL.AuctionRecordFrame.playerBalanceFrame:Update()
            local msgStr = playerName .. "已由" .. data.tradePartner .. "代交欠款：|cffffffff" .. data.tradeMoneyOther .. "|rg"
            ZL.Print(msgStr, true)
        end
    end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}
--撤销指定玩家的出价
StaticPopupDialogs["ZL_REVOKEBID"] = {
    text = "选择你想撤销出价的玩家名字：",
    button1 = "确认",
    button2 = "取消",
    OnShow = function(self)
        ZL.GroupMembersDropdown:SetDefaultText("")
        local _, index = ZL.FetchDataFromItemId(self.data.itemlink, self.data.itemindex)
        local bidderlist = ZL_CURRENT.auctionlist[index].bidderlist
        local menuTable = {}
        for _, bidderData in ipairs(bidderlist) do
            tinsert(menuTable, {text=bidderData.bidder})
        end
        ZL.GroupMembersDropdown:SetMenuTable(menuTable)
        ZL.GroupMembersDropdown:ClearAllPoints()
        ZL.GroupMembersDropdown:SetPoint("BOTTOM", self, "BOTTOM", 0, 40)
    end,
    OnAccept = function(self, data)
        local playerName = ZL.GroupMembersDropdown:GetText()
        if playerName and #playerName > 0 then
            MyAddon:TransmitAddonInfo("AUTOAUC REVOKE", {itemlink=data.itemlink, itemindex=data.itemindex, playerName=playerName})
            ZL.AuctionFrame2.entries[data.index].MLframe.functionFrame.syncBtn:Disable()
            C_Timer.After(10, function ()
                ZL.AuctionFrame2.entries[data.index].MLframe.functionFrame.syncBtn:Enable()
            end)
        end
    end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}

--增加玩家收入金额
StaticPopupDialogs["ZL_ADDTOPLAYER"] = {
    text = "输入你想|cffffd100增加|r[|cffffd100%s|r]的收入金额：",
	button1 = "确定",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent():GetButton1():Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent():GetButton1():Enable()
		else
			self:GetParent():GetButton1():Disable()
		end
	end,
    OnShow = function(self)
		self:GetButton1():Disable()
        self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)
    end,
	OnAccept = function(self, data)
		local addamount = self:GetEditBox():GetNumber() or 0
        if (not ZL_CURRENT.playerPayToML) then ZL_CURRENT.playerPayToML = {} end
        ZL_CURRENT.playerPayToML[data]= (ZL_CURRENT.playerPayToML[data] or 0 )+ addamount
        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
	end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}
--扣除玩家收入金额
StaticPopupDialogs["ZL_REMFROMPLAYER"] = {
    text = "输入你想|cffffd100扣除|r[|cffffd100%s|r]的收入金额：",
	button1 = "确定",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent():GetButton1():Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent():GetButton1():Enable()
		else
			self:GetParent():GetButton1():Disable()
		end
	end,
    OnShow = function(self)
		self:GetButton1():Disable()
        self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)
    end,
	OnAccept = function(self, data)
		local addamount = self:GetEditBox():GetNumber() or 0
        if (not ZL_CURRENT.playerPayToML) then ZL_CURRENT.playerPayToML = {} end
        ZL_CURRENT.playerPayToML[data] = (ZL_CURRENT.playerPayToML[data] or 0) - addamount
        ZL.AuctionRecordFrame.playerBalanceFrame:Update()
	end,
	OnCancel = function(self, data)
	end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}
--手动创建拍卖物品
StaticPopupDialogs["ZL_ADDAUCTIONITEM"] = {
    text = "请填写需要拍卖的物品ID和数量：",
    button1 = "确定",
    button2 = "取消",
    OnShow = function(dialog)
		dialog:GetButton1():Disable()
        local relativeTo = select(2, dialog.ButtonContainer:GetPoint())
        ZL.AddAuctionEditboxs:ClearAllPoints()
        ZL.AddAuctionEditboxs:SetPoint("TOP", relativeTo, "BOTTOM", 0, -15)
        ZL.AddAuctionEditboxs:Show()
        dialog.ButtonContainer:ClearAllPoints()
        dialog.ButtonContainer:SetPoint("TOP", ZL.AddAuctionEditboxs, "BOTTOM", 0, -9)
        local editBox5 = ZL.AddAuctionEditboxs.editBox5
        local editBox6 = ZL.AddAuctionEditboxs.editBox6
        editBox5:SetScript("OnTextChanged", function (self)
            if editBox5:GetNumber() > 0 and editBox6:GetNumber() > 0 then
                dialog:GetButton1():Enable()
            else
                dialog:GetButton1():Disable()
            end
        end)
        editBox6:SetScript("OnTextChanged", function (self)
            if editBox5:GetNumber() > 0 and editBox6:GetNumber() > 0 then
                dialog:GetButton1():Enable()
            else
                dialog:GetButton1():Disable()
            end
        end)
        editBox5:SetText("")
		editBox6:SetText("")
        if dialog.data then
            dialog.editBox5:SetNumber(dialog.data.itemId)
        end
		dialog:SetHeight(dialog:GetHeight()+ZL.AddAuctionEditboxs:GetHeight()+15)
    end,
    OnAccept = function (dialog, data)
        local editBox5 = ZL.AddAuctionEditboxs.editBox5
        local editBox6 = ZL.AddAuctionEditboxs.editBox6
        local itemId = editBox5:GetNumber()
        local itemCount = editBox6:GetNumber()
        local function func(itemlink)
            ZL.ManualCreateAuctionItem(itemlink, itemCount or 1, data and data.itemGuid)
        end
        LoadItemDataByID(itemId, func, editBox5)
     end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}

--首次提醒
StaticPopupDialogs["ZL_FIRSTNOTICE"] = {
    text = "|cff0000ff【AutoAuction】|r提醒：新增了鼠标提示功能开关：拍卖状态、历史成交价、历史成交趋势图，默认为展示状态，如需隐藏，可到设置里面修改",
	button1 = "修改",
    button2 = "取消",
	OnAccept = function(self, data)
        ZL.OpenAceConfigDialog("金团拍卖助手", "tooltip")
	end,
    OnCancel = function(self)
        local msgStr = "后续可到设置——鼠标提示里取消展示"
        ZL.Print(msgStr, true)
	end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}

--同步不同战网子账号之间数据弹窗确认
StaticPopupDialogs["ZL_SYNCROLES"] = {
	text = "%s",
	button1 = "同意",
	button2 = "拒绝",
    timeout = 0,
    OnShow = function(self)
		self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)
        self.timeout = nil
    end,
	OnAccept = function(self, data)
        ZL.SaveRoles(data)
        RolesOverView["syncKeyUnBind"][data.OwnRolesSyncKey] = nil --从新绑定的从这里面移除
        local _data = {
            type = "addnewAgree",
            playerName = ZL.GetClassColorName(UnitName("player")),
            rolesData = RolesOverView.owner,
            syncData = RolesOverView.sync,
            OwnRolesSyncKey = select(3, ZL.GetOwnRolesSyncKey()),
        }
        MyAddon:TransmitAddonInfo2("AUTOAUC ROLES", _data, "WHISPER", ZL.ParseClassColorName(data.playerName), "BULK")
        local msgStr = "已成功与" .. data.playerName .. "绑定同步角色数据！"
        ZL.Print(msgStr, true)
	end,
	OnCancel = function(self, data)
        local _data = {
            type = "addnewRefuse",
            data = ZL.GetClassColorName(UnitName("player")),
        }
        MyAddon:TransmitAddonInfo2("AUTOAUC ROLES", _data, "WHISPER", ZL.ParseClassColorName(data.playerName), "BULK")
	end,
    OnUpdate = function(self, elapsed)
        -- 每帧更新时触发
        if not self.timeout then self.timeout = self.data.timeout - GetTime() end
        self.timeout = self.timeout - elapsed
        if self.timeout <= 0 then
            self.timeout = 0
            self:Hide()  -- 倒计时结束后关闭对话框
        else
            self.text:SetText(self.data.playerName .. "请求与你共享角色数据，是否同意？倒数：" .. "|cff00ff00" .. ceil(self.timeout) .. "|r")
        end
    end,
    whileDead = true,
    hideOnEscape = false,
}

--修改子账号名字
StaticPopupDialogs["ZL_MODIFYBNCHILD"] = {
	text = "%s",
	button1 = "修改",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent():GetButton1():Click() end,
    EditBoxOnTextChanged = function(self)
		if #(self:GetText() or "") > 0 then
			self:GetParent():GetButton1():Enable()
		else
			self:GetParent():GetButton1():Disable()
		end
	end,
    OnShow = function(self)
		self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)
        self:GetButton1():Disable()
    end,
	OnAccept = function(self, data)
        local _, _, BNChild = strsplit(":", data)
        local BNChildNewName = self:GetEditBox():GetText()
        BNChildNewName = BNChildNewName:gsub(":", "")
        RolesOverView["BNChildNewName"][BNChild] = self:GetEditBox():GetText()
        if ZL.LgnoreRolesFrame:IsShown() then
            ZL.LgnoreRolesFrame:Update()
        end
        ZL.RolesOverViewFrame.battleTagDropdown:SetMenuTable(ZL.GetBattleTagDropdownList())
        ZL.RolesOverViewFrame.battleTagDropdown:SetDefaultText("全部")
        ZL.RolesOverViewFrame.BNChildDropdown:SetMenuTable(ZL.GetBNChildDropdownList())
        ZL.RolesOverViewFrame.BNChildDropdown:SetDefaultText("全部")
        ZL.RolesOverViewFrame.BNChildDropdown:SetValue("全部")
        ZL.RolesOverViewFrame.realmDropdown:SetMenuTable(ZL.GetRealmDropdownList())
        ZL.RolesOverViewFrame.realmDropdown:SetDefaultText(GetRealmName())
        ZL.RolesOverViewFrame:Update()
        ZL.LgnoreRolesFrame:Update()
	end,
	OnCancel = function(self, data)
	end,
    whileDead = 1,
    hideOnEscape = 1,
}
--删除角色数据
StaticPopupDialogs["ZL_DELETEROLES"] = {
	text = "%s",
	button1 = "删除",
	button2 = "取消",
    OnShow = function(self)
		self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)
    end,
	OnAccept = function(self, data)
        if not ZL.glb.rolesDel then ZL.glb.rolesDel = {} end
        ZL.glb.rolesDel[data] = true
        local playerName, realmName, BNChild, battleTag = strsplit(":", data)
        local parsePlayerName = ZL.ParseClassColorName(playerName)
        local factionGroup = select(2, UnitFactionGroup("player"))
        if RolesOverView["owner"][battleTag] and RolesOverView["owner"][battleTag][BNChild] and RolesOverView["owner"][battleTag][BNChild][realmName]
        and RolesOverView["owner"][battleTag][BNChild][realmName][factionGroup] then
            RolesOverView["owner"][battleTag][BNChild][realmName][factionGroup][parsePlayerName] = nil
        end
        if RolesOverView["sync"][battleTag] and RolesOverView["sync"][battleTag][BNChild] and RolesOverView["sync"][battleTag][BNChild][realmName]
        and RolesOverView["sync"][battleTag][BNChild][realmName][factionGroup] then
            RolesOverView["sync"][battleTag][BNChild][realmName][factionGroup][parsePlayerName] = nil
        end
        RolesOverView["syncKey"][realmName .. ":" .. factionGroup .. ":" .. parsePlayerName] = nil
        ZL.glb["rolesLgnore"][data] = nil
        ZL.RolesOverViewFrame:Update()
        ZL.LgnoreRolesFrame:Update()
	end,
	OnCancel = function(self, data)
	end,
    whileDead = 1,
    hideOnEscape = 1,
}
--删除绑定子账号
StaticPopupDialogs["ZL_DELETEBNCHILD"] = {
	text = "%s",
	button1 = "解除绑定",
	button2 = "取消",
    OnShow = function(self)
		self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)

    end,

	OnAccept = function(self, data)
        RolesOverView["syncKeyUnBind"][data] = nil
        local battleTag, BNChild = strsplit(":", data)
        if RolesOverView["sync"] and RolesOverView["sync"][battleTag] then
            RolesOverView["sync"][battleTag][BNChild] = nil
        end
        local accountPlayer = {}
        local myRealm, myFactiongroup = GetRealmName(), select(2, UnitFactionGroup("player"))
        for key, value in pairs(RolesOverView["syncKey"]) do
            if value == data then
                local realm, factiongroup, player = strsplit(":", key)
                if realm == myRealm and factiongroup == myFactiongroup then
                    tinsert(accountPlayer, player)
                end
                RolesOverView["syncKey"][key] = nil
            end
        end
        if ZL.glb["rolesLgnore"] then
            for key in pairs(ZL.glb["rolesLgnore"]) do
                local _, _, _BNChild, _battleTag = strsplit(":", key)
                if BNChild == _BNChild and battleTag == _battleTag then
                    ZL.glb["rolesLgnore"][key] = nil
                end
            end
        end
        if ZL.glb["rolesDel"] then
            for key in pairs(ZL.glb["rolesDel"]) do
                local _, _, _BNChild, _battleTag = strsplit(":", key)
                if BNChild == _BNChild and battleTag == _battleTag then
                    ZL.glb["rolesDel"][key] = nil
                end
            end
        end
        local msgStr = "已解除[|cffffff00" .. battleTag .. ":" .. (RolesOverView["BNChildNewName"][BNChild] or BNChild) .. "|r]绑定！"
        ZL.Print(msgStr, true)
        -- RolesOverView["BNChildNewName"][BNChild] = nil
        ZL.RolesOverViewFrame.battleTagDropdown:SetMenuTable(ZL.GetBattleTagDropdownList())
        ZL.RolesOverViewFrame.battleTagDropdown:SetDefaultText("全部")
        ZL.RolesOverViewFrame.BNChildDropdown:SetMenuTable(ZL.GetBNChildDropdownList())
        ZL.RolesOverViewFrame.BNChildDropdown:SetDefaultText("全部")
        ZL.RolesOverViewFrame.BNChildDropdown:SetValue("全部")
        ZL.RolesOverViewFrame.realmDropdown:SetMenuTable(ZL.GetRealmDropdownList())
        ZL.RolesOverViewFrame.realmDropdown:SetDefaultText(GetRealmName())
        ZL.RolesOverViewFrame:Update()
        ZL.LgnoreRolesFrame:Update()

        --发送解除消息
        if #accountPlayer > 0 then
            --先判断是否有在线好友
            local isOnline
            for _, player in ipairs(accountPlayer) do
                if ZL.IsOnline(player, nil, nil, true) then
                    --发送解绑信息
                    local _, _, ownSyncKey = ZL.GetOwnRolesSyncKey()
                    local _data = {
                        type = "unBind",
                        playerName = ZL.GetClassColorName(UnitName("player")),
                        rolesData = "已解绑",
                        accountSyncKey = ownSyncKey,
                    }
                    MyAddon:TransmitAddonInfo2("AUTOAUC ROLES", _data, "WHISPER", ZL.ParseClassColorName(player), "BULK")
                    isOnline = true
                    wipe(accountPlayer)
                    accountPlayer = nil
                    break
                end
            end
            --没有在线好友，则先全部添加, 最多添加2次
            if not isOnline then
                ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", ZL.AddFriendFilterFunc)
                for _, player in ipairs(accountPlayer) do
                    local info = C_FriendList.GetFriendInfo(player)
                    if (not info) and C_FriendList.GetNumFriends() < 100 then
                        C_FriendList.AddFriend(player)
                    end
                end
                --1秒后再添加一次
                C_Timer.After(1, function ()
                    for _, player in ipairs(accountPlayer) do
                        local info = C_FriendList.GetFriendInfo(player)
                        if (not info) and C_FriendList.GetNumFriends() < 100 then
                            C_FriendList.AddFriend(player)
                        end
                    end
                    --1秒后判断是否有在线好友
                    C_Timer.After(1, function ()
                        ChatFrame_RemoveMessageEventFilter("CHAT_MSG_SYSTEM", ZL.AddFriendFilterFunc)
                        for _, player in ipairs(accountPlayer) do
                            if ZL.IsOnline(player, nil, nil, true) then
                                --发送解绑信息
                                local _, _, ownSyncKey = ZL.GetOwnRolesSyncKey()
                                local _data = {
                                    type = "unBind",
                                    playerName = ZL.GetClassColorName(UnitName("player")),
                                    rolesData = "已解绑",
                                    accountSyncKey = ownSyncKey,
                                }
                                MyAddon:TransmitAddonInfo2("AUTOAUC ROLES", _data, "WHISPER", ZL.ParseClassColorName(player), "BULK")
                                wipe(accountPlayer)
                                accountPlayer = nil
                                break
                            end
                        end
                    end)
                end)
            end
            
        end

	end,
	OnCancel = function(self, data)
	end,
    whileDead = 1,
    hideOnEscape = 1,
}

--复制当前配置并切换为默认配置（全账号共享配置）
StaticPopupDialogs["ZL_CHANGEANDCOPYTODEFAULTPROFILE"] = {
	text = "%s",
	button1 = "复制当前配置并切换为默认配置",
	button2 = "直接切换为默认配置",
    button3 = "取消",
    OnShow = function(self)
		self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)

    end,

	OnAccept = function(self, data)
        ZL.db.profile.askedAboutProfile = true
        ZL.db:SetProfile("Default")
        ZL.db:CopyProfile(data)
        local msgStr = "已复制当前角色配置并切换到默认配置(全角色共享)，您也可以到设置里面重新更改。"
        ZL.Print(msgStr, true)
        ZL.db.global.copyToDefalutProfile = true
	end,
    OnCancel = function(self, data)
        ZL.db.profile.askedAboutProfile = true
        ZL.db:SetProfile("Default")
        local msgStr = "已切换到默认配置(全角色共享)，您也可以到设置里面重新更改。"
        ZL.Print(msgStr, true)
    end,
	OnAlt = function()
        ZL.db.profile.askedAboutProfile = true
        local msgStr = "如需全角色共享配置，可到设置里面修改为默认配置。"
        ZL.Print(msgStr, true)
	end,
    whileDead = 1,
    hideOnEscape = 1,
}
--直接切换为默认配置（全账号共享配置）
StaticPopupDialogs["ZL_CHANGEDEFAULTPROFILE"] = {
	text = "%s",
	button1 = "切换为默认配置",
	button2 = "取消",
    OnShow = function(self)
		self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)

    end,

	OnAccept = function(self, data)
        ZL.db.profile.askedAboutProfile = true
        ZL.db:SetProfile("Default")
        local msgStr = "已切换到默认配置(全角色共享)，您也可以到设置里面重新更改。"
        ZL.Print(msgStr, true)
	end,
    OnCancel = function(self, data)
        ZL.db.profile.askedAboutProfile = true
        local msgStr = "如需全角色共享配置，可到设置里面修改为默认配置。"
        ZL.Print(msgStr, true)
    end,
    whileDead = 1,
    hideOnEscape = 1,
}

--导入关注物品字符串
StaticPopupDialogs["ZL_IMPORTCORCERNSTRING"] = {
	text = "%s",
	button1 = "导入",
	button2 = "取消",
    OnShow = function(self)
		self:GetButton1():SetText(self.data.btnText)
        self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)

    end,

	OnAccept = function(self, data)
        ZL.WaStringFrame:Hide()
        local selectCharKey = data.selectCharKey
        ZL.opt.concernList[selectCharKey] = data.data
        ZL.ConcernFrame:Update()
        if ZL.AuctionFrame2:IsShown() then
            ZL.AuctionFrame2:Update()
        end
        ZL.Print(selectCharKey .. "  关注物品数据导入成功", true)
	end,
    OnCancel = function(self, data)
    end,
    whileDead = 1,
    hideOnEscape = 1,
}

--设置快速出价幅度quickBidIncrement
StaticPopupDialogs["ZL_QUICKBIDINCREMENT"] = {
	text = "请输入快速出价弹窗加价幅度",
	button1 = "确认",
	button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent():GetButton1():Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent():GetButton1():Enable()
		else
			self:GetParent():GetButton1():Disable()
		end
	end,
    OnShow = function(self)
		self:GetButton1():Disable()
        self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)

    end,

	OnAccept = function(self, data)
        ZL.opt.quickBidIncrement = self:GetEditBox():GetNumber()
	end,
    OnCancel = function(self, data)
    end,
    whileDead = 1,
    hideOnEscape = 1,
}

--角色拥有物品数量大于1时出价确认
StaticPopupDialogs["ZL_CONFIRMBID"] = {
	text = "%s",
	button1 = "继续竞价",
	button2 = "取消",
    OnShow = function(self)
        self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)

    end,

	OnAccept = function(self, data)
        ZL_CURRENT.auctionlist[data.index].confirmBid = true
        if ZL_CURRENT.globalConfig.auctionMode == "团队" then
            if not ZL_CURRENT.globalConfig.allowMultipleAuctions then
                SendChatMessage(data.msgStr, "RAID")
            else
                SendChatMessage(data.itemlink .. data.msgStr, "RAID")
            end
        else
            MyAddon:TransmitAddonInfo2("AUTOAUC BID", data.itemlink .. data.msgStr)
        end
	end,
    OnCancel = function(self, data)
    end,
    whileDead = 1,
    hideOnEscape = 1,
}

--重载界面
StaticPopupDialogs["ZL_RELOADUI"] = {
    text = "%s",
	button1 = "|cffA335EE加载UI|r",
	button2 = "取消",
    OnShow = function(self)
        self:GetEditBox():SetNumeric(false)
        self:GetEditBox():SetAutoFocus(false)

    end,

	OnAccept = function(self, data)
        DisableAddOn(addonName)
        ReloadUI()
	end,
	OnCancel = function(self, data)
        ZL.Print("你还未加载UI，可能会影响后续拍卖！输入/reload可重新加载UI", true)
	end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}
--校正包装备累计分配数量
StaticPopupDialogs["ZL_CORRECTBUYERTOTAL"] = {
    text = "请输入校正后的累计分配数量",
    button1 = "确定",
    button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent():GetButton1():Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent():GetButton1():Enable()
		else
			self:GetParent():GetButton1():Disable()
		end
	end,
    OnShow = function(self)
        self:GetEditBox():SetNumeric(true)
        self:GetEditBox():SetAutoFocus(true)

    end,

    OnAccept = function(self, index)
        local data = ZL.opt.buyerHistory[index]
        data.total = self:GetEditBox():GetText()
        local item = Item:CreateFromItemID(data.itemId)
        if item:GetItemID() then
            item:ContinueOnItemLoad(function()
                local _, itemLink = cGetItemInfo(data.itemId)
                local buyerName = ZL.GetClassColorName(data.buyerName)
                ZL.Print(itemLink .. " - " .. buyerName .. " - 累计数量已调整为：" .. data.total)
            end)
        end
        self:GetEditBox():ClearFocus()
    end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}

--设置ROLL计时
StaticPopupDialogs["ZL_ROLLCOUNTDOWN"] = {
    text = "请输入ROLL记录时长(秒)",
    button1 = "确定",
    button2 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent():GetButton1():Click() end,
    EditBoxOnTextChanged = function(self)
		if self:GetNumber() > 0 then
			self:GetParent():GetButton1():Enable()
		else
			self:GetParent():GetButton1():Disable()
		end
	end,
    OnShow = function(self)
        self:GetEditBox():SetNumeric(true)
        self:GetEditBox():SetAutoFocus(true)

    end,

    OnAccept = function(self)
        ZL.opt.rollCountDown =( self:GetEditBox():GetNumber() and self:GetEditBox():GetNumber() > 5) and self:GetEditBox():GetNumber() or 5
        ZL.Print("ROLL时长已调整为：" .. ZL.opt.rollCountDown .. "秒", true)
    end,
    timeout = 0,
    whileDead = 1,
    hideOnEscape = 1,
}
StaticPopupDialogs["ZL_IMPORTTASKPROFILESTRING1"] = {
    text = "%s",
    button1 = "覆盖导入",
    button2 = "新建导入",
    button3 = "取消",
    hasEditBox = true,
    EditBoxOnEnterPressed = function(self) self:GetParent().button2:Click() end,
    EditBoxOnTextChanged = function(self)
        if strlen(self:GetText()) > 0 then
            local isExist
            for _, profileKey in ipairs(ZL.opt.taskList["profileKeys"]) do
                if profileKey == self:GetText() then
                    isExist = true
                end
            end
            if not isExist then
                self:GetParent().button2:Enable()
            else
                self:GetParent().button2:Disable()
                ZL.Print("配置名已存在，请重新输入！", nil, nil, nil, nil, true)
            end
        else
            self:GetParent().button2:Disable()
        end
    end,
    OnShow = function(self)
		self.button2:Disable()
        self:GetEditBox():SetAutoFocus(false)
        self:GetEditBox():SetNumeric(true)

    end,

    OnAccept = function(self, data)
        local profileName
        for key in pairs(data) do
            profileName = key
            break
        end
        if profileName then
            local valueIndex
            for index, value in ipairs(ZL.opt.taskList["profileKeys"]) do
                if value == profileName then
                    valueIndex = index
                end
            end
            if valueIndex then
                ZL.opt.taskList.task[profileName] = data[profileName]
                ZL.TaskFrame.historyProfileDropdown:SetMenuTable(ZL.getTaskProfileDropdownList())
                ZL.TaskFrame.historyProfileDropdown:SetValue(valueIndex)
                ZL.Print("【|cffffffff" .. profileName .. "|r】配置已导入！")
            else
                ZL.Print("导入失败！")
            end
        else
            ZL.Print("导入失败！")
        end
    end,

    OnCancel = function(self, data)
        local profileName
        for key in pairs(data) do
            profileName = key
            break
        end
        if profileName then
            local _profileName = self:GetEditBox():GetText()
            ZL.opt.taskList.task[_profileName] = data[profileName]
            tinsert(ZL.opt.taskList["profileKeys"], _profileName)
            ZL.TaskFrame.historyProfileDropdown:SetMenuTable(ZL.getTaskProfileDropdownList())
            ZL.TaskFrame.historyProfileDropdown:SetValue(#ZL.opt.taskList["profileKeys"])
            ZL.Print("【|cffffffff" .. profileName .. "|r】已导入新建配置【|cffffffff" .. _profileName .. "|r】中！")
        else
            ZL.Print("导入失败！")
        end
    end,
    whileDead = 1,
    hideOnEscape = 1,
}

StaticPopupDialogs["ZL_IMPORTTASKPROFILESTRING2"] = {
    text = "%s",
    button1 = "导入",
    button2 = "取消",
    hasEditBox = false,
    OnShow = function(self)
        self:GetEditBox():SetNumeric(true)
        self:GetEditBox():SetAutoFocus(true)
    end,
    OnAccept = function(self, data)
        local profileName
        for key in pairs(data) do
            profileName = key
            break
        end
        if profileName then
            ZL.opt.taskList.task[profileName] = data[profileName]
            tinsert(ZL.opt.taskList["profileKeys"], profileName)
            ZL.TaskFrame.historyProfileDropdown:SetMenuTable(ZL.getTaskProfileDropdownList())
            ZL.TaskFrame.historyProfileDropdown:SetValue(#ZL.opt.taskList["profileKeys"])
            ZL.Print("【|cffffffff" .. profileName .. "|r】配置已导入！")
        else
            ZL.Print("导入失败！")
        end
    end,

    OnCancel = function(self)
    end,
    whileDead = 1,
    hideOnEscape = 1,
}