using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Net;
using Sgml;
using System.Xml;
using System.Xml.Linq;

namespace Azyobuzi.Twirunrun
{
    public class Previewer2
    {
        public Previewer2(Regex matchUri, PreviewDataTypes type, Func<string, Image> getImage)
        {
            this.Type = type;
            this.MatchUri = matchUri;
            this.GetImage = getImage;
        }

        public Previewer2(Regex matchUri, PreviewDataTypes type, Func<string, string> getText)
        {
            this.Type = type;
            this.MatchUri = matchUri;
            this.GetText = getText;
        }

        public PreviewDataTypes Type { private set; get; }

        public Regex MatchUri { private set; get; }

        public Func<string, Image> GetImage { private set; get; }

        public Func<string, string> GetText { private set; get; }

        public static Previewer2[] Previewers
        {
            get
            {
                return new Previewer2[]
                {
                    new Previewer2(new Regex(@"http://tinypaste.com/\w+"), PreviewDataTypes.Text,
                        uri => {
                            XmlDocument doc = new XmlDocument();
                            using(var reader = new SgmlReader(){ CaseFolding = CaseFolding.ToLower, Href = uri })
                            {
                                doc.Load(reader);
                            }
                            return doc.GetElementById("pasteFrame").InnerText;
                        })
                };
            }
        }
    }

   
}
