{
  lib,
  config,
  pkgs,
  ...
}: let
  cfg = config.myConfig.sway.kanshi;
in {
  options.myConfig.sway.kanshi = {
    enable = lib.mkEnableOption "kanshi, a dynamic display recognizer";
    laptop = lib.mkEnableOption "laptop workspaces";
  };

  config = lib.mkIf cfg.enable {
    services.kanshi = {
      enable = true;
      settings = lib.mkIf cfg.laptop [
        {
          profile.name = "laptop";
          profile.outputs = [
            {
              criteria = "eDP-1";
              position = "0,0";
            }
          ];
        }
        {
          profile.outputs = [
            {
              criteria = "eDP-1";
              position = "0,1080";
            }
            {
              criteria = "Dell Inc. DELL U2422HE GRCPH83";
              position = "0,0";
            }
            {
              criteria = "NEC Corporation E243WMi 7X313185NB";
              transform = "90";
              position = "1920,0";
            }
          ];
          profile.exec = [
            "${pkgs.sway}/bin/swaymsg [workspace=main] move workspace to DP-4"
            "${pkgs.sway}/bin/swaymsg [workspace=term] move workspace to DP-5"
            "${pkgs.sway}/bin/swaymsg [workspace=msg] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=music] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=5] move workspace to DP-4"
          ];
        }
        {
          profile.outputs = [
            {
              criteria = "eDP-1";
              position = "1080,1080";
            }
            {
              criteria = "Dell Inc. DELL U2422HE 8YCPH83";
              position = "1080,0";
            }
            {
              criteria = "NEC Corporation E243WMi 59118576NB";
              transform = "90";
              position = "0,0";
            }
          ];
          profile.exec = [
            "${pkgs.sway}/bin/swaymsg [workspace=main] move workspace to DP-4"
            "${pkgs.sway}/bin/swaymsg [workspace=term] move workspace to DP-5"
            "${pkgs.sway}/bin/swaymsg [workspace=msg] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=music] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=5] move workspace to DP-4"
          ];
        }
        {
          profile.outputs = [
            {
              criteria = "eDP-1";
              position = "0,1080";
            }
            {
              criteria = "Dell Inc. DELL U2422HE 53DCH83";
              position = "0,0";
            }
            {
              criteria = "Dell Inc. DELL U2412M 0FFXD46I4U5S";
              transform = "90";
              position = "1920,0";
            }
          ];
          profile.exec = [
            "${pkgs.sway}/bin/swaymsg [workspace=main] move workspace to DP-6"
            "${pkgs.sway}/bin/swaymsg [workspace=term] move workspace to DP-7"
            "${pkgs.sway}/bin/swaymsg [workspace=msg] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=music] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=5] move workspace to DP-6"
          ];
        }
        {
          profile.outputs = [
            {
              criteria = "eDP-1";
              position = "1080,1080";
            }
            {
              criteria = "Dell Inc. DELL P2422HE 4BXL9M3";
              position = "1080,0";
            }
            {
              criteria = "NEC Corporation E243WMi 75309334NB";
              transform = "90";
              position = "0,0";
            }
          ];
          profile.exec = [
            "${pkgs.sway}/bin/swaymsg [workspace=main] move workspace to DP-3"
            "${pkgs.sway}/bin/swaymsg [workspace=term] move workspace to DP-4"
            "${pkgs.sway}/bin/swaymsg [workspace=msg] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=music] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=5] move workspace to DP-3"
          ];
        }
        {
          profile.outputs = [
            {
              criteria = "eDP-1";
              position = "1080,1080";
            }
            {
              criteria = "Dell Inc. DELL P2422HE JLXL9M3";
              position = "1080,0";
            }
            {
              criteria = "NEC Corporation E243WMi 59118576NB";
              transform = "90";
              position = "0,0";
            }
          ];
          profile.exec = [
            "${pkgs.sway}/bin/swaymsg [workspace=main] move workspace to DP-3"
            "${pkgs.sway}/bin/swaymsg [workspace=term] move workspace to DP-4"
            "${pkgs.sway}/bin/swaymsg [workspace=msg] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=music] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=5] move workspace to DP-3"
          ];
        }
        {
          profile.outputs = [
            {
              criteria = "eDP-1";
              position = "0,1080";
            }
            {
              criteria = "Dell Inc. DELL P2422HE 7VWL9M3";
              position = "0,0";
            }
            {
              criteria = "ViewSonic Corporation VG2448 V5E201960167";
              transform = "90";
              position = "1920,0";
            }
          ];
          profile.exec = [
            "${pkgs.sway}/bin/swaymsg [workspace=main] move workspace to '\"Dell Inc. DELL P2422HE 7VWL9M3\"'"
            "${pkgs.sway}/bin/swaymsg [workspace=term] move workspace to '\"ViewSonic Corporation VG2448 V5E201960167\"'"
            "${pkgs.sway}/bin/swaymsg [workspace=msg] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=music] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=5] move workspace to '\"Dell Inc. DELL P2422HE 7VWL9M3\"'"
          ];
        }
        {
          profile.name = "docked-4k";
          profile.outputs = [
            {
              criteria = "eDP-1";
              position = "320,1440";
            }
            {
              criteria = "HannStar Display Corp HC281UPB ";
              position = "0,0";
              mode = "3840x2160@60";
              scale = 1.5;
            }
          ];
          profile.exec = [
            "${pkgs.sway}/bin/swaymsg [workspace=main] move workspace to HDMI-A-1"
            "${pkgs.sway}/bin/swaymsg [workspace=term] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=msg] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=music] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=5] move workspace to HDMI-A-1"
          ];
        }
        {
          profile.outputs = [
            {
              criteria = "eDP-1";
              position = "0,0";
            }
            {
              criteria = "Hisense Electric Co., Ltd. HISENSE 0x00000001";
              position = "1920,0";
            }
          ];
          profile.exec = [
            "${pkgs.sway}/bin/swaymsg [workspace=main] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=term] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=msg] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=music] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=5] move workspace to eDP-1"
            "${pkgs.sway}/bin/swaymsg [workspace=mirror] move workspace to HDMI-A-1"
            "${pkgs.sway}/bin/swaymsg [workspace=mirror] exec ${pkgs.wl-mirror}/bin/wl-mirror eDP-1"
          ];
        }
      ];
    };
  };
}
