using Microsoft.AspNetCore.Components;
using Portfolio.Domain.Features.TemperatureDay;
using Portfolio.Domain.Features.TemperatureRange;

namespace Portfolio.WebUI.Server.Components.Component.Crochet_Components
{
    public partial class TemperatureBlanketVisualizer : ComponentBase
    {
        [Parameter] public List<TemperatureDay> TemperatureDays { get; set; }

        public List<TemperatureRange> TemperatureRanges { get; set; } = new();

        protected override void OnInitialized()
        {
            TemperatureRanges = new()
            {
                new() { Min = 0, Max = 21, Color = "#ffffff" },
                new() { Min = 21, Max = 28, Color = "#ffc0cb" },
                new() { Min = 28, Max = 35, Color = "#dda0dd" },
                new() { Min = 35, Max = 42, Color = "#add8e6" },
                new() { Min = 42, Max = 49, Color = "#00008b" },
                new() { Min = 49, Max = 56, Color = "#006400" },
                new() { Min = 56, Max = 63, Color = "#07ed07" },
                new() { Min = 63, Max = 70, Color = "#ffff00" },
                new() { Min = 70, Max = 77, Color = "#ffa500" },
                new() { Min = 77, Max = 84, Color = "#ff0000" },
                new() { Min = 84, Max = 100, Color = "#000000" }
            };
        }

        private string GetColorForTemp(double temp)
        {
            var range = TemperatureRanges.FirstOrDefault(r => temp >= r.Min && temp < r.Max);
            return range?.Color ?? "#888888";
        }

        private void HandleRangesChanged(List<TemperatureRange> updatedRanges)
        {
            TemperatureRanges = updatedRanges;
            StateHasChanged();
        }



    }
}
