# shellcheck shell=dash

___x_cmd log init mac

xrc shortcut
xrc:mod:lib     mac                     \
                _desktop/_index         \
                _device/_index          \
                _exit/_index            \
                _hw/_index              \
                _network/_index         \
                _pref/_index            \
                note/_index             \
                re/_index               \
                sb/_index               \
                info    mem     alias

___x_cmd_mac___main(){
    [ "$#" -gt 0 ] || set -- --help

    ___x_cmd os name darwin: || {
        mac:error "This module is only supported in macOS environments."
        return 1
    }

    local op="$1"; shift
    case "$op" in
        b|battery)                      ___x_cmd_mac_battery                   "$@" ;;
        bt|bluetooth)                   ___x_cmd_mac_bluetooth                 "$@" ;;

        alias|\
        info|mem|net|wifi|disk|smc|\
        lock|screensave|sleep|logout|\
        restart|shutdown|trash|dock|\
        vpn|ntp|fw|airdrop|\
        lang|name|\
        launchpad|wallpaper|sshd|appid|tidsudo)
                                        ___x_cmd_mac_"$op"                     "$@" ;;

        sb|sandbox)                     ___x_cmd_mac_sb                        "$@" ;;
        re|reminder)                    ___x_cmd_mac_re                        "$@" ;;
        n|note)                         ___x_cmd_mac_note                      "$@" ;;

        v|vol)                          ___x_cmd_mac_vol                       "$@" ;;

        ss|systemsetup)                 ___x_cmd_mac_ss                        "$@" ;;
        sysctl)                         ___x_cmd sysctl                        "$@" ;;

        od)                             ___x_cmd_mac_od                        "$@" ;;

        fm|flightmode)                  ___x_cmd_mac_flightmode                "$@" ;;

        --help|-h)                      ___x_cmd help -m mac                        ;;
        exp)                            ___x_cmd_mac___exp                     "$@" ;;
        *)                              N=mac M="Unknown subcmd -> $op" log:ret:64  ;;
    esac
}

___x_cmd_mac___exp(){
    [ "$#" -gt 0 ] || set -- --help

    local op="$1"; shift
    case "$op" in
        -h|--help)                      ___x_cmd help -m mac exp     ;;
        hidden|smc|flightmode|dss|finder)
                                        ___x_cmd_mac_"$op"      "$@" ;;
        # common shortcuts
        eject)                          ___x_cmd_mac_disk eject "$@" ;;
        *)                              N=mac M="Unknown subcmd -> $op" log:ret:64 ;;
    esac
}

___x_cmd_mac___cmd(){
    local IFS=" "
    mac:debug --cmd "$*" "running comand"

    "$@"
}
