Sample error terms relationship In regression models, I just want to know why the sample error terms have such relationship as: $$\hat e_i=y_i-\hat\beta_0-\hat\beta_1 x_i=(y_i-\bar y)-\hat\beta_1(x_i-\bar x).$$ where $(\bar x, \bar y)$ is the sample mean of $x$ and $y$.
The first equality is about the definition of the sample error term but do not understand the second equality.

From the normal equations
$$\begin{bmatrix}n &\sum x_i\\\sum x_i& \sum x_i^2\end{bmatrix}\begin{bmatrix}\hat\beta_0\\\hat \beta_1\end{bmatrix}=\begin{bmatrix}\sum y_i\\ \sum x_iy_i\end{bmatrix}\tag1$$
$\hat \beta_0 =\bar y-\hat \beta_1\bar x. $ Substitute that in the expression of residual.
