-- Author      : Peder
-- Create Date : 11/21/2022 12:06:49 PM
function StablesFilterSortFrame_OnLoad() 
	StablesFilterSortFrame.FSScrollFrame.scrollChild = CreateFrame("Frame","$parentScrollChild",StablesFilterSortFrame.FSScrollFrame, BackdropTemplateMixin and "BackdropTemplate");
	StablesFilterSortFrame.FSScrollFrame:SetScrollChild(StablesFilterSortFrameFilterScrollFrame.scrollChild);
	StablesFilterSortFrame.FSScrollFrame.scrollChild:SetSize(StablesFilterSortFrame.FSScrollFrame:GetWidth(),StablesFilterSortFrame.FSScrollFrame:GetHeight());
	
	CreateFrame("Frame","TestOfScrollChild",StablesFilterSortFrame.FSScrollFrame.scrollChild,"FamilyFilterButtonTemplate");
	--TestOfScrollChild:SetSize(200,200);
	TestOfScrollChild:SetBackdrop(nil);
	TestOfScrollChild:SetPoint("TOPLEFT",StablesFilterSortFrame.FSScrollFrame.scrollChild,"TOPLEFT",0,0);

	--StablesCollectionPresetsFrameScrollFrame.scrollChild = CreateFrame("Frame", ScrollChild, StablesCollectionPresetsFrameScrollFrameScrollBar, BackdropTemplateMixin and "BackdropTemplate");
--StablesCollectionPresetsFrameScrollFrame:SetScrollChild(StablesCollectionPresetsFrameScrollFrame.scrollChild);
--StablesCollectionPresetsFrameScrollFrame.scrollChild:SetSize(127,42);
--StablesCollectionPresetsFrameScrollFrame.scrollChild:SetHeight(StablesCollectionPresetsFrameScrollFrame:GetHeight());

end


--[[ ON LOAD AND ON CLICK TEMPLATE FUNCTIONS HERE: IMPLEMENTED BY StablesFilterSortFrame.xml 

Functions Used here are implemented as part of the templates core hieritage relationship to allow for the most agile Object Oriented approach
Secondly there are functions that serve only as overrides 
]]

--[[ 
<///SUMMARY>
Manages the Hieritage and Special settings of the ScrollElement Expandables for Sorts
<///SUMMARY>
]]
function SortsScrollElementTemplate_OnLoad(self)
				
				
	-- First we set the hearitage order, note that the name has to be set correct from the first time as renaming is impossible.
				-- As we set the heritage we need to remove the reference from the wrong frame also
				self.expandbtn:SetParent(self.header);
				self.header.expandbtn = self.expandbtn;
				self.expandbtn = nil;

				-- Now we are ready to declare the functions that has to be done on the Expand Button
				function SortsButtonHeaders_OnLoad(s)
				local parent = s:GetParent();
				local root = parent:GetParent();
				--s.Text:SetPoint("TOPLEFT",s,5,-8)
				s.SelectedText:SetPoint("TOPLEFT",s.Text,"LEFT",0,-2);
				--s.CheckBox.Text:SetPoint("TOPLEFT",s,5,-16)
				--s.CheckBox:SetPoint("TOPLEFT",s.Text,s.CheckBox.Text:GetWidth(),-8)
				--s.Text = "Filter_Name";
				s.TexCoordBool = {};
				for i=1,8 do
				s.TexCoordBool[i] = select(i,s.Right:GetTexCoord());
				end
				s:GetParent():GetParent().MaxHeight = s:GetParent():GetParent():GetHeight();
				--root.Span:Hide();
				root:SetHeight(_G[root:GetName().."Header"]:GetHeight());
				end

				function SortsButtonHeaders_OnClick(s)
				local logic = select(6,s.Right:GetTexCoord());
				local logic2 = s.TexCoordBool[5];
				local logic3 = 0.4453125;
				local parent = s:GetParent();
				local root = parent:GetParent();
				--print(logic,logic2,logic3,(logic == logic3), (logic == logic2));
				--print(s.Right:GetTexCoord());
				if(logic ~= logic3) then
				s.Right:SetTexCoord(0.03125,0.90625,0.4453125,0.6484375);
				--print(root:GetName())
				root:SetHeight(root.MaxHeight);
				--print(root.MaxHeight);
				root.Span:Show();
				elseif(logic ~= logic2) then
				s.Right:SetTexCoord(s.TexCoordBool[1],s.TexCoordBool[2],s.TexCoordBool[3],s.TexCoordBool[4],s.TexCoordBool[5],s.TexCoordBool[6],s.TexCoordBool[7],s.TexCoordBool[8]);
				root:SetHeight(_G[root:GetName().."Header"]:GetHeight());
				root.Span:Hide();
				--print("else");
				end
				end
				-- first we run on load
				SortsButtonHeaders_OnLoad(self.header.expandbtn)
				-- secondly we set the script
				self.header.expandbtn:SetScript("OnClick",function(self)SortsButtonHeaders_OnClick(self)end);
				
end
--[[ 
<///SUMMARY>
Manages the Hieritage and Special settings of the ScrollElement Expandables for Filters
<///SUMMARY>
]]
function FilterScrollElementTemplate_OnLoad(self)
-- First we set the hearitage order, note that the name has to be set correct from the first time as renaming is impossible.
				-- As we set the heritage we need to remove the reference from the wrong frame also
				self.expandbtn:SetParent(self.header);
				self.header.expandbtn = self.expandbtn;
				self.expandbtn = nil;

				-- Now we are ready to declare the functions that has to be done on the Expand Button
				function FilterButtonHeaders_OnLoad(s)
				local parent = s:GetParent();
				local root = parent:GetParent();



				s.CheckBox.Text:SetPoint("TOPRIGHT",s.Text,"TOPLEFT",0,-8)

				s.CheckBox:SetPoint("TOPLEFT",s.Text,s.CheckBox.Text:GetWidth(),-12)
				--s.Text = "Filter_Name";
				s.TexCoordBool = {};
				for i=1,8 do
				s.TexCoordBool[i] = select(i,s.Right:GetTexCoord());
				end
				s:GetParent():GetParent().MaxHeight = s:GetParent():GetParent():GetHeight();
				--root.Span:Hide();
				root:SetHeight(_G[root:GetName().."Header"]:GetHeight());
				
					
				end



				function FilterButtonHeaders_OnClick(s)
				local logic = select(6,s.Right:GetTexCoord());
				local logic2 = s.TexCoordBool[5];
				local logic3 = 0.4453125;
				local parent = s:GetParent();
				local root = parent:GetParent();
				--print(logic,logic2,logic3,(logic == logic3), (logic == logic2));
				--print(s.Right:GetTexCoord());
				if(logic ~= logic3) then
				s.Right:SetTexCoord(0.03125,0.90625,0.4453125,0.6484375);
				--print(root:GetName())
				root:SetHeight(root.MaxHeight);
				--print(root.MaxHeight);
				root.Span:Show();
				elseif(logic ~= logic2) then
				s.Right:SetTexCoord(s.TexCoordBool[1],s.TexCoordBool[2],s.TexCoordBool[3],s.TexCoordBool[4],s.TexCoordBool[5],s.TexCoordBool[6],s.TexCoordBool[7],s.TexCoordBool[8]);
				root:SetHeight(_G[root:GetName().."Header"]:GetHeight());
				root.Span:Hide();
				--print("else");
				
				end
				end
				
				-- first we run on load
				FilterButtonHeaders_OnLoad(self.header.expandbtn);
				-- secondly we set the script
				self.header.expandbtn:SetScript("OnClick",function(self)FilterButtonHeaders_OnClick(self)end);
end

--[[ 
<///SUMMARY>
OVERRIDE FUNCTION of FilterButtonTemplate_OnLoad(self)
<///SUMMARY>
]]
function FilterButtonTemplate_OnLoad(self)
		
end
--[[ 
<///SUMMARY>
OVERRIDE FUNCTION of FilterButtonTemplate_OnPostLoad(self)
<///SUMMARY>
]]
function FilterButtonTemplate_OnPostLoad(self)
		self:HookScript("OnEnter", function(self) self.intrinsicWrapper.highlight:Show() end);
		self:HookScript("OnLeave", function(self) self.intrinsicWrapper.highlight:Hide() end);
end
--[[ 
<///SUMMARY>
OVERRIDE FUNCTION of IconWMFilterButtonTemplate_OnLoad(self)
<///SUMMARY>
]]
function IconWMFilterButtonTemplate_OnLoad(self)
		--set the label correctly with space
		self.FilterLabel:SetPoint("RIGHT", self, "RIGHT",-self.icon:GetWidth(),0);
		--add masking
		self.icon:SetBlendMode("ADD");
		self.icon:SetAlpha(0.8);
		self.icon:AddMaskTexture(self.mask);
end

--[[ 
<///SUMMARY>
OVERRIDE FUNCTION of IconFilterButtonTemplate_OnLoad(self)
<///SUMMARY>
]]
function IconFilterButtonTemplate_OnLoad(self)
	--set the label correctly with space
		self.FilterLabel:SetPoint("LEFT", self, "LEFT",69,0);
	-- set the point for the checkbox with space
		self.Checkbox:SetPoint("RIGHT",self.FilterLabel,"LEFT",-35,0);
end
--[[ 
<///SUMMARY>
OVERRIDE FUNCTION of SortsButtonTemplate_OnLoad(self)
<///SUMMARY>
]]
function SortsButtonTemplate_OnLoad(self)
				local root = self:GetParent();
				local scale = 0.8;
				local scaleValue = {Ring = scale, Dot = scale * 0.2 + 1}

				self.checkedTexture = self:CreateTexture();
				self.checkedTexture:SetAtlas("common-radiobutton-dot");
				self.Checkbox:SetSize(self.Checkbox:GetWidth()*scaleValue.Ring,self.Checkbox:GetHeight()*scaleValue.Ring);
				self.checkedTexture:SetSize(self.Checkbox:GetWidth()*scaleValue.Dot,self.Checkbox:GetHeight()*scaleValue.Dot);
				self.checkedTexture:SetPoint("CENTER",self.Checkbox,"CENTER",0,0);
				self.Checkbox:SetNormalTexture("common-radiobutton-circle");
				self.Checkbox:SetPushedTexture("common-radiobutton-circle");
				self.Checkbox:SetDisabledTexture("common-radiobutton-circle");
				self.Checkbox:SetCheckedTexture(self.checkedTexture);
				self.Checkbox:SetDisabledCheckedTexture(self.checkedTexture);

				self.Checkbox:SetPoint("RIGHT",self.FilterLabel,"LEFT",-2,0);
				self.FilterLabel:SetPoint("LEFT", self, "LEFT",self.Checkbox:GetWidth()+9,0);

end
