using GadgetCore.API;
using UnityEngine;

namespace MultiplayerClientSpawn
{
  public static class ItemUtil
  {
    public static int CreatePlacableSpawnItem(string tileImgPath, string itemImgPath, string partAPath, string partBPath, string name)
    {

      Texture2D texturePreview = GadgetCoreAPI.LoadTexture2D(tileImgPath);

      Texture2D textureItem = GadgetCoreAPI.LoadTexture2D(itemImgPath);
      Texture2D texturePartA = GadgetCoreAPI.LoadTexture2D(partAPath);
      Texture2D texturePartB = GadgetCoreAPI.LoadTexture2D(partBPath);

      GameObject gameObject = Object.Instantiate<GameObject>((GameObject)Resources.Load("prop/" + 2403));
      {
        Renderer renderer = gameObject.transform.GetChild(0).gameObject.GetComponentInChildren<Renderer>();
        renderer.material = new Material(Shader.Find("Unlit/Transparent"))
        {
          mainTexture = texturePartA
        };
      }
      {
        Renderer renderer = gameObject.transform.GetChild(1).gameObject.GetComponentInChildren<Renderer>();
        renderer.material = new Material(Shader.Find("Unlit/Transparent"))
        {
          mainTexture = texturePartB
        };
      }
      {
        Renderer renderer = gameObject.transform.GetChild(2).gameObject.GetComponentInChildren<ParticleSystemRenderer>();
        renderer.material = new Material(Shader.Find("Unlit/Transparent"))
        {
          mainTexture = texturePartA
        };
      }

      Component.Destroy(gameObject.GetComponentInChildren<SpawnBlock>());
      gameObject.AddComponent<MultiplayerSpawnBlock>();

      ItemInfo itemInfo = new ItemInfo(ItemType.GENERIC, name, "", textureItem, -1, default, null, null, null, null);
      itemInfo.Register(name, -1, true);
      new TileInfo(TileType.NONSOLID, texturePreview, gameObject, itemInfo).Register(name, -1, true);

      return itemInfo.GetID();
    }
  }
}
