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

let
  cfg = config.local.wezterm;
  themeCfg = config.local.theme;
in
{
  options.local.wezterm = with lib; {
    fontSize = mkOption {
      type = types.number;
      default = 11.0;
      description = "Wezterm font size";
    };
  };

  config = {
    programs.wezterm = {
      enable = true;
      colorSchemes = {
        myCoolTheme = {
          ansi = [
            themeCfg.window.regular.color0
            themeCfg.window.regular.color1
            themeCfg.window.regular.color2
            themeCfg.window.regular.color3
            themeCfg.window.regular.color4
            themeCfg.window.regular.color5
            themeCfg.window.regular.color6
            themeCfg.window.regular.color7
          ];
          brights = [
            themeCfg.window.bold.color8
            themeCfg.window.bold.color9
            themeCfg.window.bold.color10
            themeCfg.window.bold.color11
            themeCfg.window.bold.color12
            themeCfg.window.bold.color13
            themeCfg.window.bold.color14
            themeCfg.window.bold.color15
          ];
          indexed = {
            "16" = themeCfg.window.extended.color16;
            "17" = themeCfg.window.extended.color17;
            "18" = themeCfg.window.extended.color18;
            "19" = themeCfg.window.extended.color19;
          };
          background = themeCfg.window.background;
          foreground = themeCfg.window.mainText;
          cursor_bg = themeCfg.window.cursor;
          cursor_border = themeCfg.window.cursor;
          cursor_fg = themeCfg.window.cursorText;
          selection_bg = themeCfg.window.selection;
          selection_fg = themeCfg.window.selectionText;
        };
      };
      extraConfig = ''
        return {
          font = wezterm.font("monospace"),
          font_size = ${toString cfg.fontSize},
          color_scheme = "myCoolTheme",
          hide_tab_bar_if_only_one_tab = true,
        }
      '';
    };
  };
}
