local q=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local Q=q:WaitForChild("\077\111\100\117\108\101\115")local R=game:GetService("\067\111\110\116\101\120\116\065\099\116\105\111\110\083\101\114\118\105\099\101")local j=require(Q.src.utils.Logger)local E=((game:GetService("\083\116\097\114\116\101\114\080\108\097\121\101\114")):WaitForChild("\083\116\097\114\116\101\114\080\108\097\121\101\114\083\099\114\105\112\116\115")).clientSrc local x=require(E.Components.common.UICorner)local F=require(E.Components.common.YAxisBillboard)local J=require(Q.Roact)local S=require(E.Components.common.UIPadding)local k=require(Q.src.TouchItem)local i=require(E.getApiFromComponent)local g=J.createElement local X=J.PureComponent:extend("\066\105\108\108\098\111\097\114\100\066\117\121\066\117\116\116\111\110")function X.init(q)q.api=i(q)q.triggerRef=J.createRef()end function X.didMount(q)local Q=q.triggerRef.current local function E(Q,R)if R==Enum.UserInputState.Begin then q.props.onClicked()end end q.connection=k.create(Q,function()j:d("\065\100\100\101\100 \073\110\116\101\114\097\099\116 \098\105\110\100")R:BindAction("\073\110\116\101\114\097\099\116",E,true,Enum.KeyCode.E,Enum.KeyCode.ButtonR1)q:setState(function()return{interactActive=true}end)R:SetTitle("\073\110\116\101\114\097\099\116","\066\117\121")end,function()j:d("\082\101\109\111\118\101\100 \073\110\116\101\114\097\099\116 \098\105\110\100")R:UnbindAction("\073\110\116\101\114\097\099\116")q:setState(function()return{interactActive=false}end)end)end function X.willUnmount(q)if q.connection then q.connection.Disconnect()q.connection=nil R:UnbindAction("\073\110\116\101\114\097\099\116")end end function X.render(q)local Q=q.props local R=Q.CFrame local j=q.state.interactActive local E=g("\084\101\120\116\066\117\116\116\111\110",{LayoutOrder=2;TextScaled=true;TextSize=30,AnchorPoint=Vector2.new(0,0);TextXAlignment=Enum.TextXAlignment.Center,TextYAlignment=Enum.TextYAlignment.Center,BackgroundTransparency=.7,BackgroundColor3=Color3.fromRGB(255,255,255);BorderColor3=Color3.fromRGB(255,255,255);Size=UDim2.new(1,0,1,0),Text="\069",Transparency=.2;TextColor3=Color3.fromRGB(0,0,0),[J.Event.MouseButton1Click]=function() end},{UICorner=g(x,{CornerRadius=UDim.new(0,100)});UIPadding=g(S,{padding=5})})local k=g(F,{position=(R*CFrame.new(Vector3.new(0,0,-3))).Position,size=Vector2.new(1.5,1.5),onClicked=Q.onClicked},{eText=E})local i=13 local X=g("\080\097\114\116",{Size=Vector3.new(i,i,i),Position=(R*CFrame.new(Vector3.new(0,0,-3))).Position,Transparency=1,Anchored=true;Orientation=Vector3.new(0,0,90);Shape="\067\121\108\105\110\100\101\114";CanCollide=false;[J.Ref]=q.triggerRef})return J.createFragment({triggerPart=X,labelE=j and k or nil})end return X
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local Modules = ReplicatedStorage:WaitForChild('Modules')

local ContextActionService = game:GetService('ContextActionService')

local logger = require(Modules.src.utils.Logger)
local clientSrc = game:GetService('StarterPlayer'):WaitForChild('StarterPlayerScripts').clientSrc
local UICorner = require(clientSrc.Components.common.UICorner)
local YAxisBillboard = require(clientSrc.Components.common.YAxisBillboard)
local Roact = require(Modules.Roact)
local UIPadding = require(clientSrc.Components.common.UIPadding)
local TouchItem = require(Modules.src.TouchItem)
local getApiFromComponent = require(clientSrc.getApiFromComponent)
local createElement = Roact.createElement
local BillboardBuyButton = Roact.PureComponent:extend('BillboardBuyButton')

function BillboardBuyButton:init()
	self.api = getApiFromComponent(self)
	self.triggerRef = Roact.createRef()
end

function BillboardBuyButton:didMount()
	local touchPart = self.triggerRef.current

	local function handleAction(actionName, inputState)
		if inputState == Enum.UserInputState.Begin then
			self.props.onClicked()
		end
	end

	self.connection = TouchItem.create(
		touchPart,
		function()
			logger:d('Added Interact bind')
			ContextActionService:BindAction(
				'Interact',
				handleAction,
				true,
				Enum.KeyCode.E,
				Enum.KeyCode.ButtonR1
			)

			self:setState(function()
				return { interactActive = true }
			end)
			ContextActionService:SetTitle('Interact', 'Buy')
		end,
		function()
			logger:d('Removed Interact bind')
			ContextActionService:UnbindAction('Interact')
			self:setState(function()
				return { interactActive = false }
			end)
		end
	)
end

function BillboardBuyButton:willUnmount()
	if self.connection then
		self.connection.Disconnect()
		self.connection = nil
		ContextActionService:UnbindAction('Interact')
	end
end

function BillboardBuyButton:render()
	local props = self.props
	local cframe = props.CFrame
	local interactActive = self.state.interactActive

	local eText = createElement(
		'TextButton',
		{
			LayoutOrder = 2,
			TextScaled = true,
			TextSize = 30,
			AnchorPoint = Vector2.new(0, 0),
			TextXAlignment = Enum.TextXAlignment.Center,
			TextYAlignment = Enum.TextYAlignment.Center,
			BackgroundTransparency = 0.7,
			BackgroundColor3 = Color3.fromRGB(255, 255, 255),
			BorderColor3 = Color3.fromRGB(255, 255, 255),
			Size = UDim2.new(1, 0, 1, 0),
			Text = 'E',
			Transparency = 0.2,
			TextColor3 = Color3.fromRGB(0, 0, 0),
			[Roact.Event.MouseButton1Click] = function() end,
		},
		{
			UICorner = createElement(UICorner, { CornerRadius = UDim.new(0, 100) }),
			UIPadding = createElement(UIPadding, { padding = 5 }),
		}
	)

	local labelE = createElement(
		YAxisBillboard,
		{
			position = (cframe * CFrame.new(Vector3.new(0, 0, -3))).Position,
			size = Vector2.new(1.5, 1.5),
			onClicked = props.onClicked,
		},
		{ eText = eText }
	)

	local size = 13
	local triggerPart = createElement('Part', {
		Size = Vector3.new(size, size, size),
		Position = (cframe * CFrame.new(Vector3.new(0, 0, -3))).Position,
		Transparency = 1,
		Anchored = true,
		Orientation = Vector3.new(0, 0, 90),
		Shape = 'Cylinder',
		CanCollide = false,
		[Roact.Ref] = self.triggerRef,
	})

	return Roact.createFragment({
		triggerPart = triggerPart,
		labelE = interactActive and labelE or nil,
	})
end

return BillboardBuyButton