local z=script.Parent.Parent return function(a)local m=require(z.Bundles)local x=m.data local g=m.themeSystem local M=m.icons local W=m.Fusion local A=W.New local S=W.Children local l=W.Value local h=W.Observer local R=W.OnEvent local j=W.Computed local T=require(z.utilities)local d=T.get local H=T.animate local o=T.typecheck local G=T.customFont local N=require(z.simpleElements)local L=N.UIListLayout local I=Enum.SortOrder local J=Enum.FillDirection local k=Enum.HorizontalAlignment local X=Enum.VerticalAlignment local E=N.UIPadding local Z=N.UICorner local F=a.Parent local Q=a.tab local Y=l(0)local p=l(true)local e=(A("\070\114\097\109\101"))({Visible=p,Parent=F;Size=UDim2.new(1,0,0,36);BackgroundTransparency=1;[S]={L(I.LayoutOrder,J.Horizontal,k.Left,X.Center,UDim.new(0,3))}})local i=l(e.AbsoluteSize)local D={}function D.Button(a,z)local m,W=o(z,{Name="",DisabledText="",IsEnabled=false;Visible=false,Callback=function() end},{z.IsEnabled and""or"\073\115\069\110\097\098\108\101\100";z.Visible and""or"\086\105\115\105\098\108\101";z.DisabledText and""or"\068\105\115\097\098\108\101\100\084\101\120\116"})assert(m,table.concat(W,"\n"))local T=x.find("\115\101\108\101\099\116\101\100\084\097\098")local N=x.find("\115\101\097\114\099\104\084\101\120\116")local L=x.add(z)local I=z.Name local J=z.Callback local k=z.IsEnabled or l(true)local X=z.DisabledText or l("\067\111\109\112\111\110\101\110\116 \068\105\115\097\098\108\101\100")local F=z.Visible or l(true)local p=l(d(T.string)==(d(Q)).uid);(h(T.string)):onChange(function()p:set(d(T.string)==(d(Q)).uid)end)local D=H(function()return d(p)and 0 or 1 end,40,1);(A("\084\101\120\116\066\117\116\116\111\110"))({Interactable=j(function()if not d(k)then return false end return d(p)end),Visible=j(function()if d(N.string)~=""and not string.find((d(I)):lower(),(d(N.string)):lower())or not d(F)then return false end return true end),Size=j(function()return UDim2.new(1/d(Y)-(d(Y)-1==0 and 0 or(((d(Y)-1)*3)/d(Y))/(d(i)).X),0,0,36)end);Parent=e,BackgroundColor3=g.background2,BackgroundTransparency=D;[R("\065\099\116\105\118\097\116\101\100")]=function()if not d(k)then return end task.spawn(d(J))end,[S]={Z(6);(A("\070\114\097\109\101"))({ZIndex=2,Visible=j(function()if not d(k)then return true end return false end);BackgroundTransparency=H(function()return d(p)and.2 or 1 end,40,1);BackgroundColor3=g.disabledBackground;Size=UDim2.fromScale(1,1);[S]={Z(6),(A("\073\109\097\103\101\076\097\098\101\108"))({Size=UDim2.fromOffset(24,24);AnchorPoint=Vector2.new(0,.5);Position=UDim2.new(0,5,.5,0);BackgroundTransparency=1;Image=M.lock;ImageColor3=g.disabledText;ImageTransparency=D});(A("\084\101\120\116\076\097\098\101\108"))({FontFace=G("\077\111\110\116\115\101\114\114\097\116",Enum.FontWeight.Bold);BackgroundTransparency=1;Size=UDim2.new(1,-24,0,18),TextColor3=g.disabledText;TextTransparency=D,TextScaled=true;AnchorPoint=Vector2.new(0,.5),Position=UDim2.new(0,29,.5,0);Text=X;TextXAlignment=Enum.TextXAlignment.Left,RichText=true;[S]={E(0,5)}})}});(A("\070\114\097\109\101"))({Size=UDim2.fromScale(1,1);BackgroundTransparency=1;[S]={E(0,8);(A("\084\101\120\116\076\097\098\101\108"))({FontFace=G("\077\111\110\116\115\101\114\114\097\116",Enum.FontWeight.Bold),Size=UDim2.new(1,-32,0,18);BackgroundTransparency=1;TextColor3=g.text;TextScaled=true;AnchorPoint=Vector2.new(0,.5),Position=UDim2.new(0,0,.5,0);Text=I,TextTransparency=D,TextXAlignment=Enum.TextXAlignment.Left,RichText=true}),(A("\073\109\097\103\101\076\097\098\101\108"))({Size=UDim2.fromOffset(16,16),AnchorPoint=Vector2.new(1,.5),Position=UDim2.new(1,0,.5,0);BackgroundTransparency=1,Image=M.fingerprint,ImageColor3=g.text2,ImageTransparency=H(function()return d(p)and.5 or 1 end,40,1)})}})}})if d(F)then Y:set(d(Y)+1)end;(h(F)):onChange(function()if d(F)then Y:set(d(Y)+1)else Y:set(d(Y)-1)end end)local u={}function u.SetName(a,z)local m,x=o({SetName=z},{SetName=""})assert(m,table.concat(x,"\n"))I:set(z)end function u.SetCallback(a,z)local m,x=o({SetCallback=z},{SetCallback=function() end})assert(m,table.concat(x,"\n"))J:set(z)end function u.Fire(z)task.spawn(d(J))end function u.Enable(z)k:set(true)end function u.Disable(z)k:set(false)end function u.Visible(z)F:set(true)end function u.Invisible(z)F:set(false)end return u end function D.Visible(z)p:set(true)end function D.Invisible(z)p:set(false)end return D end
local darius = script.Parent.Parent
return function(property)
	local Bundles = require(darius.Bundles)
	local data = Bundles.data
	local theme = Bundles.themeSystem
	local icons = Bundles.icons
	local Fusion = Bundles.Fusion
		local new = Fusion.New
		local children = Fusion.Children
		local value = Fusion.Value
		local observe = Fusion.Observer
		local onevent = Fusion.OnEvent
		local computed = Fusion.Computed

	local utilities = require(darius.utilities)
	local get = utilities.get
	local animate = utilities.animate
	local typecheck = utilities.typecheck
	local customFont = utilities.customFont

	local simpleElements = require(darius.simpleElements)
    local UIListLayout = simpleElements.UIListLayout
    local SO = Enum.SortOrder
	local FD = Enum.FillDirection
	local HA = Enum.HorizontalAlignment
	local VA = Enum.VerticalAlignment
	local UIPadding = simpleElements.UIPadding
	local UICorner = simpleElements.UICorner

    -- Property

    local _parent = property.Parent
    local _tab = property.tab

    -- Variables

    local visibleCount = value(0)
    local visible = value(true)

	-- Button Group

    local buttonGroup = new "Frame" {
        Visible = visible,
        Parent = _parent,
		Size = UDim2.new(1,0,0,36),
        BackgroundTransparency = 1,

        [children] = {
            UIListLayout(SO.LayoutOrder,FD.Horizontal,HA.Left,VA.Center,UDim.new(0,3))
        }
    }

    local absSize = value(buttonGroup.AbsoluteSize)

    local returnTable = {}
    function returnTable:Button(_property)

        -- Typecheck

        local didPass, failedItems = typecheck(_property,{
            Name = "",
            DisabledText = "",
            IsEnabled = false,
            Visible = false,
            Callback = function()end
        },{
            _property.IsEnabled and "" or "IsEnabled",
            _property.Visible and "" or "Visible",
            _property.DisabledText and "" or "DisabledText"
        })
        assert(didPass, table.concat(failedItems, "\n"))

        -- Data

        local selectedTab = data.find("selectedTab")
        local searchText = data.find("searchText")
        local button = data.add(_property)

        -- Properties

        local name = _property.Name
        local callback = _property.Callback
        local isEnabled = _property.IsEnabled or value(true)
        local disabledText = _property.DisabledText or value("Component Disabled")
        local _visible = _property.Visible or value(true)

        -- Variables

        local isSelected = value(get(selectedTab.string) == get(_tab).uid)
        observe(selectedTab.string):onChange(function()
            isSelected:set(get(selectedTab.string) == get(_tab).uid)
        end)
        local selectedAnimation = animate(function()
            return get(isSelected) and 0 or 1
        end, 40, 1)

        new "TextButton" {
            Interactable = computed(function()
                if not get(isEnabled) then
                    return false
                end
                return get(isSelected)
            end),
            Visible = computed(function()
                if get(searchText.string) ~= "" and not string.find(get(name):lower(), get(searchText.string):lower()) or not get(_visible) then
                    return false
                end
                return true
            end),
            Size = computed(function()
                return UDim2.new(1/get(visibleCount) - (get(visibleCount) - 1 == 0 and 0 or ((((get(visibleCount)-1)*3)/get(visibleCount))/get(absSize).X)),0,0,36)
            end),
            Parent = buttonGroup,
            BackgroundColor3 = theme.background2,
            BackgroundTransparency = selectedAnimation,

            [onevent "Activated"] = function()
                if not get(isEnabled) then
                    return
                end
                task.spawn(get(callback))
            end,

            [children] = {
                UICorner(6),
                new "Frame" { -- Disabled Frame
                    ZIndex = 2,
                    Visible = computed(function()
                        if not get(isEnabled)  then
                            return true
                        end
                        return false
                    end),
                    BackgroundTransparency = animate(function()
                        return get(isSelected) and 0.2 or 1
                    end,40,1),
                    BackgroundColor3 = theme.disabledBackground,
                    Size = UDim2.fromScale(1,1),

                    [children] = {
                        UICorner(6),
                        new "ImageLabel" { -- Icon
                            Size = UDim2.fromOffset(24,24),
                            AnchorPoint = Vector2.new(0,0.5),
                            Position = UDim2.new(0,5,0.5,0),
                            BackgroundTransparency = 1,
                            Image = icons.lock,
                            ImageColor3 = theme.disabledText,
                            ImageTransparency = selectedAnimation,
                        },
                        new "TextLabel" {
                            FontFace = customFont("Montserrat", Enum.FontWeight.Bold),
                            BackgroundTransparency = 1,
                            Size = UDim2.new(1,-24,0,18),
                            TextColor3 = theme.disabledText,
                            TextTransparency = selectedAnimation,
                            TextScaled = true,
                            AnchorPoint = Vector2.new(0,0.5),
                            Position = UDim2.new(0,29,0.5,0),
                            Text = disabledText,
                            TextXAlignment = Enum.TextXAlignment.Left,
                            RichText = true,

                            [children] = {
                                UIPadding(0,5)
                            }
                        }
                    }
                },
                new "Frame" {
                    Size = UDim2.fromScale(1,1),
                    BackgroundTransparency = 1,
                    [children] = {
                        UIPadding(0,8),
                        new "TextLabel" { -- Title
                            FontFace = customFont("Montserrat", Enum.FontWeight.Bold),
                            Size = UDim2.new(1,-16-16,0,18),
                            BackgroundTransparency = 1,
                            TextColor3 = theme.text,
                            TextScaled = true,
                            AnchorPoint = Vector2.new(0,0.5),
                            Position = UDim2.new(0,0,0.5,0),
                            Text = name,
                            TextTransparency = selectedAnimation,
                            TextXAlignment = Enum.TextXAlignment.Left,
                            RichText = true
                        },
                        new "ImageLabel" { -- Icon
                            Size = UDim2.fromOffset(16,16),
                            AnchorPoint = Vector2.new(1,0.5),
                            Position = UDim2.new(1,0,0.5,0),
                            BackgroundTransparency = 1,
                            Image = icons.fingerprint,
                            ImageColor3 = theme.text2,
                            ImageTransparency = animate(function()
                                return get(isSelected) and 0.5 or 1
                            end, 40, 1)
                        }
                    }
                }
            }
        }

        if get(_visible) then
            visibleCount:set(get(visibleCount) + 1)
        end
        observe(_visible):onChange(function()
            if get(_visible) then
                visibleCount:set(get(visibleCount) + 1)
            else
                visibleCount:set(get(visibleCount) - 1)
            end
        end)

        local returnFunctions = {}
        function returnFunctions:SetName(newText)
            local _didPass, _failedItems = typecheck({['SetName'] = newText}, {SetName = ""})
            assert(_didPass, table.concat(_failedItems, "\n"))

            name:set(newText)
        end
        function returnFunctions:SetCallback(newFunction)
            local _didPass, _failedItems = typecheck({['SetCallback'] = newFunction}, {SetCallback = function()end})
            assert(_didPass, table.concat(_failedItems, "\n"))

            callback:set(newFunction)
        end
        function returnFunctions:Fire()
            task.spawn(get(callback))
        end
        function returnFunctions:Enable()
            isEnabled:set(true)
        end
        function returnFunctions:Disable()
            isEnabled:set(false)
        end
        function returnFunctions:Visible()
            _visible:set(true)
        end
        function returnFunctions:Invisible()
            _visible:set(false)
        end
        return returnFunctions
    end
    function returnTable:Visible()
        visible:set(true)
    end
    function returnTable:Invisible()
        visible:set(false)
    end
	return returnTable
end