How is repair cost calculated?

I hear equipment quality comes into play but how much does the more expensive stuff affect the total cost? 

And how do deaths factor in?