using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using C1DataGrid_Demo2010;

namespace C1DataGrid_DefaultLocalization2010
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            Language = System.Windows.Markup.XmlLanguage.GetLanguage(System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName);
            InitializeComponent();
            grid.ItemsSource = GetProducts();
        }

        public static IEnumerable<Product> GetProducts()
        {
            IEnumerable<Product> products = Data.GetProducts((product) => !string.IsNullOrEmpty(product.Element("ProductModelID").Value));
            foreach (var product in products)
            {
                product.ExpirationDate = GetDate(product.StandardCost);
                product.Available = GetAvailable(product.Name);
            }
            return products;
        }

        private static bool? GetAvailable(string seed)
        {
            return (seed.Length % 3 == 0 ? (bool?)true : (seed.Length % 3 == 1 ? (bool?)false : (bool?)null));
        }

        private static DateTime? GetDate(double seed)
        {
            return new DateTime(DateTime.Now.Ticks - ((long)seed * 10000000000));
        }
    }

    public class Models : List<Model>
    {
        public Models()
        {
            foreach (var model in Data.GetModels())
            {
                Add(model);
            }
        }
    }
}
