// Copyright © Selmo Technology GmbH. All Rights Reserved

using Microsoft.AspNetCore.Components;

namespace SelmoStudio.Hmi.Server.Shared.Components.BaseComponents
{
    public partial class Rectangle<T>
    {
        [Parameter]
        public int Width { get; set; }

        [Parameter]
        public int Height { get; set; }

        [Parameter]
        public string DefaultColor { get; set; }

        [Parameter]
        public string DefaultStrokeColor { get; set; }

        [Parameter]
        public T Value { get; set; }

        [Parameter]
        public List<(Func<T, bool> callback, string[] colors)> PredicateToColors { get; set; }

        [Parameter]
        public int StrokeWidth { get; set; }

        public string GetStyle()
        {
            var style = "";
            foreach (var item in PredicateToColors)
            {
                if (item.callback.Invoke(Value))
                {
                    var colors = item.colors;
                    style = $"fill:{colors[0]};stroke:{colors[1]};stroke-width:{StrokeWidth};";
                    break;
                }
            }
            if (style == String.Empty)
                style = $"fill:{DefaultColor};stroke:{DefaultStrokeColor};stroke-width:{StrokeWidth};";
            return style;
        }
    }
}