
    gQ-                        U d dl mZ d dlmZ d dlmZmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZmZ erd dlmZ d dlmZmZ eZded<   	 	 	 	 ddZddZ  ed      ddd	 	 	 	 	 	 	 dd       Z!y)    )annotations)Path)TYPE_CHECKINGLiteral)	TypeAlias)config)StreamlitAPIException)
ForwardMsg)
Navigation)gather_metrics)ScriptRunContextget_script_run_ctx)StreamlitPage)PageHashPageInfor   SectionHeaderc                d    g }| j                         D ]  }|D ]  }|j                  |         |S )N)valuesappend)nav_sections	page_listpagespages       R/var/www/openai/venv/lib/python3.12/site-packages/streamlit/commands/navigation.pypages_from_nav_sectionsr   '   s<     I$$&DT"  '     c                \    t               }d|j                  _        | j                  |       y )N )r
   page_not_found	page_nameenqueue)ctxmsgs     r   send_page_not_foundr$   2   s#    
,C#%C KKr   
navigationsidebarF)positionexpandedc                  t        | t              rd| in| }t        |      }|st        d      d}i }|D ](  }||   D ]  }|j                  s|t        d      |}  * ||d   }d|_        t               }	|	s	d|_        |S |D ]  }||   D ]  }t        |j                  t              rt        |j                        }
nd}
|j                  }||v rt        d|j                   d      ||j                  |j                  |
|j                  d	||<     t               }|d
k(  r*t        j                   j"                  |j$                  _        njt)        j*                  d      du r*t        j                   j"                  |j$                  _        n)t        j                   j,                  |j$                  _        ||j$                  _        |j1                         |j$                  j2                  dd |D ]  }||   D ]  }|j$                  j4                  j7                         }|j                  |_        |j                  |_        |j                  |_        |j                  |_        ||_        |j                  |_           |	jB                  jE                  |       |	jB                  jG                  |j                        }d}|r7|d   }|D cg c]  }|j                  |k(  s| }}tI        |      dkD  r|d   }|stK        |	       |}d|_        |j                  |j$                  _        |	jM                  |j                         |	jO                  |       |S c c}w )u  
    Configure the available pages in a multipage app.

    Call ``st.navigation`` in your entrypoint file with one or more pages
    defined by ``st.Page``. ``st.navigation`` returns the current page, which
    can be executed using ``.run()`` method.

    When using ``st.navigation``, your entrypoint file (the file passed to
    ``streamlit run``) acts like a router or frame of common elements around
    each of your pages. Streamlit executes the entrypoint file with every app
    rerun. To execute the current page, you must call the ``.run()`` method on
    the ``StreamlitPage`` object returned by ``st.navigation``.

    The set of available pages can be updated with each rerun for dynamic
    navigation. By default, ``st.navigation`` draws the available pages in the
    side navigation if there is more than one page. This behavior can be
    changed using the ``position`` keyword argument.

    As soon as any session of your app executes the ``st.navigation`` command,
    your app will ignore the ``pages/`` directory (across all sessions).

    Parameters
    ----------
    pages : list[StreamlitPage] or dict[str, list[StreamlitPage]]
        The available pages for the app.

        To create labeled sections or page groupings within the navigation
        menu, ``pages`` must be a dictionary. Each key is the label of a
        section and each value is the list of ``StreamlitPage`` objects for
        that section.

        To create a navigation menu with no sections or page groupings,
        ``pages`` must be a list of ``StreamlitPage`` objects.

        Use ``st.Page`` to create ``StreamlitPage`` objects.

    position : "sidebar" or "hidden"
        The position of the navigation menu. If ``position`` is ``"sidebar"``
        (default), the navigation widget appears at the top of the sidebar. If
        ``position`` is ``"hidden"``, the navigation widget is not displayed.

        If there is only one page in ``pages``, the navigation will be hidden
        for any value of ``position``.

    expanded : bool
        Whether the navigation menu should be expanded. If this is ``False``
        (default), the navigation menu will be collapsed and will include a
        button to view more options when there are too many pages to display.
        If this is ``True``, the navigation menu will always be expanded; no
        button to collapse the menu will be displayed.

        If ``st.navigation`` changes from ``expanded=True`` to
        ``expanded=False`` on a rerun, the menu will stay expanded and a
        collapse button will be displayed.

    Returns
    -------
    StreamlitPage
        The current page selected by the user.

    Examples
    --------
    The following examples show possible entrypoint files, which is the file
    you pass to ``streamlit run``. Your entrypoint file manages your app's
    navigation and serves as a router between pages.

    **Example 1: Use a callable or Python file as a page**

    You can declare pages from callables or file paths.

    ``page_1.py`` (in the same directory as your entrypoint file):

    >>> import streamlit as st
    >>>
    >>> st.title("Page 1")

    Your entrypoint file:

    >>> import streamlit as st
    >>>
    >>> def page_2():
    ...     st.title("Page 2")
    >>>
    >>> pg = st.navigation([st.Page("page_1.py"), st.Page(page_2)])
    >>> pg.run()

    .. output::
        https://doc-navigation-example-1.streamlit.app/
        height: 200px

    **Example 2: Group pages into sections**

    You can use a dictionary to create sections within your navigation menu. In
    the following example, each page is similar to Page 1 in Example 1, and all
    pages are in the same directory. However, you can use Python files from
    anywhere in your repository. For more information, see |st.Page|_.

    Directory structure:

    >>> your_repository/
    >>> ├── create_account.py
    >>> ├── learn.py
    >>> ├── manage_account.py
    >>> ├── streamlit_app.py
    >>> └── trial.py

    ``streamlit_app.py``:

    >>> import streamlit as st
    >>>
    >>> pages = {
    ...     "Your account": [
    ...         st.Page("create_account.py", title="Create your account"),
    ...         st.Page("manage_account.py", title="Manage your account"),
    ...     ],
    ...     "Resources": [
    ...         st.Page("learn.py", title="Learn about us"),
    ...         st.Page("trial.py", title="Try it out"),
    ...     ],
    ... }
    >>>
    >>> pg = st.navigation(pages)
    >>> pg.run()

    .. output::
        https://doc-navigation-example-2.streamlit.app/
        height: 300px

    **Example 3: Stateful widgets across multiple pages**

    Call widget functions in your entrypoint file when you want a widget to be
    stateful across pages. Assign keys to your common widgets and access their
    values through Session State within your pages.

    >>> import streamlit as st
    >>>
    >>> def page1():
    >>>     st.write(st.session_state.foo)
    >>>
    >>> def page2():
    >>>     st.write(st.session_state.bar)
    >>>
    >>> # Widgets shared by all the pages
    >>> st.sidebar.selectbox("Foo", ["A", "B", "C"], key="foo")
    >>> st.sidebar.checkbox("Bar", key="bar")
    >>>
    >>> pg = st.navigation([st.Page(page1), st.Page(page2)])
    >>> pg.run()

    .. output::
        https://doc-navigation-multipage-widgets.streamlit.app/
        height: 350px

    .. |st.Page| replace:: ``st.Page``
    .. _st.Page: https://docs.streamlit.io/develop/api-reference/navigation/st.page

    r   z;`st.navigation` must be called with at least one `st.Page`.NzUMultiple Pages specified with `default=True`. At most one Page can be set to default.r   Tz+Multiple Pages specified with URL pathname zl. URL pathnames must be unique. The url pathname may be inferred from the filename, callable name, or title.)page_script_hashr    iconscript_pathurl_pathnamehiddenzclient.showSidebarNavigationF)fallback_page_hashr*   )(
isinstancelistr   r	   _defaultr   _can_be_called_pager   str_script_hashurl_pathtitler+   r
   NavigationProtoPositionHIDDENr%   r'   r   
get_optionSIDEBARr(   keyssections	app_pagesaddr*   r    
is_defaultsection_headerr-   pages_manager	set_pagesget_page_scriptlenr$   set_mpa_v2_pager!   )r   r'   r(   r   r   default_pagepagehash_to_pageinforC   r   r"   r,   script_hashr#   p
found_pagepage_to_returnfound_page_script_hashmatching_pagess                     r   r%   r%   8   sM   H #-UD"9B;uL'5I#I
 	
 L57 ' 0D}}+/B   $ 1 '  | $

C '+# ' 0D$**d+!$**o ++K22 ,A$-- QK K  %0!ZZ		* $1 -! 1 '2 ,C8"1":":"A"A			9	:e	C"1":":"A"A"1":":"B"B&CNN!-!2!2!4CNNA& 0D((,,.A!%!2!2A**AKYYAF==AL-A!]]AN 1 '  45""22'44 3 J N!+,>!? 
 !ANN6L$LAy 	 
 ~"+A.NC % %)N!&4&A&ACNN#334 KK'
s   M'MN)r   z(dict[SectionHeader, list[StreamlitPage]]returnzlist[StreamlitPage])r"   r   )r   z>list[StreamlitPage] | dict[SectionHeader, list[StreamlitPage]]r'   zLiteral['sidebar', 'hidden']r(   boolrQ   r   )"
__future__r   pathlibr   typingr   r   typing_extensionsr   	streamlitr   streamlit.errorsr	   streamlit.proto.ForwardMsg_pb2r
   streamlit.proto.Navigation_pb2r   r9   streamlit.runtime.metrics_utilr   7streamlit.runtime.scriptrunner_utils.script_run_contextr   r   streamlit.navigation.pager   streamlit.source_utilr   r   r5   r   __annotations__r   r$   r%    r   r   <module>ra      s    #  ) '  2 5 H 9
 78y :  .7	NIN +N 	N
 N Nr   