# shellcheck shell=dash

___x_cmd_se_question___accept(){
    local x_
    ___x_cmd_se_question___accept_ "$@" || return

    if ___x_cmd_is_stdout2tty; then
        printf "%s\n" "$x_" | ___x_cmd glow
    else
        printf "%s\n" "$x_"
    fi
}

___x_cmd_se_question___accept_(){
    local question_id="$1"
    local data
    data="$(___x_cmd_se_question___json "$question_id" \
    | ___x_cmd jq -r '.items.[] | select(.is_accepted == true)')"

    local title
    local answer_id
    local markdown
    ___x_cmd jo env . title=.title answer_id=.answer_id markdown=.body_markdown<<A
$data
A
    [ -n "$markdown" ] || {
        se:warn "not found accepted answer of [question_id=$question_id]"
        return 1
    }
    markdown="$(printf "%s\n" "$markdown" | ___x_cmd_cmds sed -e 's|&quot;|"|g' -e "s|&#39;|\'|g")"

    x_="$(printf "%s\n" "
---
title: $title
answerid: $answer_id
questionid: $question_id
---

$markdown
")"

}
