using System.Collections.Generic;
using System.Windows.Forms;
using Baza_Reklam.Classes.Interfaces;

namespace Baza_Reklam.Classes.Helpers
{
    public class ComboBoxHelper
    {
        public static void Bind<T>(IEnumerable<T> list, ComboBox comboBox)
        {
            comboBox.Items.Clear();
            foreach (T item in list)
            {
                comboBox.Items.Add(item);
            }
        }

        public static void Bind<T>(IEnumerable<T> list, ComboBox comboBox, T defaultItem)
        {
            Bind(list, comboBox);

            comboBox.Items.Insert(0, defaultItem);
        }

        public static int GetItemIndex(int value, ComboBox comboBox)
        {
            foreach (object item in comboBox.Items)
                if (item is IEntity && ((IEntity)item).Id == value)
                    return comboBox.Items.IndexOf(item);

            return -1;
        }
    }
}