local assets =
{
	Asset("ANIM", "anim/ice_pack.zip"),
	--Asset("ANIM", "anim/ui_ice_pack_1x2.zip"),
	Asset("ATLAS", "images/inventoryimages/ice_pack.xml"),
	Asset("IMAGE", "images/inventoryimages/ice_pack.tex"),
}

--local params = {}
--local containers = require "containers"
--local prev_widgetsetup=containers.widgetsetup

--[[local function mywidgetsetup(container, prefab, data)
    local t = data or params[prefab or container.inst.prefab]
    if t ~= nil then
        for k, v in pairs(t) do
            container[k] = v
        end
        container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0)
    end
end]]

--------------------------------------------------------------------------
--[[ ice_pack ]]
--------------------------------------------------------------------------

--[[params.ice_pack =
{
    widget =
    {
        slotpos = {},
        animbank = "ui_ice_pack_1x2",
        animbuild = "ui_ice_pack_1x2",
        pos = Vector3(-5,-70,0)
    },
    issidewidget = true,
    type = "pack",
}

for y = 0, 1 do
	table.insert(params.ice_pack.widget.slotpos, Vector3(-162 + (75/2), -75 * y + 114 ,0))
end]]

--------------------------------------------------------------------------

--------------------------------------------------------------------------

local function onopen(inst)
    inst.SoundEmitter:PlaySound("dontstarve/common/icebox_open")
end

local function onclose(inst)
    inst.SoundEmitter:PlaySound("dontstarve/common/icebox_close")
end

local function itemtest(inst, item, slot)
	return (item.components.edible and item.components.perishable) or
	item.prefab == "spoiled_food" or
	item.prefab == "rottenegg" or
	item.prefab == "heatrock" or
	item:HasTag("frozen") or
	item:HasTag("icebox_valid")
end

local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddSoundEmitter()
    inst.entity:AddMiniMapEntity()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("ice_pack")
    inst.AnimState:SetBuild("ice_pack")
    inst.AnimState:PlayAnimation("idle")

	inst.MiniMapEntity:SetIcon("minimap_ice_pack.tex")

	inst:AddTag("fridge")
    inst:AddTag("nocool")

    inst.entity:SetPristine()

    if not TheWorld.ismastersim then
        return inst
    end

    inst:AddComponent("tradable")
    inst:AddComponent("inspectable")

    inst:AddComponent("inventoryitem")
	inst.components.inventoryitem.imagename = "ice_pack"
	inst.components.inventoryitem.atlasname = "images/inventoryimages/ice_pack.xml"

	inst:AddComponent("container")
	inst.components.container.itemtestfn = itemtest
	--containers.widgetsetup = mywidgetsetup
	inst.components.container:WidgetSetup("ice_pack")
	--containers.widgetsetup = prev_widgetsetup

    inst.components.container.onopenfn = onopen
    inst.components.container.onclosefn = onclose

    MakeHauntableLaunchAndSmash(inst)

    return inst
end

STRINGS.NAMES.ICE_PACK 									= "Ice Pack"
STRINGS.RECIPE_DESC.ICE_PACK 							= "Portable Ice Box."

STRINGS.CHARACTERS.GENERIC.DESCRIBE.ICE_PACK 			= "A scientific achievement for food!"
STRINGS.CHARACTERS.WILLOW.DESCRIBE.ICE_PACK 			= "It's a tiny fridge!"
STRINGS.CHARACTERS.WOLFGANG.DESCRIBE.ICE_PACK 			= "Is small, but good for food!"
STRINGS.CHARACTERS.WENDY.DESCRIBE.ICE_PACK 				= "A cold box to match my cold heart."
STRINGS.CHARACTERS.WX78.DESCRIBE.ICE_PACK 				= "THERMALS ARE STABLE"
STRINGS.CHARACTERS.WICKERBOTTOM.DESCRIBE.ICE_PACK 		= "A mobile Ice Box to slow spoilage."
STRINGS.CHARACTERS.WOODIE.DESCRIBE.ICE_PACK 			= "Ma' food will be kept tasty."
STRINGS.CHARACTERS.WAXWELL.DESCRIBE.ICE_PACK 			= "Keeps my suit clean from carrying food around."
STRINGS.CHARACTERS.WATHGRITHR.DESCRIBE.ICE_PACK 		= "A crack into Niflheim."
STRINGS.CHARACTERS.WEBBER.DESCRIBE.ICE_PACK 			= "It's a small ice box."

return Prefab( "common/inventory/ice_pack", fn, assets)
