# shellcheck shell=dash

___x_cmd_mac_trash(){
    [ "$#" -gt 0 ] || set -- ls

    local op="$1";  shift
    case "$op" in
        ls|empty|size|allow)
            ___x_cmd_mac_trash_"$op" "$@"                       ;;
        -h|--help)
            ___x_cmd help -m mac trash                          ;;
        *)  N=mac M="Unknown subcmd -> $op" log:ret:64          ;;
    esac
}

___x_cmd_mac_trash___isallow(){
    # Notice: apple not allowed shell to access Trash folder by default for security.
    [ -r "$HOME/.Trash" ] || \
        N=mac M="Not allow to read/modify trash folder in the shell out of security concerns. If you want to grant permission, try 'x mac trash allow'" log:ret:1
}

___x_cmd_mac_trash_allow(){
    mac:error "Sorry, currently we fail to implement this function -> ___x_cmd_mac_trash_allow"
    return 1
}

___x_cmd_mac_trash_empty(){
    ___x_cmd_mac___cmd osascript -e 'tell application "Finder" to empty trash'
}

# TODO: using Finder
___x_cmd_mac_trash_size(){
    ___x_cmd_mac_trash___isallow || {
        # open trash folder
        ___x_cmd open "$HOME/.Trash"
        return
    }
    ___x_cmd_cmds du -sH ~/.Trash/
}

# TODO: using Finder
___x_cmd_mac_trash_ls(){
    ___x_cmd_mac_trash___isallow || {
        # open trash folder
        ___x_cmd open "$HOME/.Trash"
        return
    }
    ___x_cmd_cmds ls -alh ~/.Trash/
}
