export const themes = [
  {
    id: 'light',
    name: 'Hell',
    type: 'light',
    group: 'Standard',
    colors: { bg: '#ffffff', accent: '#3b82f6', text: '#0f172a' },
  },
  {
    id: 'dark',
    name: 'Dunkel',
    type: 'dark',
    group: 'Standard',
    colors: { bg: '#0f172a', accent: '#3b82f6', text: '#f1f5f9' },
  },
  {
    id: 'dracula',
    name: 'Dracula',
    type: 'dark',
    group: 'Community',
    colors: { bg: '#282a36', accent: '#bd93f9', text: '#f8f8f2' },
  },
  {
    id: 'mocha',
    name: 'Catppuccin Mocha',
    type: 'dark',
    group: 'Catppuccin',
    colors: { bg: '#1e1e2e', accent: '#89b4fa', text: '#cdd6f4' },
  },
  {
    id: 'latte',
    name: 'Catppuccin Latte',
    type: 'light',
    group: 'Catppuccin',
    colors: { bg: '#eff1f5', accent: '#1e66f5', text: '#4c4f69' },
  },
  {
    id: 'nord',
    name: 'Nord',
    type: 'dark',
    group: 'Community',
    colors: { bg: '#2e3440', accent: '#88c0d0', text: '#eceff4' },
  },
  {
    id: 'tokyo-night',
    name: 'Tokyo Night',
    type: 'dark',
    group: 'Community',
    colors: { bg: '#1a1b26', accent: '#7aa2f7', text: '#a9b1d6' },
  },
  {
    id: 'gruvbox-dark',
    name: 'Gruvbox Dark',
    type: 'dark',
    group: 'Gruvbox',
    colors: { bg: '#282828', accent: '#fe8019', text: '#ebdbb2' },
  },
  {
    id: 'gruvbox-light',
    name: 'Gruvbox Light',
    type: 'light',
    group: 'Gruvbox',
    colors: { bg: '#fbf1c7', accent: '#d65d0e', text: '#3c3836' },
  },
  {
    id: 'rose-pine',
    name: 'Rosé Pine',
    type: 'dark',
    group: 'Rosé Pine',
    colors: { bg: '#191724', accent: '#c4a7e7', text: '#e0def4' },
  },
  {
    id: 'rose-pine-dawn',
    name: 'Rosé Pine Dawn',
    type: 'light',
    group: 'Rosé Pine',
    colors: { bg: '#faf4ed', accent: '#907aa9', text: '#575279' },
  },
  {
    id: 'solarized-dark',
    name: 'Solarized Dark',
    type: 'dark',
    group: 'Solarized',
    colors: { bg: '#002b36', accent: '#268bd2', text: '#839496' },
  },
  {
    id: 'solarized-light',
    name: 'Solarized Light',
    type: 'light',
    group: 'Solarized',
    colors: { bg: '#fdf6e3', accent: '#268bd2', text: '#657b83' },
  },
  {
    id: 'one-dark',
    name: 'One Dark',
    type: 'dark',
    group: 'Community',
    colors: { bg: '#282c34', accent: '#61afef', text: '#abb2bf' },
  },
  {
    id: 'github-dark',
    name: 'GitHub Dark',
    type: 'dark',
    group: 'Community',
    colors: { bg: '#0d1117', accent: '#58a6ff', text: '#c9d1d9' },
  },
  {
    id: 'scrunkly-cat',
    name: 'scrunkly.cat-dark',
    type: 'dark',
    group: 'Community',
    colors: { bg: '#161924', accent: '#b30051', text: '#dadada' },
  },
  {
    id: 'red-modular-light',
    name: 'Red Modular Light',
    type: 'light',
    group: 'Community',
    colors: { bg: '#ffffff', accent: '#e60000', text: '#000000' },
  },
  {
    id: 'everforest-dark',
    name: 'Everforest Dark',
    type: 'dark',
    group: 'Everforest',
    colors: { bg: '#2d353b', accent: '#a7c080', text: '#d3c6aa' },
  },
  {
    id: 'everforest-light',
    name: 'Everforest Light',
    type: 'light',
    group: 'Everforest',
    colors: { bg: '#fdf6e3', accent: '#8da101', text: '#5c6a72' },
  },
  {
    id: 'kanagawa',
    name: 'Kanagawa',
    type: 'dark',
    group: 'Community',
    colors: { bg: '#1f1f28', accent: '#7e9cd8', text: '#dcd7ba' },
  },
  {
    id: 'ayu-dark',
    name: 'Ayu Dark',
    type: 'dark',
    group: 'Ayu',
    colors: { bg: '#0d1017', accent: '#39bae6', text: '#bfbdb6' },
  },
  {
    id: 'moonlight',
    name: 'Moonlight',
    type: 'dark',
    group: 'Community',
    colors: { bg: '#212337', accent: '#82aaff', text: '#c8d3f5' },
  },
  {
    id: 'cyberpunk',
    name: 'Cyberpunk',
    type: 'dark',
    group: 'Community',
    colors: { bg: '#0a0a0f', accent: '#ff0080', text: '#e0e0ff' },
  },
  {
    id: 'cotton-candy-light',
    name: 'Cotton Candy Light',
    type: 'light',
    group: 'Community',
    colors: { bg: '#fff5f9', accent: '#ff85a2', text: '#8b2635' },
  },
];

export function getThemeById(id) {
  return themes.find(t => t.id === id) || themes[1]; // default to dark
}

// Whether the currently applied theme is a dark one. Reads the resolved theme
// from the <html data-theme> attribute (set by ThemeContext) with a localStorage
// fallback, so it works without React context — handy for one-off API payloads
// such as the BBB join call that forwards dark mode to the meeting.
export function isCurrentThemeDark() {
  const id = (typeof document !== 'undefined'
    && document.documentElement.getAttribute('data-theme'))
    || (typeof localStorage !== 'undefined' && localStorage.getItem('theme'))
    || 'dark';
  return getThemeById(id).type === 'dark';
}

export function getThemeGroups() {
  const groups = {};
  themes.forEach(theme => {
    if (!groups[theme.group]) {
      groups[theme.group] = [];
    }
    groups[theme.group].push(theme);
  });
  return groups;
}
