// <copyright file="EditorsLocalizationResourceAccessor.cs" company="Syncfusion">
// Copyright (c) Syncfusion. All rights reserved.
// </copyright>

namespace CustomControl
{
    using Windows.ApplicationModel.Resources.Core;

    /// <summary>
    /// Represents the class that manages the localization of editors controls based on <see cref="System.Globalization.CultureInfo.CurrentUICulture"/>.
    /// </summary>
    public sealed class EditorsLocalizationResourceAccessor : LocalizationResourceAccessor
    {
        /// <summary>
        /// Gets the instance of <see cref="EditorsLocalizationResourceAccessor"/> which manages the localization of editos controls.
        /// </summary>
        public static readonly EditorsLocalizationResourceAccessor Instance = new EditorsLocalizationResourceAccessor();

        /// <summary>
        /// Key to access localization text for "Solid".
        /// </summary>
        internal const string Solid = "Solid";

        /// <summary>
        /// Key to access localization text for "Linear".
        /// </summary>
        internal const string Linear = "Linear";

        /// <summary>
        /// Key to access localization text for "Radial".
        /// </summary>
        internal const string Radial = "Radial";

        /// <summary>
        /// Key to access localization text for "RGB".
        /// </summary>
        internal const string RGB = "RGB";

        /// <summary>
        /// Key to access localization text for "HSL".
        /// </summary>
        internal const string HSL = "HSL";

        /// <summary>
        /// Key to access localization text for "HSV".
        /// </summary>
        internal const string HSV = "HSV";

        /// <summary>
        /// Key to access localization text for "CMYK".
        /// </summary>
        internal const string CMYK = "CMYK";

        /// <summary>
        /// Initializes a new instance of the <see cref="EditorsLocalizationResourceAccessor"/> class.
        /// </summary>
        private EditorsLocalizationResourceAccessor()
        {
            this.DefaultResourceMap = Windows.ApplicationModel.Resources.Core.ResourceManager.Current.MainResourceMap.GetSubtree("CustomControl/CustomControl");
            this.CustomResourceMap = Windows.ApplicationModel.Resources.Core.ResourceManager.Current.MainResourceMap.GetSubtree("CustomControl");
        }
    }

    /// <summary>
    /// Represents the class that manages the localization for syncfusion controls.
    /// </summary>
    public abstract class LocalizationResourceAccessor
    {
        /// <summary>
        /// Initializes new instance of <see cref="LocalizationResourceAccessor"/>.
        /// </summary>
        public LocalizationResourceAccessor()
        {

        }

        /// <summary>
        /// Gets or sets the custom resource map. 
        /// </summary>
        public ResourceMap CustomResourceMap { get; set; }

        /// <summary>
        /// Gets the default resource map of the controls in the assembly.
        /// </summary>
        protected ResourceMap DefaultResourceMap { get; set; }

        /// <summary>
        /// Returns to localized string based on <see cref="System.Globalization.CultureInfo.CurrentUICulture"/>.
        /// </summary>
        /// <param name="resourcename">Resource name to get localized string.</param>
        /// <returns>Localized string resource.</returns>
        public virtual string GetLocalizedStringResource(string resourcename)
        {
            if (this.CustomResourceMap != null)
            {
                var resourcecandidate = this.CustomResourceMap.GetValue(resourcename);
                if (resourcecandidate != null)
                {
                    return resourcecandidate.ValueAsString;
                }
            }
            return this.DefaultResourceMap.GetValue(resourcename).ValueAsString;
        }
    }
}
