using System;
using System.Linq;
using System.Net;
using System.Windows;
using System.Collections.Generic;
using System.Xml.Linq;
using Windows.UI.Xaml.Markup;

namespace ControlExplorer
{
    [ContentProperty(Name="Remarks")]
    public class NewFeatureDescription
    {
        public NewFeatureDescription(XElement c)
        {
            Title = c.Attribute("Title").Value;
            //Description = (c.Element("Description") != null) ? c.Element("Description").Value : string.Empty;
            Description = (c.Attribute("Description") != null) ? c.Attribute("Description").Value : string.Empty;
            ControlName = (c.Attribute("ControlName") != null) ? c.Attribute("ControlName").Value : string.Empty;
            ImageSource = (c.Attribute("ImageSource") != null) ? c.Attribute("ImageSource").Value : string.Empty;
            DemoControlTypeName = (c.Attribute("Type") != null) ? c.Attribute("Type").Value : string.Empty;
            string itemsize = (c.Attribute("ItemSize") != null) ? c.Attribute("ItemSize").Value : string.Empty;
            int size;
            ItemSize = int.TryParse(itemsize, out size) ? int.Parse(itemsize) : 1;
            //Remarks = (from f in c.Elements("Remark") select new FeatureRemark(f)).ToList();
        }

        public string Title { get; set; }

        public string DemoControlTypeName { get; set; }
        public string ImageSource { get; set; }
        //public List<FeatureRemark> Remarks { get; set; }

        public string Description { get; set; }

        public string ControlName { get; set; }

        public int ItemSize { 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);
            }
        }
    }
}
