branch() {
    if [ "$(cat /etc/locale.conf | grep "LANG")" = "LANG=pt_BR.UTF-8" ]
    then
    echo -e "\e[34;1m==>\e[39;1m Não oferecemos suporte para este ramo... \e[0m"
    else
    echo -e "\e[34;1m==>\e[39;1m We do not support this branch... \e[0m"
    fi
}

sync_mirrors() {
    manjariando-mirrors -c all >/dev/null
}

message() {
    if [ "$(cat /etc/locale.conf | grep "LANG")" = "LANG=pt_BR.UTF-8" ]
    then
    echo -e "\e[34;1m==>\e[39;1m Dica: use \`sudo manjariando-mirrors -g\` para atualizar sua lista de espelhos Manjariando... \e[0m"
    else
    echo -e "\e[34;1m==>\e[39;1m Hint: use \`sudo manjariando-mirrors -g\` to update your Manjariando mirrorlist... \e[0m"
    fi
}

post_install() {
    if [ "$(pacman-mirrors -G)" = "stable-staging" ]; then
        branch
    else
        systemctl enable manjariando-mirrors.timer

        if [ "$(cat /etc/locale.conf | grep "LANG")" = "LANG=pt_BR.UTF-8" ]
        then
        echo -e "\e[34;1m==>\e[39;1m Aguarde um momento, estamos classificando os melhores espelhos... \e[0m"
        else
        echo -e "\e[34;1m==>\e[39;1m Wait a moment, we are classifying the best mirrors... \e[0m"
        fi

        sync_mirrors

        message
    fi
}

post_upgrade() {
    if [ "$(pacman-mirrors -G)" = "stable-staging" ]; then
        branch
    else
        if [ "$(cat /etc/locale.conf | grep "LANG")" = "LANG=pt_BR.UTF-8" ]
        then
        echo -e "\e[34;1m==>\e[39;1m Aguarde um momento, estamos classificando os melhores espelhos... \e[0m"
        else
        echo -e "\e[34;1m==>\e[39;1m Wait a moment, we are classifying the best mirrors... \e[0m"
        fi

        if systemctl is-enabled manjariando-mirrors.timer 1>/dev/null; then
            sync_mirrors
        else
            systemctl enable manjariando-mirrors.timer
            sync_mirrors
        fi

        message
    fi
}

pre_remove() {
    if [ -e "/usr/lib/systemd/system/manjariando-mirrors.timer" ]; then
        systemctl daemon-reload
        systemctl disable --now manjariando-mirrors.timer
    fi
}

post_remove() {

    if [ -e "/etc/pacman.d/manjariando-mirrorlist" ]; then
        rm -rf /etc/pacman.d/manjariando-mirrorlist
    fi
}
