using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows;
using InABox.Wpf;

namespace InABox.DynamicGrid
{
    /// <summary>
    ///     Interaction logic for NotesForm.xaml
    /// </summary>
    public partial class NotesForm : ThemableWindow
    {
        public NotesForm(Dictionary<Guid, string> employees = null)
        {
            InitializeComponent();

            EmployeeID = Guid.Empty;
            if (employees != null)
            {
                Task.Visibility = Visibility.Visible;
                TaskEmployee.Visibility = Visibility.Visible;
                TaskEmployee.ItemsSource = employees;
            }
        }

        public string Caption
        {
            get => (string)Heading.Content;
            set => Heading.Content = value;
        }

        public string Text
        {
            get => Editor.Text;
            set => Editor.Text = value;
        }

        public bool OKEnabled
        {
            get => OK.IsEnabled;
            set => OK.IsEnabled = value;
        }

        public bool CancelEnabled
        {
            get => Cancel.IsEnabled;
            set => Cancel.IsEnabled = value;
        }

        public Guid EmployeeID { get; private set; }

        private void OK_Click(object sender, RoutedEventArgs e)
        {
            if (Task.Visibility == Visibility.Visible && TaskEmployee.SelectedItem != null)
            {
                var emp = (KeyValuePair<Guid, string>)TaskEmployee.SelectedItem;
                EmployeeID = emp.Key;
            }

            DialogResult = true;
            Close();
        }

        private void Cancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }

        private void Window_Closing(object sender, CancelEventArgs e)
        {
            if (CancelEnabled == false && DialogResult != true)
                e.Cancel = true;
        }
    }
}