using Oraycn.ChatRendering;
using OVCS.ClientWpf.Tools;
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace OVCS.ClientWpf
{
    class RenderDataProvider : IRenderDataProvider
    {
        public RenderDataProvider()
        {

        }
        public string GetSpeakerDisplayName(string speakerID)
        {
            return speakerID;
        }

        public string GetUserName(string userID)
        {
            return userID;
        }
        public object GetUserHeadImage(string userID)
        {
            return CommonHelper.GetUserHeadByID(userID);
        }
        public static ImageSource Bitmap2ImageSource(System.Drawing.Bitmap bitmap)
        {
            IntPtr hBitmap = bitmap.GetHbitmap();
            ImageSource wpfBitmap = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                hBitmap,
                IntPtr.Zero,
                Int32Rect.Empty,
                System.Windows.Media.Imaging.BitmapSizeOptions.FromEmptyOptions());
            if (!DeleteObject(hBitmap))//记得要进行内存释放。否则会有内存不足的报错。
            {
                throw new System.ComponentModel.Win32Exception();
            }
            return wpfBitmap;
        }

        [DllImport("gdi32.dll", SetLastError = true)]
        private static extern bool DeleteObject(IntPtr hObject);


        public object GetImageOfFileType(string fileExtendName)
        {
            BitmapImage bitmapImage = ResourceManager.Singleton.MicEnableImage;
            return bitmapImage;
        }
        public string GetFilePathToSave(string fileName)
        {
            return "D:\\"+fileName;
        }
        public Dictionary<int, object> GetEmotions()
        {
            Dictionary<int, object> dictionary = new Dictionary<int, object>();
            List<ImageSource> emotionList =  new EmotionPanel().EmotionList;
            for (int i = 0; i < emotionList.Count; i++)
            {
                dictionary.Add(i, emotionList[i]);
            }
            return dictionary;
        }
        public object GetImageOfSendFailed()
        {
            return null;
        }

        public object GetImageOfVideoCall()
        {
            return null;
        }

        public object GetImageOfAudioCall()
        {
            return null;
        }
    }
}
