local _,ns = ...
local L = ns.L
--local z = ns.Utils.crearFrameConTextura(ns.f,3,215,0,331,1)
local windowW, windowH = 212, 361
function ns.getConfigSize()
    return windowW, windowH
end

local z = ns.Utils.crear9SliceFrame(ns.f,3, 215, 0, 331, 95, 105, 118, 210, windowW, windowH, "iconos", 512, 512)
--antiguamente
--z:SetPoint("TOP", ns.f, "TOP")
--después de recrecer el frame:
z:SetPoint("TOP", ns.outterFrame, "TOP")
ns.FrameSetup(z,"Config")

local function setTooltip(parentFrame,...)
    local text1,text2,text3,text4=...
    parentFrame:HookScript("OnEnter", function(self)
        GameTooltip:SetOwner( parentFrame, "ANCHOR_NONE" );
        GameTooltip:SetPoint("TOPLEFT", z, "BOTTOMLEFT", -2, -4)
        if text1 then
        --print(HIGHLIGHT_FONT_COLOR_CODE..text1..FONT_COLOR_CODE_CLOSE)
            GameTooltip:AddLine(NORMAL_FONT_COLOR_CODE..text1..FONT_COLOR_CODE_CLOSE,1,0,0,true)
        end
        if text2 then
            GameTooltip:AddLine(HIGHLIGHT_FONT_COLOR_CODE..text2..FONT_COLOR_CODE_CLOSE,1,0,0,true)
        end
        if text3 then
            GameTooltip:AddLine(HIGHLIGHT_FONT_COLOR_CODE..text3..FONT_COLOR_CODE_CLOSE,1,0,0,true)
        end
        if text4 then
            GameTooltip:AddLine(HIGHLIGHT_FONT_COLOR_CODE..text4..FONT_COLOR_CODE_CLOSE,1,0,0,true)
        end
        --AutoScrapTooltip:AddDoubleLine("prob", "lala")
        GameTooltip:Show()
    end)
    parentFrame:HookScript("OnLeave", function(self)
        GameTooltip:Hide()
    end)
end

z.c = CreateFrame("Button", nil, z)
z.c:SetNormalTexture(130832) --"Interface\\Buttons\\UI-Panel-MinimizeButton-Up"
z.c:SetPushedTexture(130830) --"Interface\\Buttons\\UI-Panel-MinimizeButton-Down"
z.c:SetHighlightTexture(130831) --"Interface\\Buttons\\UI-Panel-MinimizeButton-Highlight"
z.c:SetSize(32, 32)
z.c:SetPoint("TOPRIGHT", z, "TOPRIGHT", 0, -3)
z.c:SetScript("OnClick", function() ns.ocultarFrames() end)

z.title = ns.Utils.crearFrameConTextura(z,283,451,402,466,1)
z.title:SetPoint("TOP", z, "TOP", -3, -25)

local checkAutoLoot = CreateFrame("CheckButton", nil, z, "UICheckButtonTemplate");
checkAutoLoot:SetPoint("TOPLEFT", z.title, "BOTTOMLEFT", 10, 1);
checkAutoLoot.text:SetText(L["Faster AutoLoot"]);
checkAutoLoot:SetScript("OnClick", function (self)
    AutoScrap_CharSettings.AutoLoot = self:GetChecked()
    ns.enableAutoLoot(self:GetChecked())
end)

local textOtroAutoLoot = checkAutoLoot:CreateFontString (nil, "OVERLAY", "GameFontHighlightSmall")
textOtroAutoLoot:SetPoint("TOPLEFT", checkAutoLoot, "TOPLEFT", 39, -21)
textOtroAutoLoot:SetText(L["|cffd20a07Another Fasterloot\nDetected|r"])
textOtroAutoLoot:Hide()

checkAutoLoot.tachado = CreateFrame("Frame",nil,checkAutoLoot)
checkAutoLoot.tachado:SetSize(145,1)
checkAutoLoot.tachado:SetPoint("LEFT",checkAutoLoot,"LEFT",2,0)
checkAutoLoot.tachado.tex = checkAutoLoot.tachado:CreateTexture()
checkAutoLoot.tachado.tex:SetAllPoints(checkAutoLoot.tachado)
checkAutoLoot.tachado.tex:SetColorTexture(255/255, 0/255, 0/255 , 1); --rgb
checkAutoLoot.tachado:Hide()

local tooltipTextOtroAutoLoot = CreateFrame("Frame",nil,checkAutoLoot.tachado)
tooltipTextOtroAutoLoot:SetPoint("TOPLEFT",checkAutoLoot,"TOPLEFT")
tooltipTextOtroAutoLoot:SetPoint("RIGHT",checkAutoLoot.tachado,"RIGHT")
tooltipTextOtroAutoLoot:SetPoint("BOTTOM",textOtroAutoLoot,"BOTTOM")
tooltipTextOtroAutoLoot:Hide()

local checkAutoSell = CreateFrame("CheckButton", nil, z, "UICheckButtonTemplate");
checkAutoSell:SetPoint("TOP", checkAutoLoot, "BOTTOM", 0, 7);
checkAutoSell.text:SetText(L["Auto Sell"]);
checkAutoSell:SetScript("OnClick", function (self)
    AutoScrap_CharSettings.autoSell = self:GetChecked()
end)

local checkAutoRepair = CreateFrame("CheckButton", nil, z, "UICheckButtonTemplate");
checkAutoRepair:SetPoint("TOP", checkAutoSell, "BOTTOM", 0, 7);
checkAutoRepair.text:SetText(L["Auto Repair"]);
checkAutoRepair:SetScript("OnClick", function (self)
    AutoScrap_CharSettings.autoRepair = self:GetChecked()
end)

local moveFrame = CreateFrame("Frame", nil, UIParent)
local checkMoveErrors = CreateFrame("CheckButton", nil, z, "UICheckButtonTemplate");
checkMoveErrors:SetPoint("TOP", checkAutoRepair, "BOTTOM", 0, 7);
checkMoveErrors.text:SetText(L["Move UIErrorsFrame"]);
checkMoveErrors:SetScript("OnClick", function (self)
    if self:GetChecked() then
        moveFrame:Show()
    else
        moveFrame:Hide()
    end
end)

local function moveErrorsFrame ()
        local left, _ , right, xOff, yOff = moveFrame:GetPoint()
        UIErrorsFrame:ClearAllPoints()
        UIErrorsFrame:SetPoint(left,UIParent,right,xOff, yOff)
        AutoScrap_CharSettings.ErrorsFrameMoved = true
        AutoScrap_CharSettings.ErrorsFramePlace = {
            startPoint = left ,
            relativePoint = right,
            xOfs =xOff,
            yOfs =yOff,
        }
 end
 
moveFrame:SetAllPoints(UIErrorsFrame)
moveFrame.tex = moveFrame:CreateTexture(nil, "BACKGROUND")
moveFrame.tex:SetAllPoints(moveFrame)
moveFrame.tex:SetColorTexture(200/255, 150/255, 13/255 , 0.7)
moveFrame:SetMovable(true)
moveFrame:EnableMouse(true)
moveFrame:SetClampedToScreen(true)
moveFrame:SetScript("OnMouseDown",function (self,button) if button=="LeftButton" then moveFrame:StartMoving() end end)
moveFrame:SetScript("OnMouseUp",function (self,button) if button=="LeftButton" then moveFrame:StopMovingOrSizing() moveErrorsFrame() end end)
moveFrame.texto = moveFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
moveFrame.texto:SetPoint("CENTER", moveFrame, "CENTER")
moveFrame.texto:SetText(L["Move this window, then disable Move UIErrorsFrame checkbutton"])
moveFrame:Hide()

local limpiarTodo = ns.Utils.crearBoton(z,130,40,L["Empty the entire\nScrap list"],function (self, button)
    AutoScrap_CharSettings.blackList={}
    ns.toggleAutoScrapOff()
    PlaySound(148283)
        --ReloadUI()
end)
limpiarTodo:SetPoint("CENTER",z,"TOP",0,-300)

local bindingButton = ns.Utils.crearBoton(z,130,22,L["Set Manual Key"],function ()
    -- KeyBindingFrame_LoadUI()
    -- ShowUIPanel(KeyBindingFrame)
    -- ShowUIPanel(SettingsPanel)
    ns.toggleBindingKeyCatcher()
end)
bindingButton:SetPoint("BOTTOM",limpiarTodo, "TOP",0,6)

local wowTokenButton = ns.Utils.crearBoton(z,130,22,L["Wow Token Alert"],function ()
    ns.toggleWowTokenConfig()
end)
wowTokenButton:SetPoint("BOTTOM",bindingButton, "TOP",0,6)

local warbandOpsButton = ns.Utils.crearBoton(z,130,22,L["Warband Deposit"],function ()
    ns.mostrarVentanaOpcionesBandaGuerrera(true)
end)
warbandOpsButton:SetPoint("BOTTOM",wowTokenButton, "TOP",0,6)

local function otroAddonFasterLootDetectado()
    checkAutoLoot:Disable()
    checkAutoLoot.tachado:Show()
    textOtroAutoLoot:Show()
    tooltipTextOtroAutoLoot:Show()
    ns.enableAutoLoot(false)
end
ns.otroAddonFasterLootDetectado = otroAddonFasterLootDetectado

local function setAutoLoot (value)
    checkAutoLoot:SetChecked(value)
    ns.enableAutoLoot(value)
end
ns.setAutoLoot = setAutoLoot

function ns.setAutoSell (value)
    checkAutoSell:SetChecked(value)
end
function ns.setAutoRepair(value)
    checkAutoRepair:SetChecked(value)
end

z:Hide()

setTooltip(checkAutoLoot,L["Faster AutoLoot"],L["You can loot faster than the Blizzard default autoloot speed. Enable this and give it a try, you will farm much faster!!"],L["It will also automatically enable the Interface->Controls->AutoLoot checkbox for you."],L["It has a message to advise when your bags are full, support TSM disenchant window and avoid getting disconected from server by multiple loot request with inventory full."])
setTooltip(tooltipTextOtroAutoLoot,L["Faster AutoLoot"], L["You already has another Fasterloot addon running."], L["You cannot use AutoScrap Faster AutoLoot untill you disable it."], L["AutoScrap Faster Autoloot includes faster autoloot, but also a message when your bags are full, support TSM disenchant window or avoid getting disconected from the server by multiple request of looting with inventory full. Give it a try!"])
setTooltip(bindingButton,L["Set Manual Key"],L["Select a binding key to manually add items to the junk list, check the section under the menu AutoScrap in keybindings."],L["Click on top of an item to add it to the junk list. If the item is already on the junk list, it will remove it. If the item is on the AutoScrap junk list, it will add it to the whitelist."],L["If you try to add a whitelist item to junk, i will remove it from the whitelist first, click again to add it to the junk list."])
setTooltip(limpiarTodo,L["Empty Scrap List"],L["This will delete all the current Scrap item list that you entered manually with the binding key."])
setTooltip (checkAutoSell, L["Auto Sell"], L["Enable it if you want to sell all the junk automatically when you open a Merchant Window."])
setTooltip (checkAutoRepair, L["Auto Repair"], L["Enable it if you want to repair autmatically when you open a Merchan that can repair items."])
setTooltip (checkMoveErrors,L["Move UIErrorsFrame"], L["Move the Blizzard's UI Errors Window to another spot."])