{ config, lib, ... }:

let
  nomarchyLib = import ../../lib { inherit lib; };
  assetsPath = ../../themes/palettes;

  # Read unified state from ~/.config/nomarchy/state.json
  togglesState = nomarchyLib.readHomeState config.home.homeDirectory;
in
{
  config = {
    nomarchy = {
      toggles = {
        suspend = togglesState.suspend or true;
        screensaver = togglesState.screensaver or true;
        idle = togglesState.idle or true;
        nightlight = togglesState.nightlight or false;
        waybar = togglesState.waybar or true;
        skipVsCodeTheme = togglesState.skipVsCodeTheme or false;
      };
      nightlightTemperature = togglesState.nightlightTemperature or 4000;
      theme = togglesState.theme or "summer-night";
      wallpaper = togglesState.wallpaper or "";
      hyprland = {
        gaps_in = togglesState.hyprland.gaps_in or 5;
        gaps_out = togglesState.hyprland.gaps_out or 10;
        border_size = togglesState.hyprland.border_size or 2;
      };
      fonts.monospace = togglesState.font or "JetBrainsMono Nerd Font";

      # Derived properties from the theme directory
      isLightMode = nomarchyLib.isThemeLightMode {
        themeName = togglesState.theme or "summer-night";
        inherit assetsPath;
      };
      iconsTheme = nomarchyLib.getIconsTheme {
        themeName = togglesState.theme or "summer-night";
        inherit assetsPath;
      };
    };
  };
}
