use cvkg_core::{View, Never};

/// Linear or circular progress indicator
#[allow(dead_code)]
pub struct ProgressView {
    pub(crate) value: f32,
    pub(crate) total: f32,
}

impl ProgressView {
    /// Create a new ProgressView.
    ///
    /// # Examples
    /// ```
    /// use cvkg_components::ProgressView;
    /// let progress = ProgressView::new(0.5, 1.0);
    /// ```
    pub fn new(value: f32, total: f32) -> Self {
        Self { value, total }
    }
}

impl View for ProgressView {
    type Body = Never;
    fn body(self) -> Self::Body { unreachable!() }
}

/// Radial or linear gauge display
#[allow(dead_code)]
pub struct Gauge {
    pub(crate) value: f32,
    pub(crate) range: std::ops::RangeInclusive<f32>,
}

impl Gauge {
    /// Create a new Gauge.
    ///
    /// # Examples
    /// ```
    /// use cvkg_components::Gauge;
    /// let gauge = Gauge::new(50.0, 0.0..=100.0);
    /// ```
    pub fn new(value: f32, range: std::ops::RangeInclusive<f32>) -> Self {
        Self { value, range }
    }
}

impl View for Gauge {
    type Body = Never;
    fn body(self) -> Self::Body { unreachable!() }
}
use cvkg_core::{Rect, Renderer};

/// Chart types for tactical visualization
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChartType {
    Line,
    Scatter,
    Bar,
    Radar,
}

/// A tactical chart for monitoring mission data
pub struct ChartView {
    chart_type: ChartType,
    data: Vec<f32>,
    color: [f32; 4],
}

impl ChartView {
    /// Create a new ChartView.
    pub fn new(chart_type: ChartType, data: Vec<f32>) -> Self {
        Self {
            chart_type,
            data,
            color: [0.0, 1.0, 1.0, 1.0], // Default NiflCyan
        }
    }

    /// Set the chart color.
    pub fn color(mut self, color: [f32; 4]) -> Self {
        self.color = color;
        self
    }
}

impl View for ChartView {
    type Body = Never;
    fn body(self) -> Self::Body { unreachable!() }

    fn render(&self, renderer: &mut dyn Renderer, rect: Rect) {
        if self.data.is_empty() { return; }

        match self.chart_type {
            ChartType::Line => {
                let dx = rect.width / (self.data.len() - 1) as f32;
                for i in 0..self.data.len() - 1 {
                    let y1 = rect.y + rect.height * (1.0 - self.data[i]);
                    let y2 = rect.y + rect.height * (1.0 - self.data[i+1]);
                    renderer.fill_rect(Rect {
                        x: rect.x + i as f32 * dx,
                        y: y1.min(y2),
                        width: dx,
                        height: (y1 - y2).abs().max(2.0),
                    }, self.color);
                }
            }
            ChartType::Scatter => {
                for (i, &val) in self.data.iter().enumerate() {
                    let dx = rect.width / self.data.len() as f32;
                    let x = rect.x + i as f32 * dx;
                    let y = rect.y + rect.height * (1.0 - val);
                    renderer.fill_rounded_rect(Rect {
                        x: x - 3.0,
                        y: y - 3.0,
                        width: 6.0,
                        height: 6.0,
                    }, 3.0, self.color);
                }
            }
            ChartType::Bar => {
                let dx = rect.width / self.data.len() as f32;
                let spacing = 2.0;
                for (i, &val) in self.data.iter().enumerate() {
                    let h = rect.height * val;
                    renderer.fill_rect(Rect {
                        x: rect.x + i as f32 * dx + spacing,
                        y: rect.y + rect.height - h,
                        width: dx - 2.0 * spacing,
                        height: h,
                    }, self.color);
                }
            }
            ChartType::Radar => {
                renderer.stroke_rect(rect, self.color, 2.0);
            }
        }
    }
}
