{ lib, config, ... }:

with lib;
let
  cfg = config.modules.software.system.wezterm;
in {
  options.modules.software.system.wezterm = {
    enable = mkEnableOption "Enable wezterm, a blazingly fast terminal emulator";
  };

  config = mkIf cfg.enable {
    environment.variables.TERM = "wezterm";

    hm.programs.wezterm = {
      enable = true;
      extraConfig = let
        fonts = config.modules.desktop.fonts.fonts;
      in ''
        local wezterm = require 'wezterm'

        local config = {}

        config.font = wezterm.font '${fonts.monospaceBitmap.family}'
        config.font_size = ${toString fonts.monospaceBitmap.size}
        config.freetype_load_flags = 'MONOCHROME'
        config.enable_wayland = false
        config.color_scheme = 'Catppuccin Mocha'
        config.use_fancy_tab_bar = false
        config.use_resize_increments = true
        config.initial_cols = 120
        config.initial_rows = 40

        config.window_frame = {
          font = wezterm.font '${fonts.sansSerif.family}',
          font_size = ${toString fonts.sansSerif.size}
        }

        return config
      '';
    };
  };
}
