Why is my player's flipping system not working?

So the problem is that whenever I use move_and_slide() velocity based movement. the player flips rapidly between scale.x 1 and -1 and if i remove move_and_slide() my flipping system works perfect.

extends CharacterBody2D

enum direction {
	is_facing_right,
	is_facing_left,
	is_facing_down,
	is_facing_up
}
var dir = direction.is_facing_down
var is_moving = false
var last_move = Vector2(0, 1)
@onready var graphics = $Sprite2D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
	print(dir)
	var input = Input.get_vector("left", "right", "up", "down")
	velocity = input * 100
	if !is_moving:
		match(dir):
			direction.is_facing_right:
				graphics.play("idle_left")
			direction.is_facing_left:
				graphics.play("idle_left")
			direction.is_facing_up:
				graphics.play("idle_up")
			direction.is_facing_down:
				graphics.play("idle_down")
	if input:
		is_moving = true
		if(input.x < 0 and input.y == 0):
			scale.x = 1
			graphics.play("walk_left")
			dir = direction.is_facing_left
		elif(input.x > 0 and input.y == 0):
			scale.x = -1
			dir = direction.is_facing_right
			graphics.play("walk_left")
		if(input.y < 0):
			graphics.play("walk_up")
			dir = direction.is_facing_up
		elif(input.y > 0):
			graphics.play("walk_down")
			dir = direction.is_facing_down
	else:
		is_moving = false
	move_and_slide()
	pass