{ config, lib, ... }:

with lib;

let
  cfg = config.settings.applications.zellij;
in {
  options = {
    settings.applications.zellij.enable = lib.mkOption {
      type = lib.types.bool;
      description = ''
        Enable zellij tool
      '';
    };
  };

  config = mkIf cfg.enable {
    programs.zellij = {
      enable = true;
    };

    home.file.zellij = {
      target = ".config/zellij/config.kdl";
      text = ''
        pane_frames false
        keybinds {
          normal {
            bind "Ctrl e" { ToggleFloatingPanes; SwitchToMode "normal"; }
            bind "Alt 1" { GoToTab 1; }
            bind "Alt 2" { GoToTab 2; }
            bind "Alt 3" { GoToTab 3; }
            bind "Alt 4" { GoToTab 4; }
            bind "Alt 5" { GoToTab 5; }
          }
        }
      '';
    };

    home.file.zellij-layout-default = {
      target = ".config/zellij/layouts/default.kdl";
      text = ''
        layout {
          pane 
          floating_panes {
            pane {
              width "80%"
              height "80%"
              x "10%"
              y "10%"
            }
          }
        }
      '';
    };

    home.file.zellij-layout-dioxus = {
      target = ".config/zellij/layouts/dioxus.kdl";
      text = ''
        layout {
          tab {
            pane {
              command "hx"
              args "."
              focus true
            }
            floating_panes {
              pane {
                width "80%"
                height "80%"
                x "10%"
                y "10%"
              }
            }
          }
          tab {
            pane {
              command "dx"
              args "serve"
            }
          }
          tab {
            pane {
              command "devenv"
              args "up"
            }
          }
        }
      '';
    };
  };
}

