﻿using System.Windows;
using System.Windows.Controls;
using ReactiveUI;
using SN.ExceptionBrowser.Applications.MVVM.ViewModels.Projects;
using SN.ExceptionBrowser.Applications.MVVM.Views.Projects;

namespace SN.ExceptionBrowser.Presentation.Wpf.Views.Projects
{
    /// <summary>
    ///     Interaction logic for ProjectView.xaml
    /// </summary>
    public partial class ProjectView : UserControl, IProjectView
    {
        public static readonly DependencyProperty ViewModelProperty =
            DependencyProperty.Register("ViewModel", typeof (IProjectViewModel), typeof (ProjectView),
                new PropertyMetadata(null));

        public ProjectView()
        {
            InitializeComponent();
            this.WhenActivated(d =>
            {
                d(this.WhenAnyValue(x => x.ViewModel).BindTo(this, v => v.DataContext));
                d(this.OneWayBind(ViewModel, vm => vm.Name, v => v.Name.Text));
                d(this.BindCommand(ViewModel, vm => vm.NavigateCommand, v => v.NavigateTo));
            });
        }

        public IProjectViewModel ViewModel
        {
            get { return (IProjectViewModel) GetValue(ViewModelProperty); }
            set { SetValue(ViewModelProperty, value); }
        }

        object IViewFor.ViewModel
        {
            get { return ViewModel; }
            set { ViewModel = (IProjectViewModel) value; }
        }
    }
}