use serde::{Deserialize, Serialize};

use super::color::{Color, Scale12, Step12, SurfaceLevel};
use super::dim::{BlurRadius, ShadowOffset, StrokeWidth};

#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Border {
    pub width: StrokeWidth,
    pub color: Color,
}

#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Shadow {
    pub offset_x: ShadowOffset,
    pub offset_y: ShadowOffset,
    pub blur: BlurRadius,
    pub color: Color,
}

#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ElevationLevel {
    pub surface: SurfaceLevel,
    pub border: Option<Border>,
    pub shadow: Option<Shadow>,
}

#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct ElevationScale {
    pub level0: ElevationLevel,
    pub level1: ElevationLevel,
    pub level2: ElevationLevel,
    pub level3: ElevationLevel,
}

impl ElevationScale {
    pub(in crate::theme) fn tonal(neutral: Scale12) -> Self {
        Self {
            level0: ElevationLevel {
                surface: SurfaceLevel::L0,
                border: None,
                shadow: None,
            },
            level1: ElevationLevel {
                surface: SurfaceLevel::L1,
                border: Some(Border {
                    width: StrokeWidth::HAIRLINE,
                    color: neutral.step(Step12::SUBTLE_BORDER),
                }),
                shadow: None,
            },
            level2: ElevationLevel {
                surface: SurfaceLevel::L2,
                border: Some(Border {
                    width: StrokeWidth::HAIRLINE,
                    color: neutral.step(Step12::BORDER),
                }),
                shadow: None,
            },
            level3: ElevationLevel {
                surface: SurfaceLevel::L3,
                border: Some(Border {
                    width: StrokeWidth::HAIRLINE,
                    color: neutral.step(Step12::HOVER_BORDER),
                }),
                shadow: None,
            },
        }
    }
}
