using ZelWiki.Engine.Library;
using ZelWiki.Engine.Library.Interfaces;

namespace ZelWiki.Engine.Implementation
{
    /// <summary>
    /// 处理链接
    /// </summary>
    public class ExternalLinkHandler : IExternalLinkHandler
    {
        /// <summary>
        /// 处理内链
        /// </summary>
        /// <param name="state"></param>
        /// <param name="link"></param>
        /// <param name="text"></param>
        /// <param name="image"></param>
        /// <returns></returns>
        public HandlerResult Handle(IZelEngineState state, string link, string? text, string? image)
        {
            if (string.IsNullOrEmpty(image))
            {
                return new HandlerResult($"<a href=\"{link}\">{text}</a>")
                {
                    Instructions = [Constants.HandlerResultInstruction.DisallowNestedProcessing]
                };
            }

            return new HandlerResult($"<a href=\"{link}\"><img src=\"{image}\" border =\"0\"></a>")
            {
                Instructions = [Constants.HandlerResultInstruction.DisallowNestedProcessing]
            };
        }
    }
}