use std::collections::BTreeMap;
use ratatui::style::Color;
use super::identity::sha256_hex;
use super::skin::SkinTokens;
use crate::palette::{LIGHT_UI_THEME, UI_THEME, UiTheme};
pub(crate) const OCEAN_STORAGE_KEY: &str = "codewhale.ocean";
pub(crate) const OCEAN_OFF_CLASS: &str = "codewhale-ocean-off";
pub(crate) const OCEAN_WINDOW_HANDLE: &str = "__codewhaleOcean";
const BASE_VEIL_ALPHA: &str = "0.42";
const SIDEBAR_VEIL_ALPHA: &str = "0.78";
pub(crate) fn bundle_scene_js() -> &'static str {
include_str!("scene.js")
}
pub(crate) fn scene_sha256() -> String {
sha256_hex(bundle_scene_js().as_bytes())
}
fn rgb(color: Color) -> Option<(u8, u8, u8)> {
match color {
Color::Rgb(r, g, b) => Some((r, g, b)),
_ => None,
}
}
fn hex(color: Color) -> String {
crate::palette::hex_rgb_string(color).unwrap_or_else(|| "#808080".to_string())
}
fn rgba(color: Color, alpha: &str) -> String {
match rgb(color) {
Some((r, g, b)) => format!("rgba({r},{g},{b},{alpha})"),
None => "inherit".to_string(),
}
}
pub(crate) fn ocean_palette() -> BTreeMap<&'static str, BTreeMap<&'static str, String>> {
fn one(theme: &UiTheme) -> BTreeMap<&'static str, String> {
let mut m = BTreeMap::new();
m.insert("base", hex(theme.surface_bg));
m.insert("accent", hex(theme.accent_primary));
m.insert("ink", hex(theme.text_body));
m.insert("dim", hex(theme.text_dim));
m
}
let mut map = BTreeMap::new();
map.insert("light", one(&LIGHT_UI_THEME));
map.insert("dark", one(&UI_THEME));
map
}
pub(crate) fn ocean_palette_json() -> String {
serde_json::to_string_pretty(&ocean_palette()).expect("ocean palette is json")
}
pub(crate) fn ocean_veil_tokens() -> BTreeMap<String, SkinTokens> {
let light = &LIGHT_UI_THEME;
let dark = &UI_THEME;
let mut map = BTreeMap::new();
map.insert(
"--dsw-alias-bg-base".to_string(),
SkinTokens {
light: rgba(light.surface_bg, BASE_VEIL_ALPHA),
dark: rgba(dark.surface_bg, BASE_VEIL_ALPHA),
},
);
map.insert(
"--dsw-specific-sidebar-fill".to_string(),
SkinTokens {
light: rgba(light.panel_bg, SIDEBAR_VEIL_ALPHA),
dark: rgba(dark.panel_bg, SIDEBAR_VEIL_ALPHA),
},
);
map
}
pub(crate) fn ocean_veil_json() -> String {
serde_json::to_string_pretty(&ocean_veil_tokens()).expect("ocean veil is json")
}