{
  lib,
  config,
  ...
}: let
  inherit (lib) mkOption types mkIf recursiveUpdate lists;
  inherit (lists) remove;

  # v0.49.0
  # Parsing regex: /SConfigOptionDescription{\n? *\.value *= "(.*)",\n *\.description = ?\n? *"([\d\D]*?)",\n *\.type *= CONFIG_OPTION_(.*),\n *.data *= (.*),\n *},/gm

  cfg = config.horseman.wm.hyprland;
  homeCfg = config.horseman;
in {
  options.horseman.wm.hyprland.config.waybar = {
    layout = {
      horizontal = {
        left = mkOption {type = types.listOf types.str;};
        center = mkOption {type = types.listOf types.str;};
        right = mkOption {type = types.listOf types.str;};
      };
      vertical = {
        left = mkOption {type = types.listOf types.str;};
        center = mkOption {type = types.listOf types.str;};
        right = mkOption {type = types.listOf types.str;};
      };
    };
    formats = {
      horizontal = mkOption {
        type = types.attrs;
      };
      vertical = mkOption {
        type = types.attrs;
      };
    };
    modules = mkOption {
      type = types.attrs;
    };
  };

  config = mkIf cfg.enable {
    horseman.dots = {
      fuzzel.enable = true;
      waybar.enable = true;
      dunst.enable = true;
    };

    home-manager.users.${homeCfg.username} = {
      programs.waybar = {
        enable = true;

        settings = let
          outputMap = location: (
            remove null (
              map (disp:
                if (disp.bar == location)
                then disp.output
                else null)
              config.nix-hyprland.monitors.displays
            )
          );
        in {
          topBar =
            recursiveUpdate
            {
              layer = "top";
              position = "top";
              output = outputMap "top";

              modules-left = cfg.config.waybar.layout.horizontal.left;
              modules-center = cfg.config.waybar.layout.horizontal.center;
              modules-right = cfg.config.waybar.layout.horizontal.right;
            } (recursiveUpdate cfg.config.waybar.modules cfg.config.waybar.formats.horizontal);

          bottomBar =
            recursiveUpdate
            {
              layer = "top";
              position = "bottom";
              output = outputMap "bottom";

              modules-left = cfg.config.waybar.layout.horizontal.left;
              modules-center = cfg.config.waybar.layout.horizontal.center;
              modules-right = cfg.config.waybar.layout.horizontal.right;
            } (recursiveUpdate cfg.config.waybar.modules cfg.config.waybar.formats.horizontal);

          rightBar =
            recursiveUpdate
            {
              layer = "top";
              position = "right";
              output = outputMap "right";

              modules-left = cfg.config.waybar.layout.vertical.left;
              modules-center = cfg.config.waybar.layout.vertical.center;
              modules-right = cfg.config.waybar.layout.vertical.right;
            } (recursiveUpdate cfg.config.waybar.modules cfg.config.waybar.formats.vertical);

          leftBar =
            recursiveUpdate
            {
              layer = "top";
              position = "left";
              output = outputMap "left";

              modules-left = cfg.config.waybar.layout.vertical.left;
              modules-center = cfg.config.waybar.layout.vertical.center;
              modules-right = cfg.config.waybar.layout.vertical.right;
            } (recursiveUpdate cfg.config.waybar.modules cfg.config.waybar.formats.vertical);
        };
      };
    };
  };
}
