use eframe::egui::{self, Color32, Rect, Stroke};
use egui::epaint::Mesh;

// ─── ComboBox Popup Renk Sabitleri ──────────────────────────
pub const WEAK_BG_INACTIVE: Color32 = Color32::from_rgb(224, 224, 224);
pub const WEAK_BG_HOVERED:  Color32 = Color32::from_rgb(200, 200, 200);
pub const WEAK_BG_ACTIVE:   Color32 = Color32::from_rgb(180, 180, 180);

// ─── Gradient Dropdown Öğesi Renkleri ───────────────────────
pub const GRADIENT_TOP: Color32 = Color32::from_rgb(249, 249, 249);
pub const GRADIENT_BOT: Color32 = Color32::from_rgb(233, 233, 233);

// ─── ComboBox Metin Renkleri ────────────────────────────────
/// Seçili metin rengi (ComboBox kapalıyken widget üzerinde görünen metin)
pub const COMBO_TEXT_COLOR: Color32 = Color32::from_rgb(50, 50, 50);
/// Açılır listedeki öğelerin metin rengi
pub const DROPDOWN_TEXT_COLOR: Color32 = Color32::from_rgb(50, 50, 50);

// ─── ComboBox Kenarlık (border) Renkleri ────────────────────
/// Üzerine gelindiğinde / tıklanınca kenarlık rengi
pub const COMBO_BORDER_ACCENT: Color32 = Color32::from_rgb(155, 155, 155);

/// Verilen `Visuals` yapısına ComboBox stillerini uygular.
pub fn apply_visuals(v: &mut egui::Visuals) {
    v.widgets.inactive.weak_bg_fill = WEAK_BG_INACTIVE;
    v.widgets.hovered.weak_bg_fill  = WEAK_BG_HOVERED;
    v.widgets.active.weak_bg_fill   = WEAK_BG_ACTIVE;

    v.widgets.inactive.fg_stroke = Stroke::new(1.0, COMBO_TEXT_COLOR);
    v.widgets.hovered.fg_stroke  = Stroke::new(1.5, Color32::WHITE);
    v.widgets.active.fg_stroke   = Stroke::new(2.0, Color32::WHITE);

    // Kenarlıklar
    v.widgets.inactive.bg_stroke = Stroke::new(1.0, COMBO_BORDER_ACCENT);
    v.widgets.hovered.bg_stroke  = Stroke::new(1.0, COMBO_BORDER_ACCENT);
    v.widgets.active.bg_stroke   = Stroke::new(1.0, COMBO_BORDER_ACCENT);
}

/// Açık gri gradyan mesh arkaplanı çizer (dropdown öğeleri için).
pub fn draw_gradient_bg(ui: &mut egui::Ui, rect: Rect) {
    let mut mesh = Mesh::default();
    let idx = mesh.vertices.len() as u32;
    mesh.vertices.push(egui::epaint::Vertex {
        pos: egui::pos2(rect.left(), rect.top()),
        uv: egui::pos2(0.0, 0.0),
        color: GRADIENT_TOP,
    });
    mesh.vertices.push(egui::epaint::Vertex {
        pos: egui::pos2(rect.right(), rect.top()),
        uv: egui::pos2(0.0, 0.0),
        color: GRADIENT_TOP,
    });
    mesh.vertices.push(egui::epaint::Vertex {
        pos: egui::pos2(rect.right(), rect.bottom()),
        uv: egui::pos2(0.0, 0.0),
        color: GRADIENT_BOT,
    });
    mesh.vertices.push(egui::epaint::Vertex {
        pos: egui::pos2(rect.left(), rect.bottom()),
        uv: egui::pos2(0.0, 0.0),
        color: GRADIENT_BOT,
    });
    mesh.indices.extend_from_slice(&[idx, idx + 1, idx + 2, idx + 2, idx + 3, idx]);
    ui.painter().add(egui::Shape::mesh(mesh));
}
