# check out https://solara.dev/ for documentation
# or https://github.com/widgetti/solara/
# And check out https://py.cafe/maartenbreddels for more examples
import solara
# reactive variables will trigger a component rerender
# when changed.
# When you change the default (now 0), hit the embedded browser
# refresh button to reset the state
clicks = solara.reactive(0)
# initialize as 0, reactive() is a "響應式"的變化
# 有點像js, 但是讓你用pythonx來做
@solara.component # 把solor裝飾成component的樣子
def Page(): # 定義資個頁面
    print("The component render function gets called")
    # change this code, and see the output refresh
    color = "green"
    if clicks.value >= 3: # 當點>5次時,按鈕變成綠色
        color = "red"
    def increment():
        clicks.value += 1
        print("clicks", clicks)  # noqa
    solara.Button(label=f"Clicked: {clicks}", on_click=increment, color=color)
    # on_click "監聽" 你button的值是否有改變
# Solara also supports ipywidgets
# remove the Page component and assign an ipywidget to
# the page variable, e.g.
# page = mywidget