extend("fiskheroes:hero_basic");
loadTextures({
    "layer1": "skarredheroes:bat/batwoman_layer1",
    "layer2": "skarredheroes:bat/batwoman_layer2",
    "mask": "skarredheroes:bat/batwoman_mask",
        "chest": "skarredheroes:bat/batwoman_chest",
        "cape": "skarredheroes:bat/batwoman_cape",
        "capehair": "skarredheroes:bat/batwoman_cape_hair",
		"cape2": "skarredheroes:bat/batwoman_cape2"
});

var capes = implement("fiskheroes:external/capes");

var utils = implement("fiskheroes:external/utils");
var chest;
var cape;

function init(renderer) {
    parent.init(renderer);
    renderer.setTexture((entity, renderLayer) => {
        if (renderLayer == "CHESTPLATE") {
            return entity.getWornHelmet().suitType() == $SUIT_NAME ? "layer1" : "chest";
        }
		if (renderLayer == "HELMET") {
			return entity.getWornChestplate().suitType() == $SUIT_NAME ? "layer1" : "mask";
		}
        return renderLayer == "LEGGINGS" ? "layer2" : "layer1";
    });

    renderer.showModel("HELMET", "head", "headwear", "body");
}

function initEffects(renderer) {
    chest = renderer.createEffect("fiskheroes:chest");
    chest.setExtrude(1.5).setYOffset(1);
    var physics = renderer.createResource("CAPE_PHYSICS", null);
    physics.maxFlare = 0.4;
    physics.flareDegree = 1.5;
    physics.flareFactor = 1.2;
    physics.flareElasticity = 5;

    cape = capes.createGlider(renderer, 24, "fiskheroes:cape_batman.mesh.json", physics);
    cape.effect.texture.set("cape");

    renderer.bindProperty("fiskheroes:equipment_wheel").color.set(0x58161F);
    renderer.bindProperty("fiskheroes:equipped_item").setItems([
        { "anchor": "body", "scale": 0.7, "offset": [-4.5, 10.5, 0.4], "rotation": [110.0, 5.0, 0.0] }
    ]).slotIndex = 0;
}

function render(entity, renderLayer, isFirstPersonArm) {
    if (!isFirstPersonArm && renderLayer == "CHESTPLATE") {
        cape.render(entity, entity.getInterpolatedData("fiskheroes:wing_animation_timer"));
		chest.render();
		if (entity.getEquipmentInSlot(4).nbt().getString('HeroType') == 'skarredheroes:batwoman_comics') {
			if (entity.getData('fiskheroes:gliding')) {
				cape.effect.texture.set("cape2");
			} else {
				cape.effect.texture.set("capehair");
			}
		} else {
			cape.effect.texture.set("cape");
		}
    }
}
