# shellcheck shell=dash disable=SC2016
___x_cmd_font_nerd_ls(){
    local X_help_cmd=""; X_help_cmd='x help -m font nerd ls' help:arg:parse

    if ! ___x_cmd_is_stdout2tty || ! ___x_cmd_runmode_allow_manual; then
        ___x_cmd_font_nerd___tsv_name
        return
    fi
    local x_=""
    ___x_cmd storerat_ ___x_cmd_font_nerd___fzf || return

    local id=""
    ___x_cmd ui select id "Select next item -> $x_"   \
        "x font nerd install $x_"                     \
        "x font nerd preview $x_"                     \
        "x font nerd info $x_"                        \
        "return 0"

    case "$id" in
        1)      ___x_cmd font nerd install "$x_" ;;
        2)      ___x_cmd font nerd preview "$x_" ;;
        3)      ___x_cmd font nerd info    "$x_" ;;
        *)      return 0
    esac
}

___x_cmd_font_nerd___tsv_raw(){
    ___x_cmd ccmd 1d -- ___x_cmd httpget gitx x-cmd font main "data/nerd-fonts-${___X_CMD_FONT_NERD_VERSION}.tsv"
}

___x_cmd_font_nerd___tsv_name(){
    ___x_cmd_font_nerd___tsv_raw | ___x_cmd_cmds awk -v FS="\t" '{ print $1 }'
}

___x_cmd_font_nerd___fzf(){
    ___x_cmd_font_nerd___tsv_name \
        | {
            FORCE_COLOR=1 \
            FZF_DEFAULT_OPTS="
                --ansi
                --reverse
                --height='80%'
                --bind='ctrl-w:toggle-preview-wrap'
                --bind='ctrl-r:change-preview-window(right,70%|down,40%,99%,border-horizontal|hidden|right)'
            "   ___x_cmd fzf --preview="___x_cmdexe font nerd info {1}" --preview-window="right:70,wrap"
        }
}
