{ lib, ... }:
let
  mediaDir = ../media;
  mainDir = mediaDir + "/main";
  maybePath = rel:
    let path = mediaDir + "/${rel}";
    in if builtins.pathExists path then path else null;
  mainImages =
    let
      names = builtins.attrNames (builtins.readDir mainDir);
      isImage = name: builtins.match ".*\\.(png|jpg|jpeg|webp|svg)$" name != null;
    in
    map (name: mainDir + "/${name}") (lib.sort builtins.lessThan (lib.filter isImage names));
in
with lib; {
  logo = {
    ico = mkOption {
      type = types.path;
      default = mediaDir + "/logo.ico";
    };
    svg = mkOption {
      type = types.path;
      default = mediaDir + "/logo.svg";
    };
    png = mkOption {
      type = types.path;
      default = mediaDir + "/logo.png";
    };
  };

  banner = {
    svg = mkOption {
      type = types.nullOr types.path;
      default = maybePath "banner.svg";
    };
    png = mkOption {
      type = types.nullOr types.path;
      default = maybePath "banner.png";
    };
  };

  main = mkOption {
    type = types.listOf types.path;
    default = if mainImages != [ ] then mainImages else lib.optional (maybePath "main/bg.png" != null) (mediaDir + "/main/bg.png");
  };

  bg = mkOption {
    type = types.path;
    default = let bg = maybePath "main/main.png"; in if bg != null then bg else builtins.head mainImages;
  };
}
