You will just display each group based on the number in your custom state, so by default all your groups will be hidden and collapsed when hidden.
for example (to display the 1st group):
You will add a condition (custom state’s number = 1) → This element is visible
the same applies for all the groups.
Please let me know if you need me to show you more details