local o=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local i=o:WaitForChild("\099\111\109\109\111\110")local u=require(i:WaitForChild("\065\115\115\101\116\115"))local b=require(i.util:WaitForChild("\098\121"))local Q=(require(i.util:WaitForChild("\099\111\109\112\105\108\101\083\117\098\109\111\100\117\108\101\115\084\111\065\114\114\097\121")))(script,true)local c=b("\105\100",Q)local U=u.basic local C={[1]=75,[2]=250,[3]=750,[4]=3000,[5]=10000;[6]=25000}for o,i in pairs(U)do local u={id=o;price=C[i.rarity or 1],onSale=true}if not c[o]then table.insert(Q,u)end end local function A(o,i)local u,b=2,3 while u<=#o do if i(o[u-1],o[u])then u=b b=b+1 else o[u-1],o[u]=o[u],o[u-1]u=u-1 if u==1 then u=b b=b+1 end end end end local function V(o,i)local b=u.byId[o.id]local Q=u.byId[i.id]local c=o.price<i.price local U=b.rarity<=Q.rarity return c and U end A(Q,V)return{all=Q;byId=b("\105\100",Q)}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local common = ReplicatedStorage:WaitForChild("common")

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

local by = require(common.util:WaitForChild("by"))
local products = require(common.util:WaitForChild("compileSubmodulesToArray"))(script, true)
local rawProductsById = by("id", products)
-- Compile basic assets based on rarity
local basicAssets = Assets.basic

-- generic price table for basic assets
local priceTable = {
    [1] = 75,
    [2] = 250,
    [3] = 750,
    [4] = 3000,
    [5] = 10000,
    [6] = 25000,
}

for id, asset in pairs(basicAssets) do
    local newProduct = {
        id = id,
        price = priceTable[asset.rarity or 1],
        onSale = true,
    }
    if not rawProductsById[id] then
        table.insert(products,newProduct)
    end
end

local function gnomeSort(a, comp)
    local i, j = 2, 3

    while i <= #a do
        if comp(a[i-1],a[i]) then
            i = j
            j = j + 1
        else
            a[i-1], a[i] = a[i], a[i-1] -- swap
            i = i - 1
            if i == 1 then -- 1 instead of 0
                i = j
                j = j + 1
            end
        end
    end
end

local function comparison(product1,product2)
    local asset1 = Assets.byId[product1.id]
    local asset2 = Assets.byId[product2.id]



    local isLessExpensive = (product1.price < product2.price)
    local isLessOrEqualRarity = (asset1.rarity <= asset2.rarity)
    return isLessExpensive and isLessOrEqualRarity
end

gnomeSort(products,comparison)

return {
    all = products,
    byId = by("id", products),
}