using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;

using BeWo.Core;
using BeWo.Core.Service;
using BeWo.ServiceProxy;
using BeWo.ViewModel;
using BeWo.ViewModel.ListViewModel;

using BS.Shared;
using BS.Shared.Extensions;
using System.Windows.Controls;

namespace BeWo.View.Detail
{
    /// <summary>
    /// Interaction logic for EmploymentTypeView.xaml
    /// </summary>
    public partial class EnvironmentRoleView : BeWoView
    {
        private ValueListView personView = null;
        private ValueListView organisationView = null;

        public EnvironmentRoleView(ValueListEntryListVM pViewModelPerson, ValueListEntryListVM pViewModelOrganisation)
        {
            this.InitializeComponent();
            
            personView = new ValueListView(pViewModelPerson);
            organisationView = new ValueListView(pViewModelOrganisation);

            personView.SetValue(Grid.RowProperty, 0);
            organisationView.SetValue(Grid.RowProperty, 1);
            organisationView.Margin = new Thickness(0, 10, 0, 0);

            rootGrid.Children.Add(personView);
            rootGrid.Children.Add(organisationView);
                
        }

        public override bool IsDirty
        {
            get
            {
                bool dirty = this.personView.IsDirty;
                if (!dirty)
                    dirty = this.organisationView.IsDirty;

                return dirty;
            }
        }

        public override string Title
        {
            get
            {
                return null;
            }
        }

        protected override void Save()
        {
            bool valid = true;
            if (this.personView.IsDirty)
                valid = this.personView.SaveData();

            if (valid && this.organisationView.IsDirty)
                this.organisationView.SaveData();
            
        }

        internal override DependencyObject ValidationOnSaveRootElement
        {
            get { return this.borderTemp; }
        }

    }
}