local E=Roact.createElement local S=require(script:WaitForChild("\084\111\111\108\116\105\112"))local c=Roact.PureComponent:extend("\077\111\100\101\084\111\103\103\108\101")function c.init(E)E.Maid=Maid.new()function E.OnInputBegin(S,c,o)if o then return end if c.UserInputType.Name=="\077\111\117\115\101\077\111\118\101\109\101\110\116"then E:setState({IsHovering=true})end end function E.OnInputEnd(S,c,o)if c.UserInputType.Name=="\077\111\117\115\101\077\111\118\101\109\101\110\116"then E:setState({IsHovering=false})end end function E.OnActivated()E.props.Core.Targeting:ToggleTargetingMode()end E:setState({TargetingMode=E.props.Core.Targeting.TargetingMode;IsHovering=false})end function c.didMount(E)local S=E.props.Core.Targeting E.Maid.ModeListener=S.TargetingModeChanged:Connect(function(S)E:setState({TargetingMode=S})end)end function c.willUnmount(E)E.Maid:Destroy()end function c.render(c)local o=c.state.TargetingMode=="\083\099\111\112\101\100"and 0 or c.state.TargetingMode=="\068\105\114\101\099\116"and 14 return Roact.createFragment({ModeToggle=E("\073\109\097\103\101\066\117\116\116\111\110",{BackgroundTransparency=1,Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\052\052\052\053\057\053\057\053\050\051";ImageTransparency=1-(c.state.IsHovering and.5 or.2);ScaleType=Enum.ScaleType.Slice;SliceCenter=Rect.new(4,4,12,12);ImageColor3=Color3.fromRGB(131,131,131),Size=UDim2.new(0,18.0,0,18.0);LayoutOrder=0;[Roact.Event.Activated]=c.OnActivated;[Roact.Event.InputBegan]=c.OnInputBegin,[Roact.Event.InputEnded]=c.OnInputEnd},{Icon=E("\073\109\097\103\101\076\097\098\101\108",{BackgroundTransparency=1,Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\052\052\054\051\048\050\048\056\053\051";ImageTransparency=1-(c.state.IsHovering and 1 or.5);AnchorPoint=Vector2.new(.5,.5);Position=UDim2.new(.5,0,.5,0),Size=UDim2.new(0,14.0,0,14.0),ImageRectOffset=Vector2.new(o,0);ImageRectSize=Vector2.new(14,14)}),Tooltip=E(S,{Visible=c.state.IsHovering,IsToolModeEnabled=c.props.IsToolModeEnabled})}),ModeToggleSpacer=E("\070\114\097\109\101",{BackgroundTransparency=1;Size=UDim2.new(0,0,1,0),LayoutOrder=1})})end return c

local new = Roact.createElement
local Tooltip = require(script:WaitForChild 'Tooltip')

local ModeToggle = Roact.PureComponent:extend 'ModeToggle'

function ModeToggle:init()
    self.Maid = Maid.new()

    --- Processes input, listens for hover start
    function self.OnInputBegin(rbx, Input, WasProcessed)
        if WasProcessed then
            return
        end

        -- Set hovering state
        if Input.UserInputType.Name == 'MouseMovement' then
            self:setState({
                IsHovering = true;
            })
        end
    end

    --- Processes input, listens for hover end
    function self.OnInputEnd(rbx, Input, WasProcessed)
        if Input.UserInputType.Name == 'MouseMovement' then
            self:setState({
                IsHovering = false;
            })
        end
    end

    --- Processes input, and toggles between targeting modes.
    function self.OnActivated()
        self.props.Core.Targeting:ToggleTargetingMode()
    end

    -- Set initial targeting mode
    self:setState({
        TargetingMode = self.props.Core.Targeting.TargetingMode;
        IsHovering = false;
    })
end

function ModeToggle:didMount()
    local Targeting = self.props.Core.Targeting
    self.Maid.ModeListener = Targeting.TargetingModeChanged:Connect(function (NewTargetingMode)
        self:setState({
            TargetingMode = NewTargetingMode;
        })
    end)
end

function ModeToggle:willUnmount()
    self.Maid:Destroy()
end

function ModeToggle:render()
    local IconSpritesheetPosition = (self.state.TargetingMode == 'Scoped' and 0) or
                                    (self.state.TargetingMode == 'Direct' and 14)
    return Roact.createFragment({
        ModeToggle = new('ImageButton', {
            BackgroundTransparency = 1;
            Image = 'rbxassetid://4445959523';
            ImageTransparency = 1 - (self.state.IsHovering and 0.5 or 0.2);
            ScaleType = Enum.ScaleType.Slice;
            SliceCenter = Rect.new(4, 4, 12, 12);
            ImageColor3 = Color3.fromRGB(131, 131, 131);
            Size = UDim2.new(0, 36/2, 0, 36/2);
            LayoutOrder = 0;
            [Roact.Event.Activated] = self.OnActivated;
            [Roact.Event.InputBegan] = self.OnInputBegin;
            [Roact.Event.InputEnded] = self.OnInputEnd;
        },
        {
            Icon = new('ImageLabel', {
                BackgroundTransparency = 1;
                Image = 'rbxassetid://4463020853';
                ImageTransparency = 1 - (self.state.IsHovering and 1 or 0.5);
                AnchorPoint = Vector2.new(0.5, 0.5);
                Position = UDim2.new(0.5, 0, 0.5, 0);
                Size = UDim2.new(0, 28/2, 0, 28/2);
                ImageRectOffset = Vector2.new(IconSpritesheetPosition, 0);
                ImageRectSize = Vector2.new(14, 14);
            });
            Tooltip = new(Tooltip, {
                Visible = self.state.IsHovering;
                IsToolModeEnabled = self.props.IsToolModeEnabled;
            });
        });
        ModeToggleSpacer = new('Frame', {
            BackgroundTransparency = 1;
            Size = UDim2.new(0, 0, 1, 0);
            LayoutOrder = 1;
        });
    })
end

return ModeToggle
