using Microsoft.AspNetCore.Mvc.Rendering;
using System.Collections.Generic;
using System.Linq;

namespace Kit.Helpers.Extension.Entities
{
    public static class IdTitleExtensions
    {
        public static IEnumerable<SelectListItem> AddSelectListItem(this IEnumerable<SelectListItem> selectListItems, string title, string value, bool selected = false, bool insertFirst = true)
        {
            var selectListItem = new SelectListItem { Text = title, Value = value, Selected = selected };

            var list = selectListItems as IList<SelectListItem>
                       ?? selectListItems.ToList();

            if (insertFirst)
            {
                list.Insert(0, selectListItem);
            }
            else
            {
                list.Add(selectListItem);
            }

            return list;
        }

        public static IEnumerable<SelectListItem> AddSelectListItem(this IEnumerable<SelectListItem> selectListItems, string title, object value, bool selected = false, bool insertFirst = true)
        {
            return selectListItems.AddSelectListItem(title, value.ToString(), selected, insertFirst);
        }
    }
}
