{ lib, config, pkgs, ... }:
with lib;
let
  cfg = config.modules.desktop.sway;
in
{
  options.modules.desktop.sway = {
    enable = mkEnableOption "enable Sway Windows Manager";

    kanshi = mkOption {
      type = types.bool;
      default = false;
      description = "configure laptop mode";
    };

    wallpapers = {
      lockscreen = mkOption {
        type = types.str;
        default = "";
        description = "path for lockscreen wallpaper";
      };
      desktop = mkOption {
        type = types.str;
        default = "#000000 solid_color";
        description = "options for desktop wallpaper";
      };
    };

    waybar = {
      laptop = mkOption {
        type = types.bool;
        default = false;
        description = "Enable laptop element on Waybar";
      };

      cpuThermal = {

        thermalZone = mkOption {
          type = types.str;
          default = "";
          description = "CPU thermal hwmon thermal Zone";
        };

        hwmonPathAbs = mkOption {
          type = types.str;
          default = "";
          description = "CPU thermal hwmon absolute path";
        };

        inputFilename = mkOption {
          type = types.str;
          default = "";
          description = "CPU thermal hwmon file";
        };
      };

      gpuThermal = {
        enable = mkOption {
          type = types.bool;
          default = false;
          description = "enable waybar GPU temperature";
        };

        hmonPath = mkOption {
          type = types.str;
          default = "";
          description = "Thermal zone for CPU";
        };
      };
    };
  };
  imports = [
    ./includes/fuzzel.nix
    ./includes/kanshi.nix
    ./includes/mako.nix
    ./includes/sway.nix
    ./includes/swayidle.nix
    ./includes/swaylock.nix
    ./includes/waybar.nix
  ];
  config = mkIf cfg.enable {

    programs.fuzzel.enable = true;

    home.packages = with pkgs; [
      dejavu_fonts
      # emojione
      font-awesome
      grim
      lato
      liberation_ttf
      libertine
      libnotify
      nerd-fonts.fira-code
      nerd-fonts.fira-mono
      noto-fonts-emoji
      noto-fonts-cjk-sans
      slurp
      wl-clipboard
      xdg-utils
    ];

    programs.zsh.loginExtra = ''
      if [ "$(tty)" = "/dev/tty1" ]; then
        exec sway &> /dev/null
      fi
    '';

    gtk = {
      enable = true;
      theme = {
        name = "Arc-Dark";
        package = pkgs.arc-theme;
      };
      iconTheme = {
        name = "Papirus Dark";
        package = pkgs.papirus-icon-theme; 
      };
      font = {
        name = "Deja Vu Sans";
        package = "${pkgs.dejavu_fonts}";
        size = 10;
      };
    };

    home.pointerCursor = {
      name = "Adwaita";
      package = pkgs.adwaita-icon-theme;
      size = 24;
      x11 = {
        enable = true;
        defaultCursor = "Adwaita";
      };
    };

    # Avoid pixelated effect for QT application with fractionnal scaling
    home.sessionVariables = {
      QT_SCALE_FACTOR_ROUNDING_POLICY = "RoundPreferFloor";
    };

 	  qt = {
		  enable = true;
      platformTheme.name = "adwaita";
      style.name = "adwaita-dark";
	  };
    xdg = {
      enable = true;
      mimeApps.enable = true;
      userDirs = {
        enable = true;
        createDirectories = true;
        documents = "${config.home.homeDirectory}/documents";
        download = "${config.home.homeDirectory}/downloads";
        music = "${config.home.homeDirectory}/medias/musics";
        pictures = "${config.home.homeDirectory}/medias/images";
        videos = "${config.home.homeDirectory}/medias/videos";
        templates = "${config.home.homeDirectory}/tmp";
        desktop = "${config.home.homeDirectory}/documents";
        publicShare = "${config.home.homeDirectory}/tmp/public";
      };
    };
  };
}
