Formulate an answer to this elaborate question: What officially ended the first phase of the military conflict between the British Raj and the Emirate of Afghanistan from 1878 to 1880?
Treaty of Gandamak