core = exports.oCore
color, r, g, b = core:getServerColor()
serverColor = color

local priceDivider = 1

mainCategories = {
	[1] = {"walls", "Falak", {
		[1] = {"drawing", "Szerkesztés"},
		[2] = {"paint", "Festék"},
		[3] = {"wallpaper", "Tapéta"},
		[4] = {"tile", "Csempe"},
		[5] = {"ceil", "Plafon"}
	}, "wall"},
	[2] = {"floors", "Padló", {
		[1] = {"wood", "Laminált"},
		[2] = {"tile", "Csempe"},
		[3] = {"carpet", "Padlószőnyeg"}
	}, "floor"},
	[3] = {"doors", "Nyílászáró", {
		[1] = {"doors", "Ajtó"},
		[2] = {"windows", "Ablak"},
	}, "door"},
	[4] = {"furnitures", "Bútor", {}, "furniture"}
}

ppObjects = {
	[2332] = true,
	[2648] = true,
	[14772] = true,
	[1786] = true,
}

prices = {
	["wall"] = 300,

	["texture"] = {
		
	},

	["lock"] = 600,
	["door"] = {
		[1] = 4000,
		[2] = 3000,
		[3] = 8000,
		[4] = 6000,
	},
	
	["window"] = 5000,

	["furnitures"] = {
		[2069] = 750,
		[2023] = 750,
		[1416] = 1500,
		[1417] = 1250,
		[1740] = 750,
		[1741] = 1500,
		[1816] = 750,
		[2025] = 2000,
		[2087] = 1500,
		[2088] = 1750,
		[2089] = 1750,
		[2094] = 1500,
		[2095] = 750,
		[2200] = 1800,
		[2307] = 1750,
		[2323] = 1500,
		[2328] = 1000,
		[2329] = 1750,
		[2330] = 1750,
		[2576] = 2000,
		[2708] = 1500,
		[1700] = 2000,
		[1701] = 2000,
		[1745] = 2000,
		[1793] = 1000,
		[1794] = 2000,
		[1795] = 1000,
		[1796] = 1500,
		[1797] = 2000,
		[1798] = 2000,
		[1799] = 2000,
		[1800] = 750,
		[1801] = 1000,
		[1802] = 2000,
		[1803] = 2250,
		[1812] = 500,
		[2090] = 2000,
		[2298] = 2500,
		[2299] = 2000,
		[2300] = 3000,
		[2301] = 2500,
		[2302] = 1750,
		[2331] = 400,
		[2333] = 750,
		[2563] = 2500,
		[2564] = 5000,
		[2565] = 5000,
		[2566] = 2500,
		[2575] = 2500,
		[14446] = 5000,
		[2571] = 7500,
		[2357] = 5500,
		[2290] = 4000,
		[2239] = 800,
		[2119] = 850,
		[2118] = 1500,
		[2117] = 1100,
		[2116] = 1000,
		[2115] = 1000,
		[2109] = 1000,
		[2111] = 1250,
		[2112] = 1250,
		[2108] = 750,
		[1768] = 2000,
		[1766] = 2000,
		[1764] = 2000,
		[1763] = 1500,
		[1761] = 2500,
		[1760] = 2500,
		[1757] = 2000,
		[1756] = 2000,
		[1753] = 4000,
		[1713] = 2000,
		[1712] = 2000,
		[1710] = 4000,
		[1709] = 7500,
		[1707] = 2000,
		[1706] = 2500,
		[1703] = 5000,
		[1702] = 5000,
		[1742] = 3000,
		[1743] = 3000,
		[1744] = 1250,
		[1754] = 1500,
		[1755] = 1000,
		[1758] = 1000,
		[1759] = 900,
		[1762] = 1000,
		[1765] = 1000,
		[1767] = 1000,
		[1769] = 1000,
		[1814] = 1100,
		[1815] = 950,
		[1817] = 1250,
		[1818] = 1300,
		[1819] = 950,
		[1820] = 950,
		[1822] = 1100,
		[1823] = 1000,
		[2024] = 1300,
		[2046] = 800,
		[2078] = 5000,
		[2081] = 950,
		[2082] = 900,
		[2083] = 900,
		[2084] = 1000,
		[2161] = 1250,
		[2162] = 1250,
		[2163] = 1100,
		[2164] = 1500,
		[2167] = 1000,
		[2191] = 1350,
		[2199] = 1500,
		[2200] = 1500,
		[2204] = 1750,
		[2234] = 850,
		[2235] = 850,
		[2291] = 1500,
		[2292] = 1500,
		[2295] = 800,
		[2462] = 950,
		[1663] = 900,
		[1671] = 950,
		[1704] = 1600,
		[1705] = 1600,
		[1708] = 1200,
		[1711] = 1000,
		[1723] = 3250,
		[1724] = 1600,
		[1726] = 2000,
		[1735] = 1000,
		[1806] = 600,
		[1811] = 700,
		[1998] = 3100,
		[1999] = 2900,
		[2096] = 600,
		[2173] = 1200,
		[2180] = 1000,
		[2184] = 2200,
		[2206] = 1800,
		[2311] = 1500,
		[2313] = 1400,
		[2314] = 1400,
		[2315] = 1500,
		[2319] = 1300,
		[2321] = 1400,
		[2346] = 1000,
		[2370] = 1000,
		[11665] = 10000,
		[2699] = 4000,
		[1235] = 500,
		[2516] = 1400,
		[2517] = 2000,
		[2518] = 400,
		[2519] = 1400,
		[2520] = 2000,
		[2521] = 600,
		[2522] = 1800,
		[2523] = 600,
		[2524] = 600,
		[2525] = 800,
		[2526] = 1600,
		[2527] = 1800,
		[2528] = 900,
		[1778] = 200,
		[2109] = 1000,
		[2111] = 1250,
		[2112] = 1250,
		[2031] = 1500,
		[2030] = 3000,
		[2029] = 1750,
		[1770] = 500,
		[936] = 1500,
		[937] = 1500,
		[941] = 1250,
		[1821] = 500,
		[2014] = 5000,
		[2015] = 5000,
		[2016] = 5000,
		[2018] = 7500,
		[2019] = 7500,
		[2020] = 2500,
		[2021] = 1000,
		[2022] = 5000,
		[2128] = 6000,
		[2129] = 5000,
		[2133] = 5000,
		[2134] = 5000,
		[2137] = 6000,
		[2138] = 6000,
		[2139] = 5000,
		[2140] = 6000,
		[2141] = 6000,
		[2142] = 5000,
		[2143] = 7500,
		[2145] = 5000,
		[2151] = 6000,
		[2152] = 5000,
		[2153] = 5000,
		[2154] = 6000,
		[2155] = 5000,
		[2156] = 5000,
		[2157] = 5000,
		[2158] = 6000,
		[2159] = 5000,
		[2160] = 6000,
		[2303] = 6000,
		[2304] = 5000,
		[2305] = 5000,
		[2334] = 5000,
		[2335] = 5000,
		[2338] = 5000,
		[2341] = 5000,
		[1432] = 5000,
		[1433] = 3000,
		[1594] = 5000,
		[1720] = 750,
		[1721] = 500,
		[1805] = 500,
		[1810] = 500,
		[2079] = 750,
		[2120] = 750,
		[2121] = 500,
		[2124] = 1000,
		[2125] = 500,
		[2350] = 500,
		[2636] = 650,
		[2637] = 3000,
		[2644] = 1500,
		[2762] = 3250,
		[2763] = 1550,
		[2764] = 1600,
		[2788] = 500,
		[2802] = 4000,
		[15036] = 45000,
		[2294] = 9500,
		[2336] = 7500,
		[2337] = 6000,
		[2339] = 5000,
		[2340] = 5000,
		[2127] = 10000,
		[2131] = 10000,
		[2132] = 6000,
		[2135] = 9500,
		[2136] = 6000,
		[2147] = 7500,
		[1429] = 600,
		[1747] = 500,
		[1748] = 500,
		[1749] = 600,
		[1750] = 600,
		[1751] = 600,
		[1752] = 600,
		[1781] = 500,
		[1791] = 550,
		[1792] = 600,
		[2296] = 2250,
		[2297] = 1750,
		[14532] = 1000,
		[1719] = 400,
		[2028] = 400,
		[2421] = 450,
		[2149] = 350,
		[2229] = 1250,
		[2230] = 1000,
		[2231] = 1000,
		[2232] = 1500,
		[2233] = 750,
		[2099] = 2600,
		[2100] = 2600,
		[2101] = 1000,
		[2226] = 1000,
		[2225] = 1250,
		[2227] = 1000,
		[1782] = 350,
		[1783] = 350,
		[1785] = 350,
		[1787] = 350,
		[1790] = 350,
		[2190] = 750,
		[2238] = 500,
		[2196] = 250,
		[2726] = 450,
		[2724] = 500,
		[2725] = 500,
		[3383] = 5000,
		[16151] = 25000,
		[2224] = 2500,
		[2452] = 5000,
		[2627] = 6000,
		[2630] = 4000,
		[2628] = 6000,
		[2629] = 4000,
		[2916] = 300,
		[2915] = 600,
		[1585] = 4000,
		[1584] = 4000,
		[1583] = 4000,
		[2484] = 2000,
		[2491] = 1000,
		[2489] = 300,
		[2490] = 300,
		[2500] = 2500,
		[2581] = 5000,
		[2584] = 6500,
		[1775] = 10000,
		[1776] = 10000,
		[2743] = 40000,
		[1369] = 2500,
		[3065] = 500,
		[1985] = 11000,
		[3534] = 1500,
		[3385] = 1500,
		[2976] = 3000,
		[1829] = 7500,
		[2778] = 30000,
		[2779] = 30000,
		[2872] = 30000,
		[630] = 500,
		[631] = 500,
		[632] = 500,
		[633] = 500,
		[638] = 1000,
		[646] = 1000,
		[948] = 750,
		[949] = 750,
		[950] = 750,
		[1361] = 740,
		[2001] = 1000,
		[2010] = 1000,
		[2011] = 1000,
		[2194] = 300,
		[2195] = 800,
		[2240] = 800,
		[2241] = 800,
		[2244] = 800,
		[2251] = 800,
		[2252] = 400,
		[2253] = 400,
		[2811] = 800,
		[14834] = 1000,
		[7027] = 2000,

		[2332] = 2500,
		
		[2648] = 3000,
		[14772] = 3200,
		[1786] = 10000,
	}
}

local texturePrices = {
	["wall"] = {
		["paint"] = {
			["0,20"] = 100,
		}, --20
		["tile"] = {
			["0,10"] = 150,
			["11,15"] = 200,
			["16,17"] = 150,
			["18,18"] = 200,
			["19,20"] = 150,
		}, --20
		["wallpaper"] = {
			["0,55"] = 135,
			["56,60"] = 120,
			["61,62"] = 150,
			["63,67"] = 120,
			["68,68"] = 130,
		}, --68
	},
	["floor"] = {
		["carpet"] = {
			["0,6"] = 100,
			["7,19"] = 125,
			["20,21"] = 150,
		}, --21
		["tile"] = {
			["0,12"] = 150,
			["13,33"] = 175,
			["34,38"] = 200,
			["39,39"] = 150,
			["40,42"] = 200,
			["43,43"] = 150,
			["44,44"] = 150,
			["45,49"] = 175,
		}, --49
		["wood"] = {
			["0,22"] = 150,
			["23,32"] = 200,
		}, --32
	},
	["ceil"] = {
		["normal"] = {
			["0,20"] = 100,
			["21,25"] = 150,
		}, --25
	},
}

for k2, v2 in pairs(texturePrices) do
	for k, v in pairs(texturePrices[k2]) do
		for k3, v3 in pairs(texturePrices[k2][k]) do
			local iter = split(k3, ",")

			for k4=iter[1], iter[2] do
				prices["texture"][k2 .. "," .. k .. "," .. k4] = v3
			end
		end
	end
end

pricesForDraw = {}
--
function formatMoney(amount)
	amount = math.floor(amount)
	local left,num,right = string.match(tostring(amount),'^([^%d]*%d)(%d*)(.-)$')
	return left..(num:reverse():gsub('(%d%d%d)','%1.'):reverse())..right
end

function thousandsStepper(amount)
	return formatMoney(amount)
end


function adjustPrices(v)
	return math.floor(v/priceDivider*10)/10
end

for k, v in pairs(prices) do
	if type(v) == "number" then
		prices[k] = adjustPrices(v)
	else
		prices[k] = {}

		for k2, v2 in pairs(v) do
			if type(v2) == "number" then
				prices[k][k2] = adjustPrices(v2)
			else
				prices[k][k2] = {}

				for k3, v3 in pairs(v2) do
					prices[k][k2][k3] = adjustPrices(v3)
				end
			end
		end
	end
end

for k, v in pairs(prices) do
	if type(v) == "number" then
		pricesForDraw[k] = thousandsStepper(v)
	else
		pricesForDraw[k] = {}

		for k2, v2 in pairs(v) do
			if type(v2) == "number" then
				pricesForDraw[k][k2] = thousandsStepper(v2)
			else
				pricesForDraw[k][k2] = {}

				for k3, v3 in pairs(v2) do
					pricesForDraw[k][k2][k3] = thousandsStepper(v3)
				end
			end
		end
	end
end

function registerEvent(name, el, cb)
	addEvent(name, true)
	addEventHandler(name, el, cb)
end


hiFis = {
	[2226] = true,
	[2099] = true,
	[2100] = true,
	[2101] = true,
	[2103] = true,
	[2225] = true,
	[2227] = true,
}

useableTvs = {
	[2648] = "tv",
	[14772] = "tv",
	[1786] = "tv",
}