using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;

namespace OVCS.Tools
{
    /// <summary>
    /// 表情、头像、聊天时间 格式渲染
    /// </summary>
    public static class CommonHelper
    {
        public static string commentEmotion = AppDomain.CurrentDomain.BaseDirectory + "Emotion\\";
        public static string[] ImageExtensions = new string[] { "bmp", "jpeg", "png", "jpg" };
        private static Dictionary<string, Image> headDict = TextChatControl.ImageHeadList;
        public static void ShowToolTip(string str)
        {
            //App.Current.Dispatcher.Invoke((Action)(() =>
            //{

            //}));
        }
        /// <summary>
        /// 渲染聊天时间格式
        /// </summary>
        /// <param name="date"></param>
        /// <returns></returns>
        public static string ShowLastMsgTime(DateTime date)
        {
            string v = date.ToString("yyy-MM-dd");
            string v1 = DateTime.Now.ToString("yyy-MM-dd");
            if (v == v1)
            {
                string str = "上午";
                int v2 = int.Parse(date.ToString("HH"));
                if (v2 > 12)
                {
                    str = "下午";
                }
                string dateTime = date.ToString("h:mm");
                if (!dateTime.Contains(str))
                {
                    dateTime = str + dateTime;
                }
                return dateTime;
            }
            return date.ToString("yyyy-MM-dd");
        }

        /// <summary>
        /// 根据登录者id获取头像
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Image GetUserHeadByID(string id)
        {
            string index = "1";
            String str = id.Last().ToString();
            Regex _numericregex = new Regex(@"^[-]?[0-9]+(\.[0-9]+)?$");
            bool isExist = _numericregex.IsMatch(str);
            if (isExist)
            {
                int last = int.Parse(str);
                if (last % 2 == 0)
                {
                    index = "2";
                }
                else
                {
                    index = "3";
                }
            }
            Image image = headDict[index];
            if (image == null)
            {
                return null;
            }
            return image;
        }


        /// <summary>
        /// 加载头像图片资源
        /// </summary> 
        //public static void LoadImageSource()
        //{
        //    for (int i = 1; i < 4; i++)
        //    {
        //        string imgPath = $"{AppDomain.CurrentDomain.BaseDirectory}Head\\{i}.png";
        //        //Image headImg = new Image(new Uri(imgPath));
        //        //headDict.Add(i.ToString(), headImg);
        //    }
        //}

    }
}
