namespace CBT.Interface.Tabs;

using System.Collections.Generic;
using System.Linq;
using CBT.Types;
using Dalamud.Bindings.ImGui;

/// <summary>
/// CatgeoryTab configures settings for FlyTextKinds.
/// </summary>
public class KindTab : Tab
{
    private static readonly List<FlyTextKind> KindPickerValues = [.. FlyTextKindExtension.GetAll().Where(FlyTextKindExtension.UnusedKindPredicate).OrderBy(k => k.ToString())];

    private static FlyTextKind currentKind = FlyTextKindExtension.GetAll().First();

    /// <inheritdoc/>
    public override string Name => "Configuration";

    /// <inheritdoc/>
    protected override FlyTextKind Current
    {
        get => currentKind;
        set => currentKind = value;
    }

    /// <inheritdoc/>
    public override void Draw()
    {
        GuiArtist.DrawTitle("Kind Configuration Settings");

        this.DrawCurrentConfigurations(KindPickerValues);

        if (this.Current.InCategory(FlyTextCategory.AbilityDamage))
        {
            GuiArtist.DrawLabelPrefix("Configure for", sameLine: false);
            ImGui.SameLine();
            var isTaken = this.UsePlayerDamageTakenConfig;
            if (ImGui.RadioButton("Player Damage Dealt", !isTaken))
            {
                this.UsePlayerDamageTakenConfig = false;
            }

            ImGui.SameLine();
            if (ImGui.RadioButton("Player Damage Taken", isTaken))
            {
                this.UsePlayerDamageTakenConfig = true;
            }
        }

        if (this.Current.InCategory(FlyTextCategory.AutoAttack))
        {
            GuiArtist.DrawLabelPrefix("Configure for", sameLine: false);
            ImGui.SameLine();
            var isTaken = this.UsePlayerAutoAttackTakenConfig;
            if (ImGui.RadioButton("Player AutoAttack Dealt", !isTaken))
            {
                this.UsePlayerAutoAttackTakenConfig = false;
            }

            ImGui.SameLine();
            if (ImGui.RadioButton("Player AutoAttack Taken", isTaken))
            {
                this.UsePlayerAutoAttackTakenConfig = true;
            }
        }

        if (this.CurrentEnabled)
        {
            this.DrawFontConfigurations();

            if (this.Current.InCategory(FlyTextCategory.AbilityDamage))
            {
                this.DrawPositionalPickers();
            }

            this.DrawIconConfigurations();
            this.DrawAnimationConfigurations();
        }

        GuiArtist.DrawSeperator();
    }

    /// <inheritdoc/>
    public override void OnClose()
    {
        currentKind = FlyTextKindExtension.GetAll().First();
    }
}