using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
using Markdig.Syntax;

namespace MarkdownEditor.Views.Renderers;

/// <summary>
/// Renders markdown thematic breaks (horizontal rules).
/// </summary>
public class ThematicBreakRenderer : IMarkdownBlockRenderer
{
    private readonly bool _isDarkMode;

    /// <summary>
    /// Initializes a new instance of the <see cref="ThematicBreakRenderer"/> class.
    /// </summary>
    /// <param name="isDarkMode">Whether the current theme is dark mode.</param>
    public ThematicBreakRenderer(bool isDarkMode = true)
    {
        _isDarkMode = isDarkMode;
    }

    /// <inheritdoc/>
    public bool CanRender(Block block) => block is ThematicBreakBlock;

    /// <inheritdoc/>
    public Control? Render(Block block)
    {
        if (block is not ThematicBreakBlock)
        {
            return null;
        }

        return new Border
        {
            BorderBrush = new SolidColorBrush(Color.Parse(_isDarkMode ? "#555555" : "#CCCCCC")),
            BorderThickness = new Thickness(0, 1, 0, 0),
            Margin = new Thickness(0, 10, 0, 10),
            Height = 1
        };
    }
}

