I need help performing a procedure that returns screens using vertical arrangemets, can anyone help me?

I’m creating an app and I need to make it so that every time a certain vertical arrangement is clicked, one becomes visible and the other not, but when clicking the back button on the cell phone it returns to the previous screen, as well as the position of the navigation block.

I’m going to leave here the image of how far I managed to do this function using ChatGPT, although there is still an error in it.

This is the structure I received from ChatGPT:

// Define global variable to store arrangement history
set global historicalarrangement to create empty list

// Procedure to hide all arrangements
procedure hideAllArrangements
set Vertical_Arrangement1.Visible to false
set Vertical_Arrangement2.Visible to false
// Add all the arrangements you have here

// Example of changing arrangement and adding to history
when Button1.Clicked
add item to list (global historicalarrangement) item (Vertical_Arrangement1) // Assuming that Vertical_Arrangement1 is the current
set Vertical_Arrangement1.Visible to false
set Vertical_Arrangement2.Visible to true

// Device back button event
when Screen1.BackPressed
if (list length (globalHistoricalArrangement) > 0)
setCurrentArrangement to select item from list (globalHistoricalArrangement) index (length of list (globalHistoricalArrangement))
remove item from list (global historicarrangement) index (length of list (global historicarrangement))
call hideAllArrangements
setCurrentarray.Visible to true
if not
call Notifier.ShowAlert message “You are on the home screen”

Can anyone help me with this please