using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace hukpiWinApp
{
    public partial class EditListViewModalities : hukpiWinApp.BaseEditListViewForm
    {
        public EditListViewModalities(ListView parentListView) : base(parentListView)
        {
            InitializeComponent();

            fillComboBoxModalities();
        }

        private void fillComboBoxModalities()
        {
            comboBoxNewModality.DataSource = Utils.getModalitiesForCombo();
            comboBoxNewModality.DisplayMember = "Description";
            comboBoxNewModality.ValueMember = "Id";
        }

        private void clearInputsBoxes()
        {
            comboBoxNewModality.SelectedValue = 0;
        }

        private void buttonAddNewModality_Click(object sender, EventArgs e)
        {
            if (!validateForm())
            {
                MessageBox.Show(ErrorMessages.Default.invalidFormInputData);
            }
            else
            {
                ListViewItem newItem = new ListViewItem(comboBoxNewModality.Text.Split('-')[0]);
                ListViewItem.ListViewSubItem subItem = new ListViewItem.ListViewSubItem(newItem, comboBoxNewModality.Text.Split('-')[1]);
                subItem.Tag = comboBoxNewModality.SelectedValue;
                newItem.SubItems.Add(subItem);
                this.listViewData.Items.Add(newItem);

                clearInputsBoxes();
            }
        }

        private void comboBoxNewModality_Validating(object sender, CancelEventArgs e)
        {
            Utils.validateMustNonEmpty(errorProviderForEditListView, comboBoxNewModality);
        }

        private bool validateForm()
        {
            bool isValidComboNewModality = Utils.validateMustNonEmpty(errorProviderForEditListView, comboBoxNewModality);

            return isValidComboNewModality;
        }

    }
}
