local assets =
{ 
    Asset("ANIM", "anim/hollowhat.zip"),
    Asset("ANIM", "anim/hollowhat_swap.zip"), 

    Asset("ATLAS", "images/inventoryimages/hollowhat.xml"),
    Asset("IMAGE", "images/inventoryimages/hollowhat.tex"),
}

local prefabs = 
{
}

local function OnEquip(inst, owner) 
    owner.AnimState:OverrideSymbol("swap_hat", "hollowhat_swap", "swap_hat")
	
	if inst.components.fueled then
		inst.components.fueled:StartConsuming()
	end
    owner.AnimState:Show("HAT")
    owner.AnimState:Show("HAT_HAIR")
    owner.AnimState:Hide("HAIR_NOHAT")
    owner.AnimState:Hide("HAIR")

    if owner:HasTag("player") then
        owner.AnimState:Hide("HEAD")
        if TheSim:GetGameID()=="DST" then
			owner.AnimState:Show("HEAD_HAT")
		else
			owner.AnimState:Show("HEAD_HAIR")
		end
    end
end

local function OnUnequip(inst, owner) 

	if inst.components.fueled then
		inst.components.fueled:StopConsuming()
	end

    owner.AnimState:Hide("HAT")
    owner.AnimState:Hide("HAT_HAIR")
    owner.AnimState:Show("HAIR_NOHAT")
    owner.AnimState:Show("HAIR")

    if owner:HasTag("player") then
        owner.AnimState:Show("HEAD")
        if TheSim:GetGameID()=="DST" then
			owner.AnimState:Hide("HEAD_HAT")
		else
			owner.AnimState:Hide("HEAD_HAIR")
		end
    end
end

local function fn()

    local inst = CreateEntity()
    
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
	inst.entity:AddSoundEmitter()

    MakeInventoryPhysics(inst)

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

    inst:AddTag("hat")

	if TheSim:GetGameID()=="DST" then
		inst.entity:AddNetwork()
		
		if not TheWorld.ismastersim then
			return inst
		end
		
		inst.entity:SetPristine()
		
		MakeHauntableLaunch(inst)
	end

    inst:AddComponent("inspectable")

    inst:AddComponent("tradable")

    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem.imagename = "hollowhat"
    inst.components.inventoryitem.atlasname = "images/inventoryimages/hollowhat.xml"
    
	inst:AddComponent("fueled")
	if TheSim:GetGameID()=="DST" then --Don't ask -M
		inst.components.fueled.fueltype = FUELTYPE.USAGE
	else
		inst.components.fueled.fueltype = "USAGE"
	end
	inst.components.fueled.no_sewing = true
	inst.components.fueled:InitializeFuelLevel(400)
	inst.components.fueled:SetDepletedFn(inst.Remove)
	
    inst:AddComponent("equippable")
    inst.components.equippable.equipslot = EQUIPSLOTS.HEAD
    inst.components.equippable:SetOnEquip(OnEquip)
	inst.components.equippable.dapperness = -TUNING.DAPPERNESS_LARGE
	inst.components.equippable.walkspeedmult = 1.6
    inst.components.equippable:SetOnUnequip(OnUnequip)
	
	--if TheSim:GetGameID()=="DST" or IsDLCEnabled(REIGN_OF_GIANTS) then
		inst:AddComponent("waterproofer")
		inst.components.waterproofer:SetEffectiveness(TUNING.WATERPROOFNESS_SMALL)
	--end

    return inst
end

return  Prefab("common/inventory/hollowhat", fn, assets, prefabs)