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

with lib;

let

  cfg = config.programs.custom.citate;

  library = import ../../library { inherit pkgs lib; };

  xdotool = "${pkgs.xdotool}/bin/xdotool";
  dmenu = "${pkgs.dmenu}/bin/dmenu";

  citateScript = file: suffix:
    pkgs.writeShellScriptBin "citate-${suffix}" ''
      ${xdotool} - <<<"type -- $( cat ${file} | ${dmenu} -l 10 -i | sed -e "s/\(.*\)/'\1'/" )"
    '';

  scriptAxel = citateScript (toString ../../assets/sprueche-axel) "axel";
  scriptSiw = citateScript (toString ../../assets/sprueche-siw) "siw";

in
{

  options.programs.custom.citate = {
    enable = mkEnableOption "enable programs.custom.citate";
  };

  config = mkIf cfg.enable {
    environment.systemPackages = [
      scriptAxel
      (library.desktopFile scriptAxel {
        longName = "Citate Axel";
        command = "citate-axel";
      })
      scriptSiw
      (library.desktopFile scriptSiw {
        longName = "Citate Sinnlos im Weltall";
        command = "citate-siw";
      })
    ];
  };
}