<gh_stars>0
import os
import sys
from typing import Collection, Union

from dash import dcc as core
from dash import html
from dash.dependencies import Input, Output, State
from dash.development.base_component import Component

from retronas_webgui.app import (
    app,
    children,
    cls,
    page_content,
    pathname,
    root,
    settings,
    url,
    url_hash,
)
from retronas_webgui.components import header, nav
from retronas_webgui.helpers.configs import retronas_cfg
from retronas_webgui.pages import NAV_DEF, status

layout = html.Div(
    [
        # URL object, renders nothing
        core.Location(id=url, refresh=False),
        header.layout,
        nav.layout,
        core.Markdown("## ❔ root access", id="pw-status", className="rn-content"),
        # Content target
        html.Div(id=page_content, className="rn-content"),
    ],
    id=root,
    className=root,
)


def get_ip():
    """
    Currently unused
    """
    try:
        if sys.argv[1]:
            return sys.argv[1]
    except IndexError:
        return "localhost"


def index():
    @app.callback(
        [Output(page_content, children), Output(page_content, cls), Output(url, url_hash)],
        Input(url, pathname),
        State(url, url_hash),
    )
    def display_page(path: str, _: str) -> (Union[Component, Collection[Component]], str, str):
        for name, value in NAV_DEF.items():
            if path == value.href:
                return value.page.layout(), f"rn-content {value.page.name}", ""
        else:
            return status.layout(), f"rn-content {status.name}", ""


if __name__ == "__main__":
    if os.getuid() == 0:
        settings["root"] = True
    else:
        settings["root"] = False
    app.title = "RetroNAS"
    app.layout = layout
    index()
    for ip in retronas_cfg("MY_IPS"):
        app.run_server(debug=True, host=ip)

import os
import sys
from typing import Collection, Union

from dash import dcc as core
from dash import html
from dash.dependencies import Input, Output, State
from dash.development.base_component import Component

from retronas_webgui.app import (
    app,
    children,
    cls,
    page_content,
    pathname,
    root,
    settings,
    url,
    url_hash,
)
from retronas_webgui.components import header, nav
from retronas_webgui.helpers.configs import retronas_cfg
from retronas_webgui.pages import NAV_DEF, status

layout = html.Div(
    [
        # URL object, renders nothing
        core.Location(id=url, refresh=False),
        header.layout,
        nav.layout,
        core.Markdown("## ❔ root access", id="pw-status", className="rn-content"),
        # Content target
        html.Div(id=page_content, className="rn-content"),
    ],
    id=root,
    className=root,
)


def get_ip():
    """
    Currently unused
    """
    try:
        if sys.argv[1]:
            return sys.argv[1]
    except IndexError:
        return "localhost"


def index():
    @app.callback(
        [Output(page_content, children), Output(page_content, cls), Output(url, url_hash)],
        Input(url, pathname),
        State(url, url_hash),
    )
    def display_page(path: str, _: str) -> (Union[Component, Collection[Component]], str, str):
        for name, value in NAV_DEF.items():
            if path == value.href:
                return value.page.layout(), f"rn-content {value.page.name}", ""
        else:
            return status.layout(), f"rn-content {status.name}", ""


if __name__ == "__main__":
    if os.getuid() == 0:
        settings["root"] = True
    else:
        settings["root"] = False
    app.title = "RetroNAS"
    app.layout = layout
    index()
    for ip in retronas_cfg("MY_IPS"):
        app.run_server(debug=True, host=ip)
# URL object, renders nothing # ❔ root access", id="pw-status", className="rn-content"), # Content target Currently unused