import { EnchantmentType, ItemStack } from "@minecraft/server";
import { MItem_Info } from "./Data/_Buffers/MItem_Info";
import Item_Enchantment_Manager from "./Managers/Item_Enchantment_Manager";
import Item_Durability_Manager from "./Managers/Item_Durability_Manager";
export default class Item_Manager {
    static info(item_ID) {
        const info = MItem_Info.get(item_ID);
        if (info == undefined) {
            const name = item_ID
                .replace("minecraft:", "")
                .replaceAll("_", " ")
                .toLowerCase()
                .split(" ")
                .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
                .join(" ");
            return { texture: "textures/items/apple", name: name };
        }
        return info;
    }
    static new(item) {
        const new_Item = new ItemStack(item.id, item.amount);
        if (item.enchantments != undefined) {
            for (let i = 0; i < item.enchantments.length; i++) {
                const enchantment = {
                    type: new EnchantmentType(item.enchantments[i].type),
                    level: item.enchantments[i].level,
                };
                Item_Enchantment_Manager.add(new_Item, enchantment);
            }
        }
        if (item.durability != undefined)
            Item_Durability_Manager.set(new_Item, item.durability);
        if (item.lore != undefined)
            new_Item.setLore(item.lore);
        if (item.keep_On_Death != undefined)
            new_Item.keepOnDeath = item.keep_On_Death;
        if (item.lock_Mode != undefined)
            new_Item.lockMode = item.lock_Mode;
        if (item.name_Tag != undefined)
            new_Item.nameTag = item.name_Tag;
        if (item.can_Destroy != undefined)
            new_Item.setCanDestroy(item.can_Destroy);
        if (item.can_Place_On != undefined)
            new_Item.setCanPlaceOn(item.can_Place_On);
        return new_Item;
    }
}
