Create and delete pages dynamically

I am looking for a simple way to rename a page using streamlit and to eventually delete the page by clicking on a cross next to its name for example.
My goal is to build a ChatGPT like interface for learning.
How can I do that using streamlit?

import streamlit as st

# Data structure to store pages
pages = {}

def add_page(page_name):
    pages[page_name] = ""

def rename_page(old_name, new_name):
    if old_name in pages:
        pages[new_name] = pages.pop(old_name)

def delete_page(page_name):
    if page_name in pages:
        del pages[page_name]

# Streamlit app
def main():
    st.title("Page Management App")

    # Sidebar for adding new pages
    new_page_name = st.sidebar.text_input("New Page Name:")
    if st.sidebar.button("Add Page"):
        if new_page_name:

    # Main content to display and manage existing pages
    st.write("## Existing Pages")
    for page_name in pages:
        st.write(f"### {page_name}")

        # Input field to rename the page
        new_name = st.text_input(f"Rename {page_name} to:")
        if st.button(f"Rename {page_name}", key=f"rename_{page_name}"):
            if new_name:
                rename_page(page_name, new_name)

        # Button to delete the page
        if st.button(f"Delete {page_name}", key=f"delete_{page_name}"):

if __name__ == "__main__":