using System;
using System.Windows.Markup;
using MarcusLaw.OutlookAddin.UI.Services;

namespace MarcusLaw.OutlookAddin.UI.Markup
{
    /// <summary>
    /// XAML markup extension that resolves a resource key against
    /// <see cref="LocalizationManager.Instance"/>. Usage:
    /// <code>&lt;TextBlock Text="{l:Loc Settings_Title}" /&gt;</code>
    ///
    /// Resolution is one-shot — culture changes require a restart, matching
    /// the design in PROJECT-BRIEFING.md ("Override via SettingsManager…
    /// requires restart").
    /// </summary>
    [MarkupExtensionReturnType(typeof(string))]
    public sealed class LocExtension : MarkupExtension
    {
        public string? Key { get; set; }

        public LocExtension() { }

        public LocExtension(string key) { Key = key; }

        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            return string.IsNullOrEmpty(Key) ? string.Empty : LocalizationManager.Instance.Get(Key!);
        }
    }
}
