#!/usr/bin/env bash

# Source the script 'common-functions.sh'.
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
ROOT_DIR=$(grep --only-matching "^.*scripts[^/]*" <<<"$SCRIPT_DIR")
source "$ROOT_DIR/common-functions.sh"

_main() {
    local input_files=""

    # Execute initial checks.
    _check_dependencies "command=findimagedupes | command=xdg-open; package=xdg-utils"
    _display_wait_box "0"
    input_files=$(_get_files "par_type=file; par_recursive=true; par_select_mime=image/")

    # Get the installed image viewer.
    local image_viewer=""
    image_viewer=$(_xdg_get_default_app "image/jpeg")

    # Run the main process.
    # shellcheck disable=SC2086
    findimagedupes --recurse --threshold=65% --program="$(which "$image_viewer")" -- $input_files 2>/dev/null
    _display_result_box ""
}

_main "$@"
