# Copyright 2026 Marimo. All rights reserved.

import marimo

__generated_with = "0.20.1"
app = marimo.App()


@app.cell
def _():
    import marimo as mo

    return (mo,)


@app.cell
def _():
    import time

    return (time,)


@app.cell
def _(mo, time):
    def loop_replace():
        for i in range(5):
            mo.output.replace(mo.md(f"Loading {i}/5"))
            time.sleep(.01)

    def loop_append():
        for i in range(5):
            mo.output.append(mo.md(f"Loading {i}/5"))
            time.sleep(.01)

    return loop_append, loop_replace


@app.cell
def _(mo):
    mo.md("""
    ### Replace
    """)
    return


@app.cell
def _(loop_replace, mo):
    loop_replace()
    mo.md("Done!")
    return


@app.cell
def _(loop_replace, mo):
    loop_replace()
    mo.output.replace(mo.md(f"Done"))
    return


@app.cell
def _(mo):
    mo.md("""
    ### Append
    """)
    return


@app.cell
def _(loop_append, mo):
    loop_append()
    mo.md("Done!")
    return


@app.cell
def _(loop_append, mo):
    loop_append()
    mo.output.append(mo.md("Done!"))
    return


@app.cell
def _(mo):
    mo.md("""
    ### Clear
    """)
    return


@app.cell
def _(loop_append, mo):
    loop_append()
    mo.output.append(mo.md("Done!"))
    mo.output.clear()
    return


@app.cell
def _(loop_append, mo):
    loop_append()
    mo.output.append(mo.md("Done!"))
    mo.output.replace(None)
    return


@app.cell
def _(mo):
    mo.md("""
    ### Sleep (stale)
    """)
    return


@app.cell
def _(time):
    time.sleep(2)
    "hello"
    return


@app.cell
def _(mo):
    mo.output.append(mo.md("To be replaced."))
    mo.output.replace_at_index(mo.md("Replaced at index"), 0)
    return


if __name__ == "__main__":
    app.run()
