local h=LibStub("\065\099\101\071\085\073-\051\046\048")local m,t,a=pairs,assert,type local N=PlaySound local z,s=CreateFrame,UIParent do local S="\087\105\110\100\111\119"local g=8 local function i(h)h.obj:Fire("\079\110\083\104\111\119")end local function j(h)h.obj:Fire("\079\110\067\108\111\115\101")end local function D(h)N(799)h.obj:Hide()end local function U(m)h:ClearFocus()end local function E(m)(m:GetParent()):StartMoving()h:ClearFocus()end local function Q(h)local m=h:GetParent()m:StopMovingOrSizing()local t=m.obj local a=t.status or t.localstatus a.width=m:GetWidth()a.height=m:GetHeight()a.top=m:GetTop()a.left=m:GetLeft()end local function L(m)(m:GetParent()):StartSizing("\066\079\084\084\079\077\082\073\071\072\084")h:ClearFocus()end local function H(m)(m:GetParent()):StartSizing("\066\079\084\084\079\077")h:ClearFocus()end local function y(m)(m:GetParent()):StartSizing("\082\073\071\072\084")h:ClearFocus()end local function J(h)(h:GetParent()):StopMovingOrSizing()end local function f(h,m)h.titletext:SetText(m)end local function W(h,m) end local function P(h)h.frame:Hide()end local function R(h)h.frame:Show()end local function v(h)h.frame:SetParent(s)h.frame:SetFrameStrata("\070\085\076\076\083\067\082\069\069\078\095\068\073\065\076\079\071")h:ApplyStatus()h:EnableResize(true)h:Show()end local function q(h)h.status=nil for m in m(h.localstatus)do h.localstatus[m]=nil end end local function T(h,m)t(a(m)=="\116\097\098\108\101")h.status=m h:ApplyStatus()end local function x(h)local m=h.status or h.localstatus local t=h.frame h:SetWidth(m.width or 700)h:SetHeight(m.height or 500)if m.top and m.left then t:SetPoint("\084\079\080",s,"\066\079\084\084\079\077",0,m.top)t:SetPoint("\076\069\070\084",s,"\076\069\070\084",m.left,0)else t:SetPoint("\067\069\078\084\069\082",s,"\067\069\078\084\069\082")end end local function b(h,m)local t=h.content local a=m-34 if a<0 then a=0 end t:SetWidth(a)t.width=a end local function u(h,m)local t=h.content local a=m-57 if a<0 then a=0 end t:SetHeight(a)t.height=a end local function d(h,m)local t=m and"\083\104\111\119"or"\072\105\100\101"h.sizer_se[t](h.sizer_se)h.sizer_s[t](h.sizer_s)h.sizer_e[t](h.sizer_e)end local function G()local m=z("\070\114\097\109\101",nil,s)local t={}t.type="\087\105\110\100\111\119"t.Hide=P t.Show=R t.SetTitle=f t.OnRelease=q t.OnAcquire=v t.SetStatusText=W t.SetStatusTable=T t.ApplyStatus=x t.OnWidthSet=b t.OnHeightSet=u t.EnableResize=d t.localstatus={}t.frame=m m.obj=t m:SetWidth(700)m:SetHeight(500)m:SetPoint("\067\069\078\084\069\082",s,"\067\069\078\084\069\082",0,0)m:EnableMouse()m:SetMovable(true)m:SetResizable(true)m:SetFrameStrata("\070\085\076\076\083\067\082\069\069\078\095\068\073\065\076\079\071")m:SetScript("\079\110\077\111\117\115\101\068\111\119\110",U)m:SetScript("\079\110\083\104\111\119",i)m:SetScript("\079\110\072\105\100\101",j)if m.SetResizeBounds then m:SetResizeBounds(240,240)else m:SetMinResize(240,240)end m:SetToplevel(true)local a=m:CreateTexture(nil,"\066\065\067\075\071\082\079\085\078\068")a:SetTexture(251966)a:SetPoint("\084\079\080\076\069\070\084",9,-6)a:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",m,"\084\079\080\082\073\071\072\084",-28,-24)local N=m:CreateTexture(nil,"\066\065\067\075\071\082\079\085\078\068")N:SetTexture(137056)N:SetPoint("\084\079\080\076\069\070\084",8,-24)N:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",-6,8)N:SetVertexColor(0,0,0,.75)local S=m:CreateTexture(nil,"\066\079\082\068\069\082")S:SetTexture(251963)S:SetWidth(64)S:SetHeight(64)S:SetPoint("\084\079\080\076\069\070\084")S:SetTexCoord(.501953125,.625,0,1)local g=m:CreateTexture(nil,"\066\079\082\068\069\082")g:SetTexture(251963)g:SetWidth(64)g:SetHeight(64)g:SetPoint("\084\079\080\082\073\071\072\084")g:SetTexCoord(.625,.75,0,1)local G=m:CreateTexture(nil,"\066\079\082\068\069\082")G:SetTexture(251963)G:SetHeight(64)G:SetPoint("\084\079\080\076\069\070\084",S,"\084\079\080\082\073\071\072\084")G:SetPoint("\084\079\080\082\073\071\072\084",g,"\084\079\080\076\069\070\084")G:SetTexCoord(.25,.369140625,0,1)local A=m:CreateTexture(nil,"\066\079\082\068\069\082")A:SetTexture(251963)A:SetWidth(64)A:SetHeight(64)A:SetPoint("\066\079\084\084\079\077\076\069\070\084")A:SetTexCoord(.751953125,.875,0,1)local k=m:CreateTexture(nil,"\066\079\082\068\069\082")k:SetTexture(251963)k:SetWidth(64)k:SetHeight(64)k:SetPoint("\066\079\084\084\079\077\082\073\071\072\084")k:SetTexCoord(.875,1,0,1)local o=m:CreateTexture(nil,"\066\079\082\068\069\082")o:SetTexture(251963)o:SetHeight(64)o:SetPoint("\066\079\084\084\079\077\076\069\070\084",A,"\066\079\084\084\079\077\082\073\071\072\084")o:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",k,"\066\079\084\084\079\077\076\069\070\084")o:SetTexCoord(.376953125,.498046875,0,1)local B=m:CreateTexture(nil,"\066\079\082\068\069\082")B:SetTexture(251963)B:SetWidth(64)B:SetPoint("\084\079\080\076\069\070\084",S,"\066\079\084\084\079\077\076\069\070\084")B:SetPoint("\066\079\084\084\079\077\076\069\070\084",A,"\084\079\080\076\069\070\084")B:SetTexCoord(.001953125,.125,0,1)local F=m:CreateTexture(nil,"\066\079\082\068\069\082")F:SetTexture(251963)F:SetWidth(64)F:SetPoint("\084\079\080\082\073\071\072\084",g,"\066\079\084\084\079\077\082\073\071\072\084")F:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",k,"\084\079\080\082\073\071\072\084")F:SetTexCoord(.1171875,.2421875,0,1)local e=z("\066\117\116\116\111\110",nil,m,"\085\073\080\097\110\101\108\067\108\111\115\101\066\117\116\116\111\110")e:SetPoint("\084\079\080\082\073\071\072\084",2,1)e:SetScript("\079\110\067\108\105\099\107",D)t.closebutton=e e.obj=t local r=m:CreateFontString(nil,"\065\082\084\087\079\082\075")r:SetFontObject(GameFontNormal)r:SetPoint("\084\079\080\076\069\070\084",12,-8)r:SetPoint("\084\079\080\082\073\071\072\084",-32,-8)t.titletext=r local K=z("\066\117\116\116\111\110",nil,m)K:SetPoint("\084\079\080\076\069\070\084",a)K:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",a)K:EnableMouse()K:SetScript("\079\110\077\111\117\115\101\068\111\119\110",E)K:SetScript("\079\110\077\111\117\115\101\085\112",Q)t.title=K local p=z("\070\114\097\109\101",nil,m)p:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",m,"\066\079\084\084\079\077\082\073\071\072\084",0,0)p:SetWidth(25)p:SetHeight(25)p:EnableMouse()p:SetScript("\079\110\077\111\117\115\101\068\111\119\110",L)p:SetScript("\079\110\077\111\117\115\101\085\112",J)t.sizer_se=p local V=p:CreateTexture(nil,"\066\065\067\075\071\082\079\085\078\068")t.line1=V V:SetWidth(14)V:SetHeight(14)V:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",-8,8)V:SetTexture(137057)local X=.082352941176471 V:SetTexCoord(.05-X,.5,.05,.5+X,.05,.5-X,.5+X,.5)local w=p:CreateTexture(nil,"\066\065\067\075\071\082\079\085\078\068")t.line2=w w:SetWidth(8)w:SetHeight(8)w:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",-8,8)w:SetTexture(137057)X=.047058823529412 w:SetTexCoord(.05-X,.5,.05,.5+X,.05,.5-X,.5+X,.5)local l=z("\070\114\097\109\101",nil,m)l:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",m,"\066\079\084\084\079\077\082\073\071\072\084",-25,0)l:SetPoint("\066\079\084\084\079\077\076\069\070\084",m,"\066\079\084\084\079\077\076\069\070\084",0,0)l:SetHeight(25)l:EnableMouse()l:SetScript("\079\110\077\111\117\115\101\068\111\119\110",H)l:SetScript("\079\110\077\111\117\115\101\085\112",J)t.sizer_s=l local Y=z("\070\114\097\109\101",nil,m)Y:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",m,"\066\079\084\084\079\077\082\073\071\072\084",0,25)Y:SetPoint("\084\079\080\082\073\071\072\084",m,"\084\079\080\082\073\071\072\084",0,0)Y:SetWidth(25)Y:EnableMouse()Y:SetScript("\079\110\077\111\117\115\101\068\111\119\110",y)Y:SetScript("\079\110\077\111\117\115\101\085\112",J)t.sizer_e=Y local Z=z("\070\114\097\109\101",nil,m)t.content=Z Z.obj=t Z:SetPoint("\084\079\080\076\069\070\084",m,"\084\079\080\076\069\070\084",12,-32)Z:SetPoint("\066\079\084\084\079\077\082\073\071\072\084",m,"\066\079\084\084\079\077\082\073\071\072\084",-12,13)h:RegisterAsContainer(t)return t end h:RegisterWidgetType(S,G,g)end
local AceGUI = LibStub("AceGUI-3.0")

-- Lua APIs
local pairs, assert, type = pairs, assert, type

-- WoW APIs
local PlaySound = PlaySound
local CreateFrame, UIParent = CreateFrame, UIParent

----------------
-- Main Frame --
----------------
--[[
	Events :
		OnClose

]]
do
	local Type = "Window"
	local Version = 8

	local function frameOnShow(this)
		this.obj:Fire("OnShow")
	end

	local function frameOnClose(this)
		this.obj:Fire("OnClose")
	end

	local function closeOnClick(this)
		PlaySound(799) -- SOUNDKIT.GS_TITLE_OPTION_EXIT
		this.obj:Hide()
	end

	local function frameOnMouseDown(this)
		AceGUI:ClearFocus()
	end

	local function titleOnMouseDown(this)
		this:GetParent():StartMoving()
		AceGUI:ClearFocus()
	end

	local function frameOnMouseUp(this)
		local frame = this:GetParent()
		frame:StopMovingOrSizing()
		local self = frame.obj
		local status = self.status or self.localstatus
		status.width = frame:GetWidth()
		status.height = frame:GetHeight()
		status.top = frame:GetTop()
		status.left = frame:GetLeft()
	end

	local function sizerseOnMouseDown(this)
		this:GetParent():StartSizing("BOTTOMRIGHT")
		AceGUI:ClearFocus()
	end

	local function sizersOnMouseDown(this)
		this:GetParent():StartSizing("BOTTOM")
		AceGUI:ClearFocus()
	end

	local function sizereOnMouseDown(this)
		this:GetParent():StartSizing("RIGHT")
		AceGUI:ClearFocus()
	end

	local function sizerOnMouseUp(this)
		this:GetParent():StopMovingOrSizing()
	end

	local function SetTitle(self,title)
		self.titletext:SetText(title)
	end

	local function SetStatusText(self,text)
		-- self.statustext:SetText(text)
	end

	local function Hide(self)
		self.frame:Hide()
	end

	local function Show(self)
		self.frame:Show()
	end

	local function OnAcquire(self)
		self.frame:SetParent(UIParent)
		self.frame:SetFrameStrata("FULLSCREEN_DIALOG")
		self:ApplyStatus()
		self:EnableResize(true)
		self:Show()
	end

	local function OnRelease(self)
		self.status = nil
		for k in pairs(self.localstatus) do
			self.localstatus[k] = nil
		end
	end

	-- called to set an external table to store status in
	local function SetStatusTable(self, status)
		assert(type(status) == "table")
		self.status = status
		self:ApplyStatus()
	end

	local function ApplyStatus(self)
		local status = self.status or self.localstatus
		local frame = self.frame
		self:SetWidth(status.width or 700)
		self:SetHeight(status.height or 500)
		if status.top and status.left then
			frame:SetPoint("TOP",UIParent,"BOTTOM",0,status.top)
			frame:SetPoint("LEFT",UIParent,"LEFT",status.left,0)
		else
			frame:SetPoint("CENTER",UIParent,"CENTER")
		end
	end

	local function OnWidthSet(self, width)
		local content = self.content
		local contentwidth = width - 34
		if contentwidth < 0 then
			contentwidth = 0
		end
		content:SetWidth(contentwidth)
		content.width = contentwidth
	end


	local function OnHeightSet(self, height)
		local content = self.content
		local contentheight = height - 57
		if contentheight < 0 then
			contentheight = 0
		end
		content:SetHeight(contentheight)
		content.height = contentheight
	end

	local function EnableResize(self, state)
		local func = state and "Show" or "Hide"
		self.sizer_se[func](self.sizer_se)
		self.sizer_s[func](self.sizer_s)
		self.sizer_e[func](self.sizer_e)
	end

	local function Constructor()
		local frame = CreateFrame("Frame",nil,UIParent)
		local self = {}
		self.type = "Window"

		self.Hide = Hide
		self.Show = Show
		self.SetTitle =  SetTitle
		self.OnRelease = OnRelease
		self.OnAcquire = OnAcquire
		self.SetStatusText = SetStatusText
		self.SetStatusTable = SetStatusTable
		self.ApplyStatus = ApplyStatus
		self.OnWidthSet = OnWidthSet
		self.OnHeightSet = OnHeightSet
		self.EnableResize = EnableResize

		self.localstatus = {}

		self.frame = frame
		frame.obj = self
		frame:SetWidth(700)
		frame:SetHeight(500)
		frame:SetPoint("CENTER",UIParent,"CENTER",0,0)
		frame:EnableMouse()
		frame:SetMovable(true)
		frame:SetResizable(true)
		frame:SetFrameStrata("FULLSCREEN_DIALOG")
		frame:SetScript("OnMouseDown", frameOnMouseDown)

		frame:SetScript("OnShow",frameOnShow)
		frame:SetScript("OnHide",frameOnClose)
		if frame.SetResizeBounds then -- WoW 10.0
			frame:SetResizeBounds(240,240)
		else
			frame:SetMinResize(240,240)
		end
		frame:SetToplevel(true)

		local titlebg = frame:CreateTexture(nil, "BACKGROUND")
		titlebg:SetTexture(251966) -- Interface\\PaperDollInfoFrame\\UI-GearManager-Title-Background
		titlebg:SetPoint("TOPLEFT", 9, -6)
		titlebg:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", -28, -24)

		local dialogbg = frame:CreateTexture(nil, "BACKGROUND")
		dialogbg:SetTexture(137056) -- Interface\\Tooltips\\UI-Tooltip-Background
		dialogbg:SetPoint("TOPLEFT", 8, -24)
		dialogbg:SetPoint("BOTTOMRIGHT", -6, 8)
		dialogbg:SetVertexColor(0, 0, 0, .75)

		local topleft = frame:CreateTexture(nil, "BORDER")
		topleft:SetTexture(251963) -- Interface\\PaperDollInfoFrame\\UI-GearManager-Border
		topleft:SetWidth(64)
		topleft:SetHeight(64)
		topleft:SetPoint("TOPLEFT")
		topleft:SetTexCoord(0.501953125, 0.625, 0, 1)

		local topright = frame:CreateTexture(nil, "BORDER")
		topright:SetTexture(251963) -- Interface\\PaperDollInfoFrame\\UI-GearManager-Border
		topright:SetWidth(64)
		topright:SetHeight(64)
		topright:SetPoint("TOPRIGHT")
		topright:SetTexCoord(0.625, 0.75, 0, 1)

		local top = frame:CreateTexture(nil, "BORDER")
		top:SetTexture(251963) -- Interface\\PaperDollInfoFrame\\UI-GearManager-Border
		top:SetHeight(64)
		top:SetPoint("TOPLEFT", topleft, "TOPRIGHT")
		top:SetPoint("TOPRIGHT", topright, "TOPLEFT")
		top:SetTexCoord(0.25, 0.369140625, 0, 1)

		local bottomleft = frame:CreateTexture(nil, "BORDER")
		bottomleft:SetTexture(251963) -- Interface\\PaperDollInfoFrame\\UI-GearManager-Border
		bottomleft:SetWidth(64)
		bottomleft:SetHeight(64)
		bottomleft:SetPoint("BOTTOMLEFT")
		bottomleft:SetTexCoord(0.751953125, 0.875, 0, 1)

		local bottomright = frame:CreateTexture(nil, "BORDER")
		bottomright:SetTexture(251963) -- Interface\\PaperDollInfoFrame\\UI-GearManager-Border
		bottomright:SetWidth(64)
		bottomright:SetHeight(64)
		bottomright:SetPoint("BOTTOMRIGHT")
		bottomright:SetTexCoord(0.875, 1, 0, 1)

		local bottom = frame:CreateTexture(nil, "BORDER")
		bottom:SetTexture(251963) -- Interface\\PaperDollInfoFrame\\UI-GearManager-Border
		bottom:SetHeight(64)
		bottom:SetPoint("BOTTOMLEFT", bottomleft, "BOTTOMRIGHT")
		bottom:SetPoint("BOTTOMRIGHT", bottomright, "BOTTOMLEFT")
		bottom:SetTexCoord(0.376953125, 0.498046875, 0, 1)

		local left = frame:CreateTexture(nil, "BORDER")
		left:SetTexture(251963) -- Interface\\PaperDollInfoFrame\\UI-GearManager-Border
		left:SetWidth(64)
		left:SetPoint("TOPLEFT", topleft, "BOTTOMLEFT")
		left:SetPoint("BOTTOMLEFT", bottomleft, "TOPLEFT")
		left:SetTexCoord(0.001953125, 0.125, 0, 1)

		local right = frame:CreateTexture(nil, "BORDER")
		right:SetTexture(251963) -- Interface\\PaperDollInfoFrame\\UI-GearManager-Border
		right:SetWidth(64)
		right:SetPoint("TOPRIGHT", topright, "BOTTOMRIGHT")
		right:SetPoint("BOTTOMRIGHT", bottomright, "TOPRIGHT")
		right:SetTexCoord(0.1171875, 0.2421875, 0, 1)

		local close = CreateFrame("Button", nil, frame, "UIPanelCloseButton")
		close:SetPoint("TOPRIGHT", 2, 1)
		close:SetScript("OnClick", closeOnClick)
		self.closebutton = close
		close.obj = self

		local titletext = frame:CreateFontString(nil, "ARTWORK")
		titletext:SetFontObject(GameFontNormal)
		titletext:SetPoint("TOPLEFT", 12, -8)
		titletext:SetPoint("TOPRIGHT", -32, -8)
		self.titletext = titletext

		local title = CreateFrame("Button", nil, frame)
		title:SetPoint("TOPLEFT", titlebg)
		title:SetPoint("BOTTOMRIGHT", titlebg)
		title:EnableMouse()
		title:SetScript("OnMouseDown",titleOnMouseDown)
		title:SetScript("OnMouseUp", frameOnMouseUp)
		self.title = title

		local sizer_se = CreateFrame("Frame",nil,frame)
		sizer_se:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,0)
		sizer_se:SetWidth(25)
		sizer_se:SetHeight(25)
		sizer_se:EnableMouse()
		sizer_se:SetScript("OnMouseDown",sizerseOnMouseDown)
		sizer_se:SetScript("OnMouseUp", sizerOnMouseUp)
		self.sizer_se = sizer_se

		local line1 = sizer_se:CreateTexture(nil, "BACKGROUND")
		self.line1 = line1
		line1:SetWidth(14)
		line1:SetHeight(14)
		line1:SetPoint("BOTTOMRIGHT", -8, 8)
		line1:SetTexture(137057) -- Interface\\Tooltips\\UI-Tooltip-Border
		local x = 0.1 * 14/17
		line1:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5)

		local line2 = sizer_se:CreateTexture(nil, "BACKGROUND")
		self.line2 = line2
		line2:SetWidth(8)
		line2:SetHeight(8)
		line2:SetPoint("BOTTOMRIGHT", -8, 8)
		line2:SetTexture(137057) -- Interface\\Tooltips\\UI-Tooltip-Border
		x = 0.1 * 8/17
		line2:SetTexCoord(0.05 - x, 0.5, 0.05, 0.5 + x, 0.05, 0.5 - x, 0.5 + x, 0.5)

		local sizer_s = CreateFrame("Frame",nil,frame)
		sizer_s:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-25,0)
		sizer_s:SetPoint("BOTTOMLEFT",frame,"BOTTOMLEFT",0,0)
		sizer_s:SetHeight(25)
		sizer_s:EnableMouse()
		sizer_s:SetScript("OnMouseDown",sizersOnMouseDown)
		sizer_s:SetScript("OnMouseUp", sizerOnMouseUp)
		self.sizer_s = sizer_s

		local sizer_e = CreateFrame("Frame",nil,frame)
		sizer_e:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",0,25)
		sizer_e:SetPoint("TOPRIGHT",frame,"TOPRIGHT",0,0)
		sizer_e:SetWidth(25)
		sizer_e:EnableMouse()
		sizer_e:SetScript("OnMouseDown",sizereOnMouseDown)
		sizer_e:SetScript("OnMouseUp", sizerOnMouseUp)
		self.sizer_e = sizer_e

		--Container Support
		local content = CreateFrame("Frame",nil,frame)
		self.content = content
		content.obj = self
		content:SetPoint("TOPLEFT",frame,"TOPLEFT",12,-32)
		content:SetPoint("BOTTOMRIGHT",frame,"BOTTOMRIGHT",-12,13)

		AceGUI:RegisterAsContainer(self)
		return self
	end

	AceGUI:RegisterWidgetType(Type,Constructor,Version)
end
