using System.IO;
using FairyGUI;
using NBC;
using UnityEngine;

namespace NBF.Utils
{
    public static class ItemHelper
    {
        public static string GetFullModelPath(this cfg.Item config)
        {
            //Assets/ResRaw/gfx/hooks/alliance/c_hook_20789_20794/c_hook_20789.prefab
            return $"Assets/ResRaw/gfx/{config.Model}.prefab"; //Path.Combine("Assets/ResRaw/gfx", config.Model);
        }

        public static ItemType GetItemType(this int id)
        {
            return (ItemType)(id / 10000);
        }
        public static ItemType GetItemType(this uint id)
        {
            return (ItemType)(id / 10000);
        }

        public static string GetName(this int id)
        {
            return Lan.Get($"Name_{id}");
        }

        public static string GetDesc(this int id)
        {
            return Lan.Get($"Desc_{id}");
        }

        public static string GetIcon(this int id)
        {
            //Assets/Resources/Icons/baitfrog.png
            ////$"Icons/{id}";
            return UIPackage.GetItemURL(UIDef.Pack.CommonIcon, id.ToString());
        }

        public static void SetIcon(this GLoader loader, int id)
        {
            loader.url = id.GetIcon();
        }

        public static void SetIcon(this GComponent loader, int id)
        {
            loader.icon = id.GetIcon();
        }

        #region 品质相关

        public static Color QualityColor0 = new Color(1, 1, 1, 0);
        public static Color QualityColor1 = new Color(96 / 255f, 160 / 255f, 224 / 255f, 1);
        public static Color QualityColor2 = new Color(0 / 255f, 138 / 255f, 255 / 255f, 1);
        public static Color QualityColor3 = new Color(126 / 255f, 0 / 255f, 255 / 255f, 1);
        public static Color QualityColor4 = new Color(220 / 255f, 50 / 255f, 50 / 255f, 1);
        public static Color QualityColor5 = new Color(255 / 255f, 108 / 255f, 0 / 255f, 1);

        public static Color GetItemQualityColor(int quality)
        {
            return quality switch
            {
                1 => QualityColor1,
                2 => QualityColor2,
                3 => QualityColor3,
                4 => QualityColor4,
                5 => QualityColor5,
                _ => QualityColor0
            };
        }

        #endregion
    }
}