local W=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local q=game:GetService("\077\097\114\107\101\116\112\108\097\099\101\083\101\114\118\105\099\101")local e=game:GetService("\080\108\097\121\101\114\115")local t=W.AvatarEditor local V=require(t.Shared.Util.Spring)local d=require(t.Shared.Util.Maid)local E=require(t.Shared.Util.Promise)local L=require(t.Client.GuiLib.LazyLoader)local v=require(t.Shared.GetProductInfo)local F=require(t.Client.Theme)local U=e.LocalPlayer local z={}z.__index=z function z.new(W)local q=setmetatable({},z)q.Frame=W q.PurchaseFrame=q.Frame.Frame q.CreateFrame=q.Frame.CreateOutfit q.ConfirmFrame=q.Frame.Confirm q.Maid=d.new()q.Listeners=d.new()for W,e in ipairs(W:GetChildren())do if not e:IsA("\070\114\097\109\101")then continue end q.Maid:GiveTask(F:Bind(e,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\080\114\105\109\097\114\121"))q.Maid:GiveTask(F:Bind(e.Buttons.Button1,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\067\097\110\099\101\108"))q.Maid:GiveTask(F:Bind(e.Buttons.Button1,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))q.Maid:GiveTask(F:Bind(e.Buttons.Button2,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\067\111\110\102\105\114\109"))q.Maid:GiveTask(F:Bind(e.Buttons.Button2,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))end q.Maid:GiveTask(F:Bind(q.ConfirmFrame.Body.MessageLabel,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))q.Maid:GiveTask(F:Bind(q.ConfirmFrame.Body.TextLabel,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))q.Maid:GiveTask(F:Bind(q.ConfirmFrame.Body.TextLabel.Line,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\101\120\116"))q.Maid:GiveTask(F:Bind(q.CreateFrame.Body.TextLabel,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))q.Maid:GiveTask(F:Bind(q.CreateFrame.Body.TextLabel.Line,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\101\120\116"))q.Maid:GiveTask(F:Bind(q.CreateFrame.Body.Info.Search,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\097\098\066\117\116\116\111\110"))q.Maid:GiveTask(F:Bind(q.CreateFrame.Body.Info.Search.TextBox,"\080\108\097\099\101\104\111\108\100\101\114\067\111\108\111\114\051","\080\108\097\099\101\104\111\108\100\101\114\084\101\120\116"))q.Maid:GiveTask(F:Bind(q.CreateFrame.Body.Info.Search.TextBox,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))q.Maid:GiveTask(F:Bind(q.PurchaseFrame.Body.ProductInfo.ItemPreviewImage.ItemPreviewImageContainer,"\066\097\099\107\103\114\111\117\110\100\067\111\108\111\114\051","\084\101\120\116"))q.Maid:GiveTask(F:Bind(q.PurchaseFrame.Body.ProductInfo.ProductDescription.ProductDescriptionText,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))q.Maid:GiveTask(F:Bind(q.PurchaseFrame.Body.AdditionalDetails,"\084\101\120\116\067\111\108\111\114\051","\084\101\120\116"))q.TweenSpring=V.new(1)q.TweenSpring.Damper=1 q.TweenSpring.Speed=20 for W,q in ipairs(W:GetChildren())do if q:IsA("\070\114\097\109\101")then q.Visible=false end end return q end function z.OnRenderStep(q,W)local e=q.Frame local t=q.TweenSpring t:TimeSkip(W)local V=t.Position e.BackgroundTransparency=.4+V*.6 e.Visible=e.BackgroundTransparency<.98 end function z.PromptPurchase(e,W)local t=e.Listeners local V=e.PurchaseFrame local d=V.Buttons local E=V.Body.ProductInfo local L=E.ProductDescription.ProductDescriptionText local F=E.ItemPreviewImage.ItemPreviewImageContainer.ItemImage e:_setup(V)L.Text=""F.Image=""d.Button2.Text="\063\063\063"local z=v(W);(z:andThen(function(e)L.Text=e.Name F.Image="\114\098\120\116\104\117\109\098\058\047\047\116\121\112\101\061\065\115\115\101\116\038\105\100\061"..(e.AssetId.."\038\119\061\049\053\048\038\104\061\049\053\048")if e.IsPublicDomain then d.Button2.Text="\070\114\101\101"elseif e.IsForSale then d.Button2.Text=e.PriceInRobux.." \082\111\098\117\120"else d.Button2.Text="\079\102\102\115\097\108\101"end t:GiveTask(d.Button2.Activated:Connect(function(e)q:PromptPurchase(U,W)t:DoCleaning()end))end)):catch(warn)t:GiveTask(function()z:cancel()L.Text=""F.Image=""d.Button2.Text="\063\063\063"end)end function z.PromptCostume(q,W)local e=q.Listeners local t=q.CreateFrame local V=t.Buttons local d=t.Body.Info.Search.TextBox q:_setup(t)t.Body.Info.TextLabel.Visible=false local E=L.Classes.TextMask.new(d)e:GiveTask(E)E:SetMaskType("\065\108\112\104\097\110\117\109\098\101\114\105\099")E:SetMaxLength(20)local function v()if d.Text~=""then W(d.Text)e:DoCleaning()end end e:GiveTask(E.Frame.FocusLost:Connect(function(W,q)if not W then return end v()end))e:GiveTask(V.Button2.Activated:Connect(function(W)v()end))e:GiveTask(function()d.Text=""end)d:CaptureFocus()end function z.PromptConfirm(e,W,q)local t=e.Listeners local V=e.ConfirmFrame local d=V.Buttons V.Body.TextLabel.Text=W.Title or"\067\111\110\102\105\114\109"V.Body.MessageLabel.Text=W.Text or"\065\114\101 \121\111\117 \115\117\114\101 \121\111\117 \119\097\110\116 \116\111 \100\111 \116\104\105\115 \097\099\116\105\111\110\063"t:GiveTask(d.Button2.Activated:Connect(function(W)q()t:DoCleaning()end))e:_setup(V)end function z._setup(q,W)local e=q.Listeners local t=q.TweenSpring local V=W.Buttons e:GiveTask(V.Button1.Activated:Connect(function(W)e:DoCleaning()end))e:GiveTask(W.Parent.Activated:Connect(function(W)e:DoCleaning()end))e:GiveTask(function()W.Visible=false t.Target=1 end)W.Visible=true t.Target=0 end function z.Destroy(W)W.Maid:DoCleaning()W.Maid=nil W.Listeners:DoCleaning()W.Listeners=nil W.Frame=nil W.PurchaseFrame=nil W.CreateFrame=nil W.ConfirmFrame=nil W.TweenSpring=nil setmetatable(W,nil)end return z
-- Class
-- 0_1195
-- January 10, 2021

--[[



]]

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Marketplace = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local AvatarEditor = ReplicatedStorage.AvatarEditor
local Spring = require(AvatarEditor.Shared.Util.Spring)
local Maid = require(AvatarEditor.Shared.Util.Maid)
local Promise = require(AvatarEditor.Shared.Util.Promise)
local GuiLib = require(AvatarEditor.Client.GuiLib.LazyLoader)
local GetProductInfo = require(AvatarEditor.Shared.GetProductInfo)
local Theme = require(AvatarEditor.Client.Theme)

local player = Players.LocalPlayer

local Class = {}
Class.__index = Class


function Class.new(frame)
	local self = setmetatable({}, Class)
	
	self.Frame = frame
	self.PurchaseFrame = self.Frame.Frame
	self.CreateFrame = self.Frame.CreateOutfit
	self.ConfirmFrame = self.Frame.Confirm
	
	self.Maid = Maid.new()
	self.Listeners = Maid.new()
	
	for i, v in ipairs(frame:GetChildren()) do
		if not v:IsA("Frame") then
			continue
		end
		self.Maid:GiveTask(Theme:Bind(v, "BackgroundColor3", "Primary"))
		self.Maid:GiveTask(Theme:Bind(v.Buttons.Button1, "BackgroundColor3", "Cancel"))
		self.Maid:GiveTask(Theme:Bind(v.Buttons.Button1, "TextColor3", "Text"))
		self.Maid:GiveTask(Theme:Bind(v.Buttons.Button2, "BackgroundColor3", "Confirm"))
		self.Maid:GiveTask(Theme:Bind(v.Buttons.Button2, "TextColor3", "Text"))
	end

	self.Maid:GiveTask(Theme:Bind(self.ConfirmFrame.Body.MessageLabel, "TextColor3", "Text"))
	self.Maid:GiveTask(Theme:Bind(self.ConfirmFrame.Body.TextLabel, "TextColor3", "Text"))
	self.Maid:GiveTask(Theme:Bind(self.ConfirmFrame.Body.TextLabel.Line, "BackgroundColor3", "Text"))
	
	self.Maid:GiveTask(Theme:Bind(self.CreateFrame.Body.TextLabel, "TextColor3", "Text"))
	self.Maid:GiveTask(Theme:Bind(self.CreateFrame.Body.TextLabel.Line, "BackgroundColor3", "Text"))
	self.Maid:GiveTask(Theme:Bind(self.CreateFrame.Body.Info.Search, "BackgroundColor3", "TabButton"))
	self.Maid:GiveTask(Theme:Bind(self.CreateFrame.Body.Info.Search.TextBox, "PlaceholderColor3", "PlaceholderText"))
	self.Maid:GiveTask(Theme:Bind(self.CreateFrame.Body.Info.Search.TextBox, "TextColor3", "Text"))
	
	self.Maid:GiveTask(Theme:Bind(self.PurchaseFrame.Body.ProductInfo.ItemPreviewImage.ItemPreviewImageContainer, "BackgroundColor3", "Text"))
	self.Maid:GiveTask(Theme:Bind(self.PurchaseFrame.Body.ProductInfo.ProductDescription.ProductDescriptionText, "TextColor3", "Text"))
	self.Maid:GiveTask(Theme:Bind(self.PurchaseFrame.Body.AdditionalDetails, "TextColor3", "Text"))
	
	self.TweenSpring = Spring.new(1)
	self.TweenSpring.Damper = 1
	self.TweenSpring.Speed = 20
	
	for i, v in ipairs(frame:GetChildren()) do
		if v:IsA("Frame") then
			v.Visible = false
		end
	end
	
	return self
end


function Class:OnRenderStep(delta)
	local frame = self.Frame
	local tweenSpring = self.TweenSpring
	
	tweenSpring:TimeSkip(delta)
	
	local pos = tweenSpring.Position
	frame.BackgroundTransparency = 0.4 + pos * 0.6
	frame.Visible = frame.BackgroundTransparency < 0.98
end


function Class:PromptPurchase(assetId)
	local maid = self.Listeners
	local frame = self.PurchaseFrame
	
	local overlayButtons = frame.Buttons
	local productInfoFrame = frame.Body.ProductInfo
	local descriptionLabel = productInfoFrame.ProductDescription.ProductDescriptionText
	local previewImage = productInfoFrame.ItemPreviewImage.ItemPreviewImageContainer.ItemImage
	
	self:_setup(frame)
	
	descriptionLabel.Text = ""
	previewImage.Image = ""
	overlayButtons.Button2.Text = "???"
	
	local productInfoPromise = GetProductInfo(assetId)
	productInfoPromise:andThen(function(productInfo)
		descriptionLabel.Text = productInfo.Name
		previewImage.Image = "rbxthumb://type=Asset&id=" .. productInfo.AssetId .. "&w=150&h=150"

		if productInfo.IsPublicDomain then
			overlayButtons.Button2.Text = "Free"
		elseif productInfo.IsForSale then
			overlayButtons.Button2.Text = productInfo.PriceInRobux .. " Robux"
		else
			overlayButtons.Button2.Text = "Offsale"
		end
		
		maid:GiveTask(overlayButtons.Button2.Activated:Connect(function(inputObject)
			Marketplace:PromptPurchase(player, assetId)
			maid:DoCleaning()
		end))
	end)
	:catch(warn)
	
	maid:GiveTask(function()
		productInfoPromise:cancel()
		descriptionLabel.Text = ""
		previewImage.Image = ""
		overlayButtons.Button2.Text = "???"
	end)
end


function Class:PromptCostume(callback)
	local maid = self.Listeners
	
	local frame = self.CreateFrame
	local overlayButtons = frame.Buttons
	local textBox = frame.Body.Info.Search.TextBox
	
	self:_setup(frame)
	
	frame.Body.Info.TextLabel.Visible = false -- TODO error messages?
	
	local mask = GuiLib.Classes.TextMask.new(textBox)
	maid:GiveTask(mask)
	
	mask:SetMaskType("Alphanumberic")
	mask:SetMaxLength(20)
	
	local function onFocusLost()
		if textBox.Text ~= "" then
			callback(textBox.Text)
			maid:DoCleaning()
		end
	end
	
	maid:GiveTask(mask.Frame.FocusLost:Connect(function(enterPressed, inputThatCausedFocusLoss)
		if not enterPressed then
			return
		end
		onFocusLost()
	end))
	
	maid:GiveTask(overlayButtons.Button2.Activated:Connect(function(inputObject)
		onFocusLost()
	end))
	
	maid:GiveTask(function()
		textBox.Text = ""
	end)
	
	textBox:CaptureFocus()
end


function Class:PromptConfirm(configTable, callback)
	local maid = self.Listeners
	
	local frame = self.ConfirmFrame
	local overlayButtons = frame.Buttons
	
	frame.Body.TextLabel.Text = configTable.Title or "Confirm"
	frame.Body.MessageLabel.Text = configTable.Text or "Are you sure you want to do this action?"
	
	maid:GiveTask(overlayButtons.Button2.Activated:Connect(function(inputObject)
		callback()
		maid:DoCleaning()
	end))
	
	self:_setup(frame)
end


function Class:_setup(frame)
	local maid = self.Listeners
	local tweenSpring = self.TweenSpring
	
	local overlayButtons = frame.Buttons
	
	maid:GiveTask(overlayButtons.Button1.Activated:Connect(function(inputObject)
		maid:DoCleaning()
	end))
	
	maid:GiveTask(frame.Parent.Activated:Connect(function(inputObject)
		maid:DoCleaning()
	end))
	
	maid:GiveTask(function()
		frame.Visible = false
		tweenSpring.Target = 1
	end)
	
	frame.Visible = true
	tweenSpring.Target = 0
end


function Class:Destroy()
	self.Maid:DoCleaning()
	self.Maid = nil
	self.Listeners:DoCleaning()
	self.Listeners = nil
	self.Frame = nil
	self.PurchaseFrame = nil
	self.CreateFrame = nil
	self.ConfirmFrame = nil
	self.TweenSpring = nil
	setmetatable(self, nil)
end


return Class