Why does this man I work with act like this?

Background—We have worked together for 3 years.
Him and I get on very well and I really like him.
I’ve always had a crush on him ever since I met him but never acted on it.
He is single too but he is a bit older than me.

Some days he’s very flirty towards me, gives me compliments and will be very chatty. We will text each other outside of work too.

Then other days at work he will be extremely moody with me, is quite rude to me, makes me feel like I’m asking him stupid questions or just annoying him and like he doesn’t want to talk to me so I sometimes get scared to approach him.

Then other days he’s all chatty, super nice and flirting with me.

We went out for drinks with other colleagues a month ago and when he was drunk he told me he really liked me and kept saying sorry over and over…

He acts like he may like me then the next day he acts like he hates me.

I know everyone has bad days but I just find the whole flirting with me one day, being rude, then apologising, then back to flirting a bit of a head fuck - especially with a man in his late 40s who is 15 years older than me.. so why does he act this way?
Why does this man I work with act like this?
Add Opinion