The rule is simple: you get back what you actually paid after the discount, not the product's original price.
If you return the whole order
You get back exactly what you paid.
If you return one item from a multi item order
The discount is spread across the products proportionally and you get that item's share back. For example: you bought 3 products worth 300, used a 10% code and paid 270. If you return an item originally priced at 100, you get 90 back.
The discount itself is not refunded in cash or converted to store credit, since it never came out of your pocket.
Please also note that a used discount code does not become valid again after a return.