{ config, lib, pkgs, inputs, ... }:

with lib;
let
  cfg = config.samfelag.modules.desktop;
  laptopPkgs = with pkgs; [
  ];
in
{
  options.samfelag.modules.desktop = {

    enable = mkEnableOption "desktop environment";

    laptop = mkOption {
      description = "Enable features for a laptop (trackpad, battery, etc...)";
      type = types.bool;
      default = false;
    };

    wallpaper = my.mkOpt' types.path ../../data/wallpaper/flors "Path to wallpaper(s)";
  };

  config = mkIf cfg.enable {

    # - Packages ---------------------------------

    environment.systemPackages = with pkgs; [
      pamixer
      i3lock-blur
      brightnessctl
      playerctl
      feh
    ] ++ optionals cfg.laptop laptopPkgs;

    # - Audio ------------------------------------

    sound.enable = true;

    hardware = {
      pulseaudio = {
        enable = true;
        support32Bit = true;
        package = pkgs.pulseaudioFull;
      };
    };

    # - Compositor -------------------------------

    services.picom.enable = true;

    # - Modules ----------------------------------

    samfelag.modules = {

      app.alacritty.enable = true;
      desktop.rofi.enable = true;
      desktop.polybar.enable = true;
      app.firefox.enable = true;

      desktop.i3 = {
        enable = true;
        laptop = cfg.laptop;

        extraStartup = [
          { command = "systemctl --user restart polybar"; always = true; notification = false; }
          { command = "feh --bg-fill -B \"#${config.colorScheme.colors.base00}\" -z --no-fehbg ${cfg.wallpaper}"; always = true; notification = false; }
        ];

        extraKeybindings = {
          "${cfg.i3.mod}+space" = "exec $HOME/.config/rofi/menus/launcher/launcher.sh";
          "${cfg.i3.mod}+End" = "exec $HOME/.config/rofi/menus/powermenu/powermenu.sh";
        };
      };
    };

  };
}
