Куда нам эта шляпа? У нас их целый склад. - Why take this hat, we don't have room for it.
Add "куда + pronoun in Dative + Infinitive" to this row.
Куда тебе бегать, ты и ходишь-то с трудом! - Do you really want to run being unable to walk properly?
Куда там! - No such luck.
It's pretty colloquial, but quite decent.
But the other version is
На кой чёрт тебе эта шляпа? - Why the hell do you need this hat?
Кой is a shorter version of какой.
"Чёрт" was (and is) a swearing word, that's why it was omitted, and the expression became
На кой мне туда идти? - Why the hell shall I go there?
And later one swearing word was replaced by other swearing words an euphemisms.