/*
COPYRIGHT (C) 2011 EPISERVER AB

THIS FILE IS PART OF NHUNSPELLCHECKER FOR EPISERVER CMS.
IT IS FREE SOFTWARE: YOU CAN REDISTRIBUTE IT AND/OR MODIFY IT UNDER THE TERMS OF THE GNU LESSER GENERAL PUBLIC LICENSE VERSION v2.1 AS PUBLISHED BY THE FREE SOFTWARE FOUNDATION.

NHUNSPELLCHECKER FOR EPISERVER CMS IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU LESSER GENERAL PUBLIC LICENSE FOR MORE DETAILS.
NOTE THAT THIS PROJECT RELIES ON OTHER OPEN SOURCE PROJECTS WITH THEIR OWN RESPECTIVE LICENSES.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EPiServer.Editor.TinyMCE;
using EPiServer.Configuration;
using EPiServer.DataAbstraction;
using System.Text;
namespace EPiServer.Research.Plugins.NHunspell
{
    [TinyMCEPluginButton(LanguagePath =
"/admin/tinymce/plugins/mce_spellchecker/mce_spellchecker",
GroupName = "misc", ButtonSortIndex = 0, ButtonName = "spellchecker"
, PlugInName = "spellchecker", IconUrl = "NHunspellChecker/SpellCheck.GIF", DynamicConfigurationOptionsHandler = typeof(SpellCheckerPlugin))] 
    public class SpellCheckerPlugin : IDynamicConfigurationOptions
    {
        public SpellCheckerPlugin()
        {
        }

        #region IDynamicConfigurationOptions Members

        public IDictionary<string, object> GetConfigurationOptions()
        {
            var rt = new Dictionary<string, object>();
            StringBuilder langString = new StringBuilder();
            
            foreach (var lang in LanguageBranch.ListEnabled())
            {
                //Check if we have translation files for language
                if (lang.LanguageID == EPiServer.Globalization.ContentLanguage.PreferredCulture.TwoLetterISOLanguageName)
                    langString.Append("+");
                langString.Append(lang.Name + "=" + lang.LanguageID + ",");
            }
            langString.Remove(langString.Length - 1, 1);
            rt.Add("spellchecker_languages", langString.ToString());
            rt.Add("spellchecker_rpc_url", UriSupport.ResolveUrlBySettings("~/modules/NHunspellchecker/rpc.ashx"));
            return rt;
        }

        #endregion
    }

}
