Facebook and Instagram’s owner has agreed to pay up to 18 billion dollars (£13.3 billion) as part of a settlement ending a legal battle in the US.