using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using VisionBuilder.UI.Common;

namespace VisionBuilder.UI.Windows.Components
{
    public partial class SingleCameraControl : UserControl
    {
        private SingleCameraVM _singleCameraVm;

        public void SetViewModel(SingleCameraVM singleCameraVm)
        {
            _singleCameraVm = singleCameraVm;
            singleCameraVm.SynchronizationContext = SynchronizationContext.Current;
            this.previewWindow1.SetViewModel(singleCameraVm.PreviewVm);
            this.errorPreview1.SetViewModel(singleCameraVm.ErrorsVm);
            this.stats1.SetViewModel(singleCameraVm.StatisticsVm);

            SetBindings();
            _singleCameraVm.PropertyChanged += SingleCameraVm_PropertyChanged;
        }

        private void SingleCameraVm_PropertyChanged(object? sender, PropertyChangedEventArgs e)
        {
            
        }

        private void SetBindings()
        {
            btnStart.Command=_singleCameraVm.StartCommand;
            btnStop.Command=_singleCameraVm.StopCommand;
            btnSelectRecipe.Command=_singleCameraVm.SelectRecipeCommand;
            btnPause.Command=_singleCameraVm.PauseCommand;
            btnResume.Command=_singleCameraVm.ResumeCommand;

            lblCameraName.DataBindings.Add("Text", _singleCameraVm, nameof(_singleCameraVm.CameraLabelAndStatus), true, DataSourceUpdateMode.OnPropertyChanged);
            btnSelectRecipe.DataBindings.Add("Text", _singleCameraVm, nameof(_singleCameraVm.CurrentRecipeName), true, DataSourceUpdateMode.OnPropertyChanged);
            btnStart.DataBindings.Add(nameof(btnStart.Visible), _singleCameraVm, nameof(_singleCameraVm.CanStart), true, DataSourceUpdateMode.OnPropertyChanged);
            btnStop.DataBindings.Add(nameof(btnStop.Visible), _singleCameraVm, nameof(_singleCameraVm.CanStop), true, DataSourceUpdateMode.OnPropertyChanged);
            btnSelectRecipe.DataBindings.Add(nameof(btnSelectRecipe.Primary), _singleCameraVm, nameof(_singleCameraVm.RecipeNotSelected), true, DataSourceUpdateMode.OnPropertyChanged);
            btnPause.DataBindings.Add(nameof(btnPause.Visible), _singleCameraVm, nameof(_singleCameraVm.CanPause), true, DataSourceUpdateMode.OnPropertyChanged);
            btnResume.DataBindings.Add(nameof(btnResume.Visible), _singleCameraVm, nameof(_singleCameraVm.CanResume), true, DataSourceUpdateMode.OnPropertyChanged);

            btnHotReload.Command = _singleCameraVm.HotReloadCommand;
            btnHotReload.DataBindings.Add(nameof(btnHotReload.Visible), _singleCameraVm, nameof(_singleCameraVm.CanHotReload), true, DataSourceUpdateMode.OnPropertyChanged);

        }

        public SingleCameraControl()
        {
            
            InitializeComponent();
        }
    }
}
