using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The User Control item template is documented at http://go.microsoft.com/fwlink/?LinkId=234236

namespace BarCodeSamples
{
    public sealed partial class Editor : UserControl
    {
        public Editor()
        {
            this.InitializeComponent();
        }

        public Format CurrentCategory
        {
            get { return (Format)GetValue(CurrentCategoryProperty); }
            set
            {
                SetValue(CurrentCategoryProperty, value);
            }
        }


        public static readonly DependencyProperty CurrentCategoryProperty =
            DependencyProperty.Register(
                "CurrentCategory",
                typeof(Format),
                typeof(Editor),
                new PropertyMetadata(Format.Url, OnCurrentCategoryPropertyChanged));
        
        private static void OnCurrentCategoryPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var editor = d as Editor;
            if (e.NewValue != null)
            {
                Format newValue = (Format)e.NewValue;
                editor.CurrentEditorControl.Children.Clear();
                UserControl control = null;
                switch (newValue)
                {
                    case Format.Url:
                        control = new Url();
                        editor.DataContext = new UrlEntity() { Url = "http://www.componentone.com" };
                        break;
                    case Format.Text:
                        control = new Text();
                        editor.DataContext = new TextEntity() { Text = "Welcome to use C1BarCode control" };
                        break;
                    case Format.Email:
                        control = new Email();
                        editor.DataContext = new EmailEntity() { Address ="sales@componentone.com" };
                        break;
                    case Format.VCard:
                        control = new VCard();
                        editor.DataContext = new VCardEntity()
                        {
                            Prefix = "Mr",
                            FirstName = "C1",
                            LastName = "Sales",
                            HomeCountry = "US",
                            Suffix = "Jr",
                            FullName = "Mr.C1.Sales.Jr",
                            Nickname = "C1Sales",
                            Title = "Developer",
                            Photo = "myimage.jpg",
                            Role = "Software developer"
                        };
                        break;
                }
                if (control != null)
                {
                    editor.CurrentEditorControl.Children.Add(control);
                }
            }
        }
    }
}
