using Microsoft.AspNet.Http;
using System.Collections.Generic;

namespace MvcExplorer.Models
{
    public class Theme
    {
        public const string Default = "Default";

        public string Name { get; set; }

        public string Path { get; set; }

        public static List<Theme> GetThemes() 
        {
            var names = new[] { "Default", "Cerulean", "Cocoa", "Coral", "Cyborg", "Dark", "Darkly", "Flatly", "Grayscale", "Highcontrast", "Light", "Material", "Midnight", "Minimal", "Modern", "Organic", "Simplex", "Slate", "Superhero", "Zen" };
            var themes = new List<Theme>();
            foreach (var name in names)
            {
                themes.Add(new Theme { Name = name });
            }
            return themes;
        }

        public static int GetIndexByName(IEnumerable<Theme> themes, string name) 
        {
            int currentIndex = 0, i = 0;

            foreach (var theme in themes)
            {
                if (theme.Name == name) 
                {
                    return i;
                }
                i++;
            }

            return currentIndex;
        }

        public static string GetCurrentTheme(HttpContext context)
        {
            var theme = context.Session.GetString("C1MvcTheme");
            return theme != null ? theme : Default;
        }

        public static void SetCurrentTheme(HttpContext context, string value)
        {
            if (!string.IsNullOrEmpty(value))
            {
                context.Session.SetString("C1MvcTheme", value);
            }
        }
    }
}