In reading some of James Madison's notes and commentaries on the Constitutional Convention and other discussions such as the Virginia Ratification Debates, it seems like there was a preoccupation with the need for a well-regulated militia to counter the threat of a standing army. This particular clause is seemingly conjoined in the 2nd Amendment with the right to bear arms.
Was the intent of the 2nd Amendment primarily to provide firearms to the people for use in a professionally trained public militia, or was it primarily to allow for the unrestricted ownership of guns?
Why do we not maintain a public militia today when it was of such importance to the framers of the Constitution?
I'm not trying to dissuade discussion here, but this is (as you can imagine) a very popular question on this sub, and it's one that constantly repeats itself. Here's an answer to a similar question from not long ago.
The short version is, the creation of the second amendment was largely due to the fear of armed rebellion against the government. This had happened in many states, the two biggest being Massachusetts and Pennsylvania. Delegates who were in favor of the second amendment wanted the federal government to have the ability for it's own gentry to be able to call up militias in times of need. Remember, this is during a time period with little to no standing army, so having the ability to legally call up a militia was EXTREMELY important.
I'd also like to point out that you mentioned "professionally trained militias" which weren't actually something that existed at this time. Many militiamen were former soldiers in the Continental Army (which was professionally trained) but militias weren't structured like a normal army unit. I can give you details if you are interested, but I wanted to at least mention this.
Why do we not maintain a public militia today when it was of such importance to the framers of the Constitution?
For this question, I really can't fully address because it's outside of my depth. However, essentially, it has to do with a few things. By the end of the 19th century, the US had a national army (regardless of how small it was) and by 1916, the had fully established the National Guard, which completely took the place of needing local militias. Also, it's important to realize that several landmark Supreme Court cases through the last 220+ years greatly shaped the Second Amendment into what it is today -- which is to primarily protect private ownership of firearms.