let
  themesDir = ./.;
  
  # Get all directories in the themes folder that have a colors.toml file
  allEntries = builtins.readDir themesDir;
  directories = builtins.filter (name: 
    allEntries.${name} == "directory" && builtins.pathExists (themesDir + "/${name}/colors.toml")
  ) (builtins.attrNames allEntries);

  readTheme = name:
    let
      toml = builtins.fromTOML (builtins.readFile (themesDir + "/${name}/colors.toml"));
      
      # Helper to strip '#' from color codes
      stripHash = s: builtins.replaceStrings ["#"] [""] s;
      
    in {
      inherit name;
      author = "nomarchy";
      palette = {
        base00 = stripHash toml.background;
        base01 = stripHash toml.color0;
        base02 = stripHash toml.color8;
        base03 = stripHash toml.color8;
        base04 = stripHash toml.color7;
        base05 = stripHash toml.foreground;
        base06 = stripHash toml.color15;
        base07 = stripHash toml.color15;
        base08 = stripHash toml.color1;
        base09 = stripHash toml.color3;
        base0A = stripHash toml.color3;
        base0B = stripHash toml.color2;
        base0C = stripHash toml.color6;
        base0D = stripHash toml.color4;
        base0E = stripHash toml.color5;
        base0F = stripHash toml.color1;
      };
    };

in
  builtins.listToAttrs (map (name: {
    inherit name;
    value = readTheme name;
  }) directories)
