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



]]

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
