using FLY.Thick.Base.UI;
using FLY.Thick.FilmCasting.IService;
using System.Windows;
using Unity;

namespace FLY.Thick.FilmCasting.UI.UiModule
{
    /// <summary>
    /// TrendGraph2.xaml 的交互逻辑
    /// </summary>
    public partial class TrendGraph : System.Windows.Controls.UserControl
    {
        TrendGraphVm viewModel;
        TrendGraphItemParam graphparam;
        public TrendGraph()
        {
            InitializeComponent();
        }

        [InjectionMethod]
        public void Init(int id,
            IBulkDbService bulkDb,
            IFilmCastingProfileService profileService)
        {

            graphparam = TrendGraphParams.Current.Items.Find(p => p.ID == id);
            if (graphparam == null)
            {
                graphparam = new TrendGraphItemParam() { ID = id };
                TrendGraphParams.Current.Items.Add(graphparam);
                TrendGraphParams.Current.Save();
            }
            viewModel = new TrendGraphVm();
            viewModel.Init(graphparam, bulkDb, profileService.Param);
            this.DataContext = viewModel;
        }

        private void Button_info_click(object sender, RoutedEventArgs e)
        {
            if (!WdPassword.Authorize("GraphConfig"))
                return;

            TrendGraphConfig window = new TrendGraphConfig();
            window.Init(graphparam, viewModel);
            window.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
            window.ShowDialog();
        }
    }
}
