How do I reset the rotation?

The coding is a mess, I just starting Unity about a day ago, and everything works fine, but when I use “transform.rotation = Quaternion.Euler(0, 0, 0);” It snaps it back but I want it to slowly rotate back to “0, 0, 0” So how would I implement a new way of doing that?
{
if (Input.GetKey(KeyCode.W))
transform.Rotate(Vector3.left * speed * Time.deltaTime);

    if (Input.GetKey(KeyCode.S))
  transform.Rotate(Vector3.left * -speed * 1 * Time.deltaTime);

 if (Input.GetKey(KeyCode.A))
  transform.Rotate(Vector3.forward * speed * Time.deltaTime);

  if (Input.GetKey(KeyCode.D))
  transform.Rotate(Vector3.forward * -speed * 1 * Time.deltaTime);

  if (Input.GetKeyUp(KeyCode.D))
  transform.rotation = Quaternion.Euler(0, 0, 0);

if (Input.GetKeyUp(KeyCode.A))
  transform.rotation = Quaternion.Euler(0, 0, 0);

if (Input.GetKeyUp(KeyCode.S))
transform.rotation = Quaternion.Euler(0, 0, 0);

if (Input.GetKeyUp(KeyCode.W))
transform.rotation = Quaternion.Euler(0, 0, 0);
}
}

Use Quaternion.Slerp(). Note that you will need to store the starting rotation. Also, you can use Quaternion.identity instead of Quaternion.Euler(0, 0, 0)

Quaternion startRotation;
float time;

private void SomeFunctionCalledOnceAtBeginningOfRotation()
{
    startRotation = transform.rotation;
}

private void SomeFunctionCalledEveryFrame()
{
    transform.rotation = Quaternion.Slerp(startRotation, Quaternion.identity, time);
    time += Time.deltaTime;
}