using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Web;

namespace atakanozbancom
{
    public class LanguageTR
    {
        public static List<Languages> AvailableLanguages = new List<Languages>
        {
            new Languages { LanguageFullName = "English", LanguageCultureName = "en-US" },
            new Languages { LanguageFullName = "Turkish", LanguageCultureName = "tr-TR" }
        };

        public static bool IsLanguageAvailable(string lang)
        {
            return AvailableLanguages.Any(a => a.LanguageCultureName.Equals(lang, StringComparison.OrdinalIgnoreCase));
        }

        public static string GetDefaultLanguage()
        {
            return AvailableLanguages[0].LanguageCultureName;
        }

        public void SetLanguage(string lang)
        {
            try
            {
                if (!IsLanguageAvailable(lang))
                    lang = GetDefaultLanguage();

                var cultureInfo = new CultureInfo(lang);
                Thread.CurrentThread.CurrentUICulture = cultureInfo;
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(cultureInfo.Name);

                HttpCookie langCookie = new HttpCookie("culture", lang)
                {
                    Expires = DateTime.Now.AddYears(1),
                    HttpOnly = true
                };
                HttpContext.Current.Response.Cookies.Add(langCookie);
            }
            catch (Exception) { }
        }
    }

    public class Languages
    {
        public string LanguageFullName { get; set; }
        public string LanguageCultureName { get; set; }
    }
}
