using Connected.Extensions;
using Connected.Utilities;

namespace Connected.Components;

internal static class InputCssHelper
{
   public static string GetClassname<T>(InputBase<T> baseInput, Func<bool> shrinkWhen) =>
      new CssBuilder("input")
         .AddClass($"input-{baseInput.Variant.ToDescription()}")
         .AddClass($"input-adorned-{baseInput.Adornment.ToDescription()}", baseInput.Adornment != Adornment.None)
         .AddClass($"input-margin-{baseInput.Margin.ToDescription()}", when: () => baseInput.Margin != Margin.None)
         .AddClass("input-underline", when: () => baseInput.DisableUnderLine == false && baseInput.Variant != Variant.Outlined)
         .AddClass("shrink", when: shrinkWhen)
         .AddClass("disabled", baseInput.Disabled)
         .AddClass("input-error", baseInput.HasErrors)
         .AddClass("ltr", baseInput.GetInputType() == InputType.Email || baseInput.GetInputType() == InputType.Telephone)
         .AddClass(baseInput.AdditionalClassList)
         .Build();

   public static string GetInputClassname<T>(InputBase<T> baseInput) =>
      new CssBuilder("input-slot")
         .AddClass("input-root")
         .AddClass($"input-root-{baseInput.Variant.ToDescription()}")
         .AddClass($"input-root-adorned-{baseInput.Adornment.ToDescription()}", baseInput.Adornment != Adornment.None)
         .AddClass($"input-root-margin-{baseInput.Margin.ToDescription()}", when: () => baseInput.Margin != Margin.None)
         .AddClass(baseInput.AdditionalClassList)
         .Build();

   public static string GetAdornmentClassname<T>(InputBase<T> baseInput) =>
      new CssBuilder("input-adornment")
         .AddClass($"input-adornment-{baseInput.Adornment.ToDescription()}", baseInput.Adornment != Adornment.None)
         .AddClass($"text", !string.IsNullOrEmpty(baseInput.AdornmentText))
         .AddClass($"input-root-filled-shrink", baseInput.Variant == Variant.Filled)
         .AddClass(baseInput.AdditionalClassList)
         .Build();
}
