[verb て-form] + くれてありがとう [verb て-form] + くれてありがとうございます [verb て-form] + くださってありがとうございます
てくれてありがとう is "thank you for ~ing". The verb goes into the て-form, then comes くれて, then ありがとう.
くれて says the action was done for you, and it is what links the verb to ありがとう. The て-form on its own does not.
To a friend, ありがとう is enough. To someone you speak politely to, it is ありがとうございます. To a teacher, a customer or someone senior, くれて also becomes the honorific くださって.
When the favour is over – at the end of a visit, a meeting, a lesson – the polite form usually goes into the past. While it is still going on, or for something that keeps happening, it stays ありがとうございます.
てもらってありがとう is also heard. It thanks from your side as the one who received; てくれて puts the other person's action first and is the usual choice.