using ImGuiNET;
using System.Numerics;
using Titled_Gui;
using Titled_Gui.Classes;
using Titled_Gui.Data.Entity;
using Titled_Gui.Data.Menu.Types;
using Titled_Gui.ImGUI.Widgets;
using Titled_Gui.Modules.Combat;
using Titled_Gui.Modules.Legit;
using Titled_Gui.Modules.Visual;
using static Titled_Gui.ImGUI.Widgets.ColorPickers;
using static Titled_Gui.ImGUI.Widgets.Combos;
using static Titled_Gui.ImGUI.Widgets.Sliders;
using static Titled_Gui.ImGUI.Widgets.Toggles;

internal class Sections
{
    public static float ChildRounding = 6f;
    public class SectionT(string label, int tab, Action content)
    {
        public string label = label;
        public Action content = content;
        public int tab = tab;
    }
    public static List<SectionT> sections = InitializeSections();

    public static List<SectionT> InitializeSections()
    {
        List<SectionT> sections = new()
        {
            new("杂项", 0, () =>
            {
                RenderBoolSettingWithWarning("自动连跳", "Bhop.Enabled", () => Bhop.BhopEnable, v => Bhop.BhopEnable = v);
                RenderBoolSetting("命中音效", "HitStuff.Enabled", () => HitStuff.EnableHitSounds, v => HitStuff.EnableHitSounds = v);
                RenderFloatSlider("命中音效音量", "HitStuff.Volume", ref HitStuff.Volume, 0, 1);
                RenderIntCombo("当前命中音效", "HitStuff.CurrentHitSound", ref HitStuff.CurrentHitSound, HitStuff.HitSoundDisplays, HitStuff.HitSounds.Count, true);
                RenderBoolSettingWith1ColorPicker("爆头文字", "HitStuff.HeadshotText", () => HitStuff.EnableHeadshotText, v => HitStuff.EnableHeadshotText = v, ref HitStuff.TextColor);
            }),
            new("投掷物辅助", 0, () =>
            {
                RenderBoolSetting("启用投掷物辅助", "GernadeLineup.Enabled", () => GernadeLineup.Enabled, v => GernadeLineup.Enabled = v);
                RenderBoolSetting("始终显示", "GernadeLineup.AlwaysShow", () => GernadeLineup.AlwaysShow, v => GernadeLineup.AlwaysShow = v);
                //Render2ColorPickers("Position Circle Color", ref GernadeLineup.PositionColorInside, ref GernadeLineup.PositionColorOutside);
                ImGui.InputText("点位名称", ref GernadeLineup.LineupName, 128);
                RenderIntCombo("投掷类型", "GernadeLineup.Type", ref GernadeLineup.SelectedType, GernadeLineup.TypesList, GernadeLineup.TypesList.Count, false);
                Titled_Gui.ImGUI.Widgets.Button.RenderButton("保存点位", "GernadeLineup.Save", () => {
                    GernadeLineup.SaveLineup(GernadeLineup.LineupName, (GrenadeLaunchType)GernadeLineup.SelectedType);
                });
            }),

            new("自瞄", 1, () =>
            {
                RenderBoolSetting("启用", "Aimbot.Enabled", () => Aimbot.AimbotEnable, v => Aimbot.AimbotEnable = v);
                RenderIntCombo("瞄准骨骼", "Aimbot.AimBone", ref Aimbot.CurrentBone, Aimbot.Bones.ToList(), Aimbot.Bones.Length);
                Keybind.RenderKeybindChooser("自瞄按键", "Aimbot.Keybind", ref Aimbot.AimbotKey, () => Aimbot.AimbotEnable);
                RenderBoolSetting("瞄准队友", "Aimbot.AimOnTeam", () => Aimbot.Team, v => Aimbot.Team = v);
                RenderFloatSlider("平滑 X", "Aimbot.SmoothingX", ref Aimbot.SmoothingX, 0, 20, "%.2f");
                RenderFloatSlider("平滑 Y", "Aimbot.SmoothingY", ref Aimbot.SmoothingY, 0, 20, "%.2f");
                RenderBoolSetting("绘制 FOV", "Aimbot.DrawFOV", () => Aimbot.DrawFov, v => Aimbot.DrawFov = v);
                RenderBoolSetting("使用 FOV", "Aimbot.UseFOV", () => Aimbot.UseFOV, v => Aimbot.UseFOV = v);
                RenderBoolSetting("开镜检测", "Aimbot.ScopedOnly", () => Aimbot.ScopedOnly, v => Aimbot.ScopedOnly = v);
                RenderIntSlider("FOV 大小", "Aimbot.FOVSize", ref Aimbot.FovSize, 10, 1000, "%d");
                RenderColorPicker("FOV 颜色", "Aimbot.FOVColor", ref Aimbot.FovColor, ref Aimbot.RGB);
                RenderBoolSetting("可见性检测", "Aimbot.VisibilityCheck", () => Aimbot.VisibilityCheck, v => Aimbot.VisibilityCheck = v);
                RenderBoolSetting("目标连线", "Aimbot.TargetLine", () => Aimbot.TargetLine, v => Aimbot.TargetLine = v);
            }),
            new("压枪", 1, () =>
            {
                RenderBoolSetting("压枪", "RCS.Enabled", () => RCS.Enabled, v => RCS.Enabled = v);
                RenderFloatSlider("强度", "RCS.Strength", ref RCS.Strength, 0f, 1f, "%.2f");
            }),
            new("扳机", 1, () =>
            {
                RenderBoolSetting("扳机", "TriggerBot.Enabled", () => TriggerBot.Enabled, v => TriggerBot.Enabled = v);
                RenderBoolSetting("队友检测", "TriggerBot.TeamCheck", () => TriggerBot.TeamCheck, v => TriggerBot.TeamCheck = v);
                Keybind.RenderKeybindChooser("扳机按键", "TriggerBot.Keybind", ref TriggerBot.TriggerKey, () => TriggerBot.Enabled);
                RenderIntSlider("最大延迟", "TriggerBot.MaxDelay", ref TriggerBot.MaxDelay, 0, 1000, "%d");
                RenderIntSlider("最小延迟", "TriggerBot.MinDelay", ref TriggerBot.MinDelay, 0, 1000, "%d");
            }),

            new("方框 ESP", 2, () =>
            {
                RenderBoolSetting("启用", "BoxESP.Enabled", () => BoxESP.EnableESP, v => BoxESP.EnableESP = v);
                RenderIntCombo("ESP 形状", "BoxESP.Shape", ref BoxESP.CurrentShape, BoxESP.Shapes.ToList(), BoxESP.Shapes.Length, false);
                RenderBoolSetting("队友检测", "BoxESP.TeamCheck", () => BoxESP.TeamCheck, v => BoxESP.TeamCheck = v);
                RenderBoolSettingWith2ColorPickers("方框填充渐变", "BoxESP.BoxFillGradient", () => BoxESP.BoxFillGradient, v => BoxESP.BoxFillGradient = v, ref BoxESP.GradientColors.TeamRGB, ref BoxESP.GradientColors.EnemyRGB, ref BoxESP.GradientColors.TeamColor, ref BoxESP.GradientColors.EnemyColor); // TODO impl rgb
                RenderBoolSettingWith2ColorPickers("填充方框", "BoxESP.FillBox", () => BoxESP.FillBox, v => BoxESP.FillBox = v, ref BoxESP.FillColors.TeamRGB, ref BoxESP.FillColors.EnemyRGB, ref BoxESP.FillColors.TeamColor, ref BoxESP.FillColors.EnemyColor);
                RenderBoolSettingWith1ColorPicker("内描边", "BoxESP.InnerOutline", () => BoxESP.InnerOutline, v => BoxESP.InnerOutline = v, ref BoxESP.InnerOutlineColors.TeamRGB, ref BoxESP.InnerOutlineColors.TeamColor);
                RenderFloatSlider("ESP 圆角", "BoxESP.Rounding", ref BoxESP.Rounding, 0, 5f);
                RenderFloatSlider("ESP 发光", "BoxESP.Glow", ref BoxESP.GlowAmount, 0f, 5f);
                RenderBoolSettingWith2ColorPickers("外描边", "BoxESP.OuterOutline", () => BoxESP.OuterOutline, v => BoxESP.OuterOutline = v, ref BoxESP.OutlineColors.TeamRGB, ref BoxESP.OutlineColors.EnemyRGB, ref BoxESP.OutlineColors.TeamColor, ref BoxESP.OutlineColors.EnemyColor);
                RenderBoolSettingWith2ColorPickers("可见性检测", "BoxESP.VisibilityCheck", () => BoxESP.VisibilityCheck, v => BoxESP.VisibilityCheck = v, ref BoxESP.OccludedColors.TeamRGB, ref BoxESP.OccludedColors.EnemyRGB, ref BoxESP.OccludedColors.TeamColor, ref BoxESP.OccludedColors.EnemyColor);
                RenderBoolSetting("闪光检测", "BoxESP.FlashCheck", () => BoxESP.FlashCheck, v => BoxESP.FlashCheck = v);
            }),
            new("玩家 ESP", 2, () =>
            {
                RenderBoolSetting("启用血条", "HealthBar.Enabled", () => HealthBar.EnableHealthBar, v => HealthBar.EnableHealthBar = v);
                RenderBoolSettingWith2ColorPickers("启用护甲条", "ArmorBar.Enabled", () => ArmorBar.EnableArmorBar, v => ArmorBar.EnableArmorBar = v, ref ArmorBar.ArmorColor.TeamRGB, ref ArmorBar.ArmorColor.EnemyRGB, ref ArmorBar.ArmorColor.TeamColor, ref ArmorBar.ArmorColor.EnemyColor);
                RenderBoolSetting("视线射线", "EyeRay.Enabled", () => EyeRay.Enabled, v => EyeRay.Enabled = v);
            }),
            new("标记", 2, () =>
            {
                Render2ColorPickers("文字颜色", "Flags.TextColor", ref Flags.TextColors.TeamRGB, ref Flags.TextColors.EnemyRGB, ref Flags.TextColors.TeamColor, ref Flags.TextColors.EnemyColor);
                RenderBoolSetting("开镜", "Flags.Scoped", () => Flags.ScopedEnabled, v => Flags.ScopedEnabled = v);
                RenderBoolSetting("被闪", "Flags.Flashed", () => Flags.FlashEnabled, v => Flags.FlashEnabled = v);
                RenderBoolSetting("显示距离文字", "DistanceText.Enabled", () => DistanceText.Enabled, v => DistanceText.Enabled = v);
                RenderBoolSetting("显示名字", "NameDisplay.Enabled", () => NameDisplay.Enabled, v => NameDisplay.Enabled = v);
                RenderBoolSetting("枪械图标", "Flags.GunIcon", () => Flags.GunEnabled, v => Flags.GunEnabled = v);
                RenderBoolSettingWith1ColorPicker("延迟显示", "PingDisplay.Enabled", () => PingDisplay.Enabled, v => PingDisplay.Enabled = v, ref PingDisplay.PingTextColor);
            }),
            new("骨骼 ESP", 2, () =>
            {
                RenderBoolSettingWith2ColorPickers("启用骨骼 ESP", "BoneESP.Enabled", () => BoneESP.EnableBoneESP, v => BoneESP.EnableBoneESP = v, ref BoneESP.VisibleColors.TeamRGB, ref BoneESP.VisibleColors.EnemyRGB, ref BoneESP.VisibleColors.TeamColor, ref BoneESP.VisibleColors.EnemyColor);
                RenderBoolSettingWith2ColorPickers("可见性检测", "BoneESP.VisibilityCheck", () => BoneESP.visibilityCheck, v => BoneESP.visibilityCheck = v, ref BoneESP.OccludedColors.TeamRGB, ref BoneESP.OccludedColors.EnemyRGB, ref BoneESP.OccludedColors.TeamColor, ref BoneESP.OccludedColors.EnemyColor);
                RenderIntCombo("骨骼 ESP 类型", "BoneESP.Type", ref BoneESP.CurrentType, BoneESP.Types.ToList(), BoneESP.Types.Length);
                RenderBoolSetting("队友检测", "BoneESP.TeamCheck", () => BoneESP.TeamCheck, v => BoneESP.TeamCheck = v);
                RenderFloatSlider("骨骼发光", "BoneESP.Glow", ref BoneESP.GlowAmount, 0, 1f);
            }),
            new("射线", 2, () =>
            {
                RenderBoolSettingWith2ColorPickers("启用", "Tracers.Enabled", () => Tracers.EnableTracers, v => Tracers.EnableTracers = v, ref Tracers.TracerColors.TeamRGB, ref Tracers.TracerColors.EnemyRGB, ref Tracers.TracerColors.TeamColor, ref Tracers.TracerColors.EnemyColor);
                RenderIntCombo("射线起点", "Tracers.StartPosition", ref Tracers.CurrentStartPos, Tracers.StartPositions, Tracers.StartPositions.Count, false);
                RenderIntCombo("射线终点", "Tracers.EndPosition", ref Tracers.CurrentEndPos, Tracers.EndPositions.ToList(), Tracers.EndPositions.Length);
                RenderFloatSlider("射线粗细", "Tracers.Thickness", ref Tracers.LineThickness, 0.05f, 5f);
            }),
            new("弹道射线", 2, () =>
            {
                RenderBoolSettingWith1ColorPicker("启用", "BulletTracers.Enabled", () => BulletTracers.Enabled, v => BulletTracers.Enabled = v, ref BulletTracers.TracerColors.PrimaryRGB, ref Tracers.TracerColors.PrimaryColor);
                RenderFloatSlider("射线半径", "BulletTracers.Radius", ref BulletTracers.Radius, 0.5f, 5f);
                RenderFloatSlider("射线粗细", "BulletTracers.Thickness", ref BulletTracers.Thickness, 0.5f, 10f);
                RenderFloatSlider("射线持续时间", "BulletTracers.Duration", ref BulletTracers.Duration, 0.5f, 15f);
            }),
            
            new("其他视觉", 2, () =>
            {
                RenderBoolSetting("炸弹计时", "BombTimerOverlay.Enabled", () => BombTimerOverlay.EnableTimeOverlay, v => BombTimerOverlay.EnableTimeOverlay = v);
                RenderBoolSetting("观战列表", "SpectatorList.Enabled", () => SpectatorList.Enabled, v => SpectatorList.Enabled = v);
                RenderBoolSettingWithWarning("防闪光", "NoFlash.Enabled", () => NoFlash.NoFlashEnable, v => NoFlash.NoFlashEnable = v);
                RenderBoolSettingWithWarning("FOV 修改", "FovChanger.Enabled", () => FovChanger.Enabled, v => FovChanger.Enabled = v);
                RenderBoolSettingWithWarning("第三人称", "ThirdPerson.Enabled", () => ThirdPerson.Enabled, v => ThirdPerson.Enabled = v);
                RenderIntSlider("目标 FOV", "FovChanger.FOV", ref FovChanger.FOV, 60, 160);
                RenderBoolSettingWith2ColorPickers("雷达", "Radar.Enabled", () => Radar.IsEnabled, v => Radar.IsEnabled = v, ref Radar.PointColors.TeamRGB, ref Radar.PointColors.EnemyRGB, ref  Radar.PointColors.TeamColor, ref Radar.PointColors.EnemyColor);
                RenderBoolSetting("绘制队友", "Radar.DrawTeam", () => Radar.DrawOnTeam, v => Radar.DrawOnTeam = v);
                RenderBoolSetting("绘制十字", "Radar.DrawCross", () => Radar.DrawCrossb, v => Radar.DrawCrossb = v);
                        RenderBoolSettingWith2ColorPickers("声音 ESP", "SoundESP.Enabled", () => SoundESP.Enabled, v => SoundESP.Enabled = v, ref SoundESP.VisibleColors.TeamRGB, ref SoundESP.VisibleColors.EnemyRGB, ref SoundESP.VisibleColors.TeamColor, ref SoundESP.VisibleColors.EnemyColor);
            }),
            new("世界 ESP", 2, () =>
            {
                RenderBoolSettingWith2ColorPickers("C4 ESP", "C4ESP.Enabled", () => C4ESP.Enabled, v => C4ESP.Enabled = v, ref C4ESP.Colors.PrimaryRGB, ref C4ESP.Colors.SecondaryRGB, ref C4ESP.Colors.PrimaryColor, ref C4ESP.Colors.SecondaryColor);
                RenderBoolSettingWith1ColorPicker("掉落武器 ESP", "WorldESP.DroppedWeapon", () => WorldESP.DroppedWeaponESP, v => WorldESP.DroppedWeaponESP = v, ref WorldESP.WeaponTextColor);
                RenderBoolSettingWith1ColorPicker("人质 ESP", "WorldESP.Hostage", () => WorldESP.HostageESP, v => WorldESP.HostageESP = v, ref WorldESP.HostageTextColor);
                RenderBoolSettingWith1ColorPicker("小鸡 ESP", "WorldESP.Chicken", () => WorldESP.ChickenESP, v => WorldESP.ChickenESP = v, ref WorldESP.ChickenTextColor);
                RenderBoolSettingWith1ColorPicker("投掷物 ESP", "WorldESP.Projectile", () => WorldESP.ProjectileESP, v => WorldESP.ProjectileESP = v, ref WorldESP.ProjectileTextColor);
                RenderBoolSettingWith1ColorPicker("世界 ESP 方框", "WorldESP.Boxes", () => WorldESP.DrawBoxes, v => WorldESP.DrawBoxes = v, ref WorldESP.BoxColor);
                RenderBoolSettingWith2ColorPickers("燃烧瓶范围", "WorldESP.MolotovBounds", () => WorldESP.MolotovBoundsESP, v => WorldESP.MolotovBoundsESP = v, ref WorldESP.MolotovColors.PrimaryRGB, ref WorldESP.MolotovColors.SecondaryRGB, ref WorldESP.MolotovColors.PrimaryColor, ref WorldESP.MolotovColors.SecondaryColor);
                RenderBoolSetting("世界 ESP 文字", "WorldESP.Text", () => WorldESP.DrawText, v => WorldESP.DrawText = v);
                RenderBoolSetting("世界 Chams", "WorldESP.Chams", () => WorldESP.DrawChams, v => WorldESP.DrawChams = v);
            }),

            new("界面", 4, () =>
            {
                RenderFloatSlider("窗口透明度", "Renderer.WindowAlpha", ref Renderer.WindowAlpha, 0.1f, 1.0f, "%.2f");
                Render2ColorPickers("菜单颜色", "Renderer.MenuColors", ref Renderer.MenuColors.PrimaryRGB, ref Renderer.MenuColors.SecondaryRGB, ref Renderer.MenuColors.PrimaryColor, ref Renderer.MenuColors.SecondaryColor, () =>{Renderer.ApplyColors(); });
                RenderFloatSlider("动画速度", "Renderer.AnimationSpeed", ref Renderer.AnimationSpeed, 0.01f, 1.0f, "%.2f");
                RenderFloatSlider("粒子速度", "Renderer.ParticleSpeed", ref Renderer.ParticleSpeed, 0, 10);
                RenderColorPicker("粒子颜色", "Renderer.ParticleColor", ref Renderer.BackgroundEffectColors.PrimaryColor, ref Renderer.BackgroundEffectColors.PrimaryRGB, () =>{Renderer.ApplyColors(); });
                RenderColorPicker("线条颜色", "Renderer.LineColor", ref Renderer.BackgroundEffectColors.SecondaryColor, ref Renderer.BackgroundEffectColors.SecondaryRGB, () =>{Renderer.ApplyColors(); });
                Keybind.RenderKeybindChooser("打开菜单按键", "Renderer.OpenKeybind", ref Renderer.OpenKeyInt, () => Renderer.DrawWindow);
                RenderBoolSetting("菜单音效", "Renderer.MenuSounds", () => Renderer.MenuSounds, v => Renderer.MenuSounds = v);
                RenderFloatSlider("菜单音效音量", "Renderer.MenuSoundsVolume", ref Renderer.MenuSoundsVolume, 0, 1);
                RenderBoolSetting("水印", "Renderer.Watermark", () => Renderer.EnableWatermark, v => Renderer.EnableWatermark = v);
            }),
            new("性能", 4, () =>
            {
                RenderBoolSetting("使用旧版可见性检测", "EntityManager.UseOldVisibilityCheck", () => EntityManager.UseOldVisibilityCheck, v => EntityManager.UseOldVisibilityCheck = v);
                RenderBoolSetting("垂直同步", "Renderer.VSync", () => Renderer.EnableVsync, v => Renderer.EnableVsync = v);
            }),
            new("关于", 4, () =>
            {
                ImGui.Text($"Titled GUI V{Configs.Version}");
                ImGui.Text("12游戏吧永久地址发布页：www.12gameb.co");
                ImGui.Text("更多信息: " + Configs.Link);
                ImGui.TextWrapped("如果你为此付费，那你被骗了。\n这个项目从未收费，也永远不会收费。\n12游戏吧永远免费发布。");
            }),
        };

        return sections;
    }

    public static void BeginSection(string label, Action content, Vector2 size)
    {
        ImGui.PushStyleVar(ImGuiStyleVar.ChildRounding, ChildRounding);
        ImGui.PushStyleColor(ImGuiCol.ChildBg, Renderer.MenuColors.SecondaryRGB ? Colors.Rgb(Renderer.WindowAlpha) : Renderer.MenuColors.SecondaryColor);
        ImGui.BeginChild(label, size, ImGuiChildFlags.Border | ImGuiChildFlags.AutoResizeY);
        ImGui.Text(label);
        ImGui.Separator();
        content();
        ImGui.EndChild();
        ImGui.PopStyleColor();
        ImGui.PopStyleVar();
    }
}
