Javascript calculation in private plugin and data sources

What I want to do is:

I am in a page and have 3 states that are filled with the values of user’s choices.

My plugin needs to get those values, query the database to get some extra values (I didn’t understand how exactly I can do this from the states) and then make a calculation and populate some input fields on the page with the results. This needs to be an action from what I understood.

The documentation is not very clear on this flow. Can someone help to explain what steps I need to do? Thank you

Are you able to query the database as the input for the plugin?

Create a field

See how I access my dB and send values to my plugin