local miniDeadpoolLines = {}

miniDeadpoolLineHeight = 15
DeadpoolGlobal_MiniBetweenObjectsGap = 5

function deadpoolMiniFrame()
	--NewMiniDeadpoolFrame
	MiniDeadpoolFrame = CreateFrame("Frame", "MiniDeadpoolFrame", UIParent, "MiniDeadpoolFrameTemplate")
	
	local fontstring = MiniDeadpoolFrame:CreateFontString("MiniDeadpoolLabel", "ARTWORK", "DeadpoolWindowTitleTemplate")
    fontstring:SetText("Dead Pool")
    fontstring:SetPoint("TOP", 0, -7)

	for i = 1, DEADPOOL_NUM_LINES do
		local line = CreateFrame("Button", "MiniDeadpoolLine"..i, MiniDeadpoolFrame.Inset, "DeadpoolLineTemplate")
		--line:SetHighlightTexture("Interface/FriendsFrame/UI-FriendsFrame-HighlightBar-Blue", 0.4)
		if i == 1 then
			line:SetPoint("TOPLEFT", MiniDeadpoolFrame.Inset, 0, -3)
		else
			line:SetPoint("TOPLEFT", miniDeadpoolLines[i - 1], "BOTTOMLEFT")
		end
		line:SetSize(MiniDeadpoolFrame.Inset:GetWidth(), miniDeadpoolLineHeight)
		line:Hide()
		line:EnableMouse(false)
		miniDeadpoolLines[i] = line
	end
end

function updateMiniDeadpoolFrame()
	if MiniDeadpoolFrame and MiniDeadpoolFrame:IsShown() then
		local numItems = Deadpool_countTableElements(deadpoolList)
		if numItems > 10 then
			miniDeadpoolLineHeight = 10
			MiniDeadpoolFrame.Inset:SetPoint("TOPLEFT", 20, -26)
			MiniDeadpoolFrame.Inset:SetPoint("BOTTOMRIGHT", -22, 26)
		else
			miniDeadpoolLineHeight = 15
			MiniDeadpoolFrame.Inset:SetPoint("TOPLEFT", 10, -26)
			MiniDeadpoolFrame.Inset:SetPoint("BOTTOMRIGHT", -12, 26)
		end
	
		updateDeadpoolList(deadpoolCharInfo)
		local nbLignes = 0
		for index,miniDeadpoolLine in pairs(miniDeadpoolLines) do
			if miniDeadpoolLine and deadpoolList[index] then
				miniDeadpoolLine:SetHeight(miniDeadpoolLineHeight)
				createDeadpoolLine(DeadpoolGlobal_SessionId, index, deadpoolList[index], miniDeadpoolLine, false, true)
				miniDeadpoolLine:Show()
				nbLignes = nbLignes + 1
			else
				miniDeadpoolLine:Hide()
			end
		end
		MiniDeadpoolFrame:SetHeight(58 + nbLignes * miniDeadpoolLineHeight)
	end
end

function applyMiniDeadpoolWindowOptions()
	MiniDeadpoolFrameInset.Bg:SetAlpha(DeadpoolWindow[Deadpool_WindowsOptions]["DeadpoolFrameAlpha"])
	MiniDeadpoolFrameInsetMaximize:SetAlpha(DeadpoolWindow[Deadpool_WindowsOptions]["DeadpoolFrameAlpha"])
	MiniDeadpoolFrameInsetLock:SetAlpha(DeadpoolWindow[Deadpool_WindowsOptions]["DeadpoolFrameAlpha"])

	retOK, ret = pcall(callbackDeadpoolWindow, MiniDeadpoolFrame)

	local windowLocked = DeadpoolWindow[Deadpool_WindowsOptions]["MiniDeadpoolWindowLocked"]
	MiniDeadpoolFrameInsetLock:SetChecked(windowLocked)
	MiniDeadpoolFrame.canMove = not windowLocked
	DPEnableMouse(MiniDeadpoolFrame, not windowLocked)
end
