using System;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Markup;
using System.Collections.Generic;
using System.Xml.Linq;

namespace ControlExplorer
{
    [ContentProperty("Remarks")]
    public class NewFeatureDescription
    {
        public NewFeatureDescription(XElement c)
        {
            Title = c.Attribute("Title").Value;
            ImageSource = new Uri(c.Attribute("ImageSource").Value, UriKind.Relative);
            Remarks = (from f in c.Elements("Remark") select new FeatureRemark(f)).ToList();
        }

        public string Title { get; set; }
        public Uri ImageSource { get; set; }
        public List<FeatureRemark> Remarks { get; set; }
    }

    public class FeatureRemark
    {
        public FeatureRemark(XElement c)
        {
            Description = c.Attribute("Description").Value;
            string link = c.Attribute("Link").Value;
            Link = new Uri(link, link.StartsWith("http") ? UriKind.Absolute : UriKind.Relative);
            var targetName = c.Attribute("TargetName");
            if (targetName != null)
            {
                TargetName = targetName.Value;
            }
        }
        public string Description { get; set; }
        public Uri Link { get; set; }
        public string TargetName { get; set; }

        public bool HasLink
        {
            get
            {
                return (Link != null);
            }
        }
    }
}
