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

namespace Qusion.WebApp.Areas.Qusion.Helpers
{
    public delegate void CultureChanged(object Sender, string CurrentCulture);
    public class HelpersCulture : System.Web.UI.Page
    {
        public HelpersCulture()
        {
        
        }
        private HttpRequest _request;


        public HelpersCulture(HttpRequest request)
        {
           this._request = request;
        }

        public event CultureChanged OnCultureChanged;
    
       public void InitializeCulture()
        {
            if (!String.IsNullOrEmpty(TrenutnaKultura))
            {
                try
                {
                    Thread.CurrentThread.CurrentCulture = new CultureInfo(TrenutnaKultura);
                    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
                }
                catch { throw; }
            }
            else
            {
                HttpContext.Current.Session["PreferedCulture"] = "sr";
                Thread.CurrentThread.CurrentCulture = new CultureInfo(TrenutnaKultura);
                Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
            }

        }

         public string TrenutnaKultura
        {
           
            get
            {
                if (null != HttpContext.Current.Session["PreferedCulture"])
                {
                    return HttpContext.Current.Session["PreferedCulture"].ToString();
                }
                return String.Empty;
            }
            set 
            {
                HttpContext.Current.Session["PreferedCulture"] = value;
            }
        }
    }
}