local W={nonFunctionalReturn="\067\111\109\112\111\110\101\110\116 \112\114\111\112\115 \111\118\101\114\114\105\100\101 \109\111\100\117\108\101 \102\111\114 \091\037\115\093 \100\111\101\115 \110\111\116 \114\101\116\117\114\110 \097 \102\117\110\099\116\105\111\110\033"}local function w()local w={}function w.componentAdded(a,w,Z,d)if not typeof(Z)=="\073\110\115\116\097\110\099\101"then return end local p=Z:FindFirstChild("\067\111\109\112\111\110\101\110\116\080\114\111\112\115")if not p then return end if p:IsA("\079\098\106\101\099\116\086\097\108\117\101")then p=p.Value end if not p then return end if not p:IsA("\077\111\100\117\108\101\083\099\114\105\112\116")then return end local o=require(p)assert(typeof(o)=="\102\117\110\099\116\105\111\110",W.nonFunctionalReturn:format(Z:GetFullName()))local c=o()local h=c[d.className]if not h then return end for W,w in pairs(h)do d[W]=w end end return w end return w
local errors = {
    nonFunctionalReturn = "Component props override module for [%s] does not return a function!"
}

local function createComponentPropsOverridePlugin()
    local componentPropsOverridePlugin = {}

    function componentPropsOverridePlugin:componentAdded(core, entity, component)
        if not typeof(entity) == "Instance" then return end -- entity is not an instance, not interested.
        local componentPropsModule = entity:FindFirstChild("ComponentProps")
        if not componentPropsModule then return end -- doesnt exist, not interested
        if componentPropsModule:IsA("ObjectValue") then componentPropsModule = componentPropsModule.Value end
        if not componentPropsModule then return end
        if not componentPropsModule:IsA("ModuleScript") then return end -- not a module script, not interested.

        -- type checkingggg
        local componentPropsOverrideFunc = require(componentPropsModule)
        assert( typeof(componentPropsOverrideFunc) == "function",
            errors.nonFunctionalReturn:format(entity:GetFullName())
        )

        -- create the new override table
        local componentPropsOverride = componentPropsOverrideFunc()
        local thisComponentOverride = componentPropsOverride[component.className]
        if not thisComponentOverride then return end

        -- assign each key,value of the new override to the component
        for key,value in pairs(thisComponentOverride) do
            component[key] = value
        end
    end

    return componentPropsOverridePlugin
end

return createComponentPropsOverridePlugin