#pragma once
#include "imgui.h"
#include "imgui.h"
#include <cmath>
bool IOS_ToggleButton(const char* str_id, bool* v, float width = 51.0f, float height = 31.0f)
{
    ImVec2 p = ImGui::GetCursorScreenPos();
    ImDrawList* draw_list = ImGui::GetWindowDrawList();
    float radius = height * 0.5f;
    
    // Exact iOS dimensions and colors
    const float knob_padding = 1.5f; // iOS's subtle inset
    const ImColor offBg(200, 200, 200, 255); // iOS light gray
    const ImColor onBg(76, 217, 100, 255); // iOS green
    const ImColor knobColor(255, 255, 255, 255); // Pure white
    const ImColor shadowColor(0, 0, 0, 30); // Subtle iOS shadow
    
    // Handle interaction
    ImGui::InvisibleButton(str_id, ImVec2(width, height));
    if (ImGui::IsItemClicked()) *v = !*v;
    
    // Smooth animation (iOS uses ~0.3s duration)
    static std::map<ImGuiID, float> anim_states;
    float& t = anim_states[ImGui::GetID(str_id)];
    t = ImClamp(t + ImGui::GetIO().DeltaTime * (*v ? 4.0f : -4.0f), 0.0f, 1.0f);
    
    // Background (with exact iOS rounded corners)
    draw_list->AddRectFilled(
        p, 
        ImVec2(p.x + width, p.y + height), 
        ImColor(
            ImLerp(offBg.Value.x, onBg.Value.x, t),
            ImLerp(offBg.Value.y, onBg.Value.y, t),
            ImLerp(offBg.Value.z, onBg.Value.z, t),
            1.0f
        ), 
        height * 0.5f
    );
    
    // Knob position calculation (exact iOS spacing)
    float knob_x = ImLerp(
        p.x + radius - knob_padding, 
        p.x + width - radius + knob_padding, 
        t
    );
    
    // Knob shadow (iOS-style subtle drop shadow)
    draw_list->AddCircleFilled(
        ImVec2(knob_x, p.y + radius), 
        radius - knob_padding, 
        shadowColor, 
        32
    );
    
    // Knob itself (pure white with exact size)
    draw_list->AddCircleFilled(
        ImVec2(knob_x, p.y + radius), 
        radius - knob_padding * 1.5f, 
        knobColor, 
        32
    );
    
    // Inner glow when on (iOS subtle effect)
    if (*v) {
        draw_list->AddCircle(
            ImVec2(knob_x, p.y + radius), 
            radius - knob_padding * 0.8f, 
            ImColor(255, 255, 255, 30), 
            32, 
            1.5f
        );
    }
    
    return *v;
}
