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

let
  cfg = config.samfelag.modules.app.ghostty;
  i3Cfg = config.samfelag.modules.desktop.wm.i3;
  hyprCfg = config.samfelag.modules.desktop.wm.hyprland;
in
{
  options.samfelag.modules.app.ghostty = {
    enable = lib.mkEnableOption "ghostty";
  };
  config = lib.mkIf cfg.enable {
    hm.home.packages = with pkgs; [
      ghostty
    ];

    fonts.fontconfig.enable = true;

    fonts.packages = with pkgs; [
      iosevka
      pkgs.nerd-fonts.iosevka
    ];

    hm.xdg.configFile."ghostty/config".text = ''
    background = "${config.colorScheme.palette.base00}"
    foreground = "${config.colorScheme.palette.base05}"

    font-family = "Iosevka Nerd Font"
    background-opacity = 0.85
    background-blur = true
    '';

    samfelag.modules.desktop.wm.i3.extraKeybindings = lib.mkIf i3Cfg.enable {
      "${i3Cfg.mod}+Return"       =  "exec ${pkgs.ghostty}/bin/ghostty";
      # "${i3Cfg.mod}+Shift+Return" =  "exec ${pkgs.ghostty}/bin/ghostty -t floating-term";
    };

    samfelag.modules.desktop.wm.hyprland.extraKeybindings = lib.mkIf hyprCfg.enable [
      "${hyprCfg.mod}, Return, exec, ${pkgs.ghostty}/bin/ghostty"
      "${hyprCfg.mod} SHIFT, Return, exec, [float] ${pkgs.ghostty}/bin/ghostty"
    ];

  };
}
