local I=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local F=I:WaitForChild("\099\111\109\109\111\110")local e=I:WaitForChild("\108\105\098")local k=require(F:WaitForChild("\083\104\111\112\080\114\111\100\117\099\116\115"))local c=require(script.Parent.Parent:WaitForChild("\083\101\108\101\099\116\111\114\115"))local t=require(script.Parent.Parent:WaitForChild("\065\099\116\105\111\110\115"))local o={coins=t.COIN_SUBTRACT,candy=t.CANDY_SUBTRACT}return function(I,F)return function(e)local O=k.byId[F]if O then local k=O.currency or"\099\111\105\110\115"if not c.isOwned(e:getState(),I,F)then local p=c.getStats(e:getState(),I)local b=p[k]or 0 if b>=O.price then e:dispatch(o[k](I,O.price))e:dispatch(t.ASSET_GIVE(I,F))end end end end end
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local common = ReplicatedStorage:WaitForChild("common")
local lib = ReplicatedStorage:WaitForChild("lib")

local ShopProducts = require(common:WaitForChild("ShopProducts"))

local Selectors = require(script.Parent.Parent:WaitForChild("Selectors"))
local Actions = require(script.Parent.Parent:WaitForChild("Actions"))

local currencyActions = {
    coins = Actions.COIN_SUBTRACT,
    candy = Actions.CANDY_SUBTRACT,
}

return function(player,assetId)
    return function(store)
        local product = ShopProducts.byId[assetId]
        if product then
            local currencyType = product.currency or "coins"
            if not Selectors.isOwned(store:getState(),player,assetId) then
                local stats = Selectors.getStats(store:getState(),player)
                local ownedCurrency = stats[currencyType] or 0
                if ownedCurrency >= product.price then
                    store:dispatch(currencyActions[currencyType](player,product.price))
                    store:dispatch(Actions.ASSET_GIVE(player,assetId))
                end
            end
        end
    end
end