//---------------------------------------------------------------------------------------------
// This file was AUTO-GENERATED by "WPF Views" Xomega.Net generator.
//
// Manual CHANGES to this file WILL BE LOST when the code is regenerated.
//---------------------------------------------------------------------------------------------

using AdventureWorks.Client.ViewModels;
using Microsoft.Extensions.DependencyInjection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Xomega.Framework;
using Xomega.Framework.Views;

namespace AdventureWorks.Client.Wpf
{
    public partial class SalesOrderListView
    {
        protected SalesOrderListViewModel VM => Model as SalesOrderListViewModel;

        public SalesOrderListView()
        {
            LinkDetails_Command = new RelayCommand<DataRow>(LinkDetails_Execute, LinkDetails_Enabled);
            LinkNew_Command = new RelayCommand<object>(LinkNew_Execute, LinkNew_Enabled);
            InitializeComponent();
            IsAsync = true;
        }

        #region LinkDetails_Command

        public ICommand LinkDetails_Command { get; set; }

        public virtual async void LinkDetails_Execute(DataRow row)
        {
            if (VM == null) return;
            WPFView cur = pnlDetails.Content as SalesOrderView;
            WPFView tgt = cur ?? VM.ServiceProvider.GetService<SalesOrderView>();
            tgt.Owner = this;
            await VM.LinkDetails_CommandAsync(tgt, cur, row);
        }

        public virtual bool LinkDetails_Enabled(DataRow row)
            => VM != null && VM.LinkDetails_Enabled(row);

        #endregion

        #region LinkNew_Command

        public ICommand LinkNew_Command { get; set; }

        public virtual async void LinkNew_Execute(object arg)
        {
            if (VM == null) return;
            WPFView cur = pnlDetails.Content as SalesOrderView;
            WPFView tgt = cur ?? VM.ServiceProvider.GetService<SalesOrderView>();
            tgt.Owner = this;
            await VM.LinkNew_CommandAsync(tgt, cur);
        }

        public virtual bool LinkNew_Enabled(object arg)
            => VM != null && VM.LinkNew_Enabled();

        #endregion

        protected override TextBlock TitleControl => viewTitle;
        protected override Button CloseButton => btnClose;
        protected override IErrorPresenter ErrorsPanel => pnlErrors;
        protected override Button SearchButton => btnSearch;
        protected override Button SelectButton => btnSelect;

        protected override ItemsControl ResultsGrid => gridResults;
        protected override Button ResetButton => btnReset;
        protected override IAppliedCriteriaPanel AppliedCriteriaPanel => pnlAppliedCriteria;
        protected override ICollapsiblePanel CriteriaExpander => new ExpanderCollapsiblePanel(pnlCriteria);
        protected override FrameworkElement CriteriaPanel => pnlCriteria;
        protected override ContentControl ChildPanel => pnlDetails;
    }
}