using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using WpfPath = System.Windows.Shapes.Path;

namespace Noctalk.UI.Components.Buttons_left_area;

internal static class Noctalk_left_area_button_icon_factory
{
    public static FrameworkElement Create(Noctalk_left_area_button_icon The_icon, Brush The_brush)
    {
        Canvas canvas = new()
        {
            Width = 32,
            Height = 32
        };

        switch (The_icon)
        {
            case Noctalk_left_area_button_icon.Log:
                Icon__log(canvas, The_brush);
                break;
            case Noctalk_left_area_button_icon.Admin:
                Icon__admin(canvas, The_brush);
                break;
            case Noctalk_left_area_button_icon.Sound_on:
                Icon__sound(canvas, The_brush, false);
                break;
            case Noctalk_left_area_button_icon.Sound_off:
                Icon__sound(canvas, The_brush, true);
                break;
        }

        return new Viewbox
        {
            Width = 25,
            Height = 25,
            Child = canvas,
            Stretch = Stretch.Uniform
        };
    }

    private static void Icon__log(Canvas The_canvas, Brush The_brush)
    {
        WpfPath page = Icon__path("M 7 4 L 22 4 L 27 9 L 27 28 L 7 28 Z M 22 4 L 22 10 L 27 10", The_brush, 2.4);
        The_canvas.Children.Add(page);
        The_canvas.Children.Add(Icon__line(11, 14, 21, 14, The_brush));
        The_canvas.Children.Add(Icon__line(11, 19, 23, 19, The_brush));
        The_canvas.Children.Add(Icon__line(11, 24, 20, 24, The_brush));
    }

    private static void Icon__admin(Canvas The_canvas, Brush The_brush)
    {
        The_canvas.Children.Add(Icon__ellipse(10, 4, 12, 12, The_brush, 2.4));
        WpfPath shoulders = Icon__path("M 6 28 L 6 25 C 6 20 10 17 16 17 C 20 17 23 18.5 25 21", The_brush, 2.4);
        The_canvas.Children.Add(shoulders);
        The_canvas.Children.Add(Icon__gear(The_brush));
    }

    private static void Icon__sound(Canvas The_canvas, Brush The_brush, bool Flag__off)
    {
        The_canvas.Children.Add(Icon__path("M 5 13 L 11 13 L 20 6 L 20 26 L 11 19 L 5 19 Z", The_brush, 2.7));
        The_canvas.Children.Add(Icon__path("M 23 12 C 25 14 25 18 23 20", The_brush, 2.7));
        The_canvas.Children.Add(Icon__path("M 26 9 C 30 13 30 19 26 23", The_brush, 2.7));

        if (!Flag__off)
        {
            return;
        }

        Brush redBrush = new SolidColorBrush(Color.FromRgb(255, 138, 154));
        The_canvas.Children.Add(Icon__line(8, 8, 24, 24, redBrush, 2.8));
    }

    private static WpfPath Icon__gear(Brush The_brush)
    {
        WpfPath gear = Icon__path("M 24 18 L 26 20 L 29 19 L 30 22 L 27 23 L 27 26 L 30 27 L 29 30 L 26 29 L 24 31 L 22 29 L 19 30 L 18 27 L 21 26 L 21 23 L 18 22 L 19 19 L 22 20 Z M 24 22.5 A 2.5 2.5 0 1 0 24 27.5 A 2.5 2.5 0 1 0 24 22.5", The_brush, 2.0);
        gear.Fill = Brushes.Transparent;
        return gear;
    }

    private static WpfPath Icon__path(string The_data, Brush The_brush, double The_stroke_thickness)
    {
        return new WpfPath
        {
            Data = Geometry.Parse(The_data),
            Stroke = The_brush,
            StrokeThickness = The_stroke_thickness,
            StrokeStartLineCap = PenLineCap.Round,
            StrokeEndLineCap = PenLineCap.Round,
            StrokeLineJoin = PenLineJoin.Round,
            Fill = Brushes.Transparent
        };
    }

    private static Line Icon__line(double X1, double Y1, double X2, double Y2, Brush The_brush, double The_stroke_thickness = 2.7)
    {
        return new Line
        {
            X1 = X1,
            Y1 = Y1,
            X2 = X2,
            Y2 = Y2,
            Stroke = The_brush,
            StrokeThickness = The_stroke_thickness,
            StrokeStartLineCap = PenLineCap.Round,
            StrokeEndLineCap = PenLineCap.Round
        };
    }

    private static Ellipse Icon__ellipse(double Left, double Top, double Width, double Height, Brush The_brush, double The_stroke_thickness)
    {
        Ellipse ellipse = new()
        {
            Width = Width,
            Height = Height,
            Stroke = The_brush,
            StrokeThickness = The_stroke_thickness,
            Fill = Brushes.Transparent
        };
        Canvas.SetLeft(ellipse, Left);
        Canvas.SetTop(ellipse, Top);
        return ellipse;
    }
}
