MZ [Solved] Question about Nested Choices via JS

I have a wardrobe that I want the player to pick items from. The wardrobe is a dictionary, and the choices offered to the player should be nested. I.e.: "Pants > Jeans" or "Top > Tee".

I do get the first level working, but then the messaging system stops reacting. I somewhat understand that this due to how the external JS is interpreted by RPGM. I know I can do nested selection using Event's UI, I wrote a post below explaining why this is not an option.

Here is my code. Could somebody please kindly help with RPGM's API - how can I do a nested selection using JS? I am failing even at showing a message after the selection has been made.

JavaScript:
//This is a dictionary with the 2-level nested choice
my_wardrobe = {
    "Pants"    :    ["Jeans", "Shorts"],
    "Top"    :    ["Shirt", "Tee"]
};

//This is the callback function factored out
function on_wardropbe_selection(items, selection){
    message = `Selected: ${items[selection]}`
    console.log(message)
 
    //$gameMessage.newPage();
    $gameMessage.add(message);
}

//This function displays selection prompt
(function() {
    offer_choice = function(message, my_items) {    
        const items = my_items
        $gameMessage.add(message)
        $gameMessage.setChoices(items, 0, -1)
        $gameMessage.setChoiceBackground(0);
        $gameMessage.setChoicePositionType(2)
        $gameMessage.setChoiceCallback(function(selection) {
            on_wardropbe_selection(items, selection)
        });  
    }
})();

//This takes dictionary's keys and turns them into 1st level selection prompt
function chose_from_dictionary(message, my_dict){
    offer_choice(message, Object.keys(my_dict))
}

//This takes dictionary's values and turns them into arrays
function chose_from_array(my_array){
    offer_choice(message, my_array)
}

//Function called from an event via Script: my_wardrobe_menu()
(function() {
    my_wardrobe_menu = function() {    
        chose_from_dictionary("Wardrobe choices?", my_wardrobe)
    }
})();

Thank you.

PS I saw a similar post asking for help, yet it was unsolved: link
I.e. below is an example of nested choice that I am trying to accomplish vis JS. Reason I need JS over event's UI is that my game is a "trainer" with 50 items of wardrobe per category. It is simply unwieldy to setup a wardrobe using Event's UI.

Code:
◆Show Choices:Pants, Top (Window, Right, #1, #2)
:When Pants
  ◆Show Choices:Jeans, Shorts (Window, Right, #1, #2)
  :When Jeans
    ◆
  :When Shorts
    ◆
  :End
  ◆
:When Top
  ◆Show Choices:Shirt, Tee (Window, Right, #1, #2)
  :When Shirt
    ◆
  :When Tee
    ◆
  :End
  ◆
:End

Example.png
One candidate for solution that I see is looping JS's query while maintaining where in the nested selection the player is, like this, with all proper loop breaks, etc:

Candidate.png


But Jesus, I hope there is a better way.
So, I managed to get a nested selection going using event's loop:

01.png


And the in-game result:

Spoiler: Screenshots
02.png
03.png

But if anyone knows a JS-only solution, avoiding the need for an event loop, please let me know. Thank you.
Illustration of the JS-based nested-selection wardrobe system:

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-question-about-nested-choices-via-js.140230/