Tab component - Creating an interactive behavior with variables

I want to create an interactive tab navigation component, but I don’t know if can do that in Figma yet.
I know that we can create this the old way, but I want to use variables because it could be applied to more complex scenarios with more than 10 options.

I have 3 tabs linked to 3 pages. CAT, DOG and FOX.
Here we have 2 tabs opened.

Then if I click on the FOX button (imagine that part), I get this

I want to close the DOG tab, after doing that I get this

No problems up to this point. But what if I want to open the DOG tab again? It should be placed to the right side of the last tab, in this case, the FOX tab, like this

Have any of you ever created something like this?

Thank you