# shellcheck shell=dash

xrc:mod:lib    mac     _desktop/dock/magnification

___x_cmd_mac_dock(){
    [ $# -gt 0 ]     || set -- size
    local op="$1";      shift
    case "$op" in
        -h|--help)      ___x_cmd help -m mac dock       ;;

        size|resize|orientation|\
        autohide|magnification|\
        restart)
                        ___x_cmd_mac_dock_"$op" "$@"    ;;
        *)              N=mac M="Unknown subcmd -> $op" log:ret:64 ;;
    esac
}

___x_cmd_mac_dock_restart(){
    ___x_cmd_mac___cmd killall Dock
}

___x_cmd_mac_dock_size(){
    ___x_cmd_mac___cmd defaults read com.apple.dock tilesize
}

___x_cmd_mac_dock_resize(){
    local size="$1";
    if [ "$size" = "--help" ] || [ "$size" = "-h" ]; then
        ___x_cmd help -m mac dock resize
        return
    elif [ "$size" -gt 128 ] || [ "$size" -lt 16 ];then
        N=mac M="Icon sizes should be between 16-128" log:ret:64
    fi
    ___x_cmd_mac___cmd defaults write com.apple.dock tilesize -int "$size"
    ___x_cmd_mac_dock_restart
}

___x_cmd_mac_dock_orientation(){
    local size="$1";
    if [ "$size" = "--help" ] || [ "$size" = "-h" ]; then
        ___x_cmd help -m mac dock orientation
        return
    fi
    ___x_cmd_mac___cmd defaults write com.apple.dock orientation -string "$@"
    ___x_cmd_mac_dock_restart
}

___x_cmd_mac_dock_autohide(){
    local op="$1"; shift
    case "$op" in
        -h|--help)  ___x_cmd help -m mac dock  autohide; return      ;;
        enable)     ___x_cmd_mac___cmd defaults write com.apple.dock autohide -bool true    ;;
        disable)    ___x_cmd_mac___cmd defaults write com.apple.dock autohide -bool false   ;;
        *)          N=mac M="Please specify whether to enable or disable" log:ret:64        ;;
    esac
    ___x_cmd_mac_dock_restart
}
