Non-Hermitian Hamiltonians with real and complex eigenvalues in a Lie-algebraic framework