from dataclasses import dataclass
from typing import Any

from fasthtml import serve
from fasthtml.components import *

from myfasthtml.controls.helpers import mk
from myfasthtml.core.bindings import Binding
from myfasthtml.core.utils import debug_routes
from myfasthtml.myfastapp import create_app

app, rt = create_app(protect_routes=False)


@dataclass
class Data:
  value: Any = "Hello World"


data = Data(50)


@rt("/")
def get():
  range_elt = Input(
    type="range",
    name="range_name",
    min="0",
    max="100",
    value="50"
  )
  label_elt = Label()
  mk.manage_binding(range_elt, Binding(data))
  mk.manage_binding(label_elt, Binding(data))
  return range_elt, label_elt


if __name__ == "__main__":
  debug_routes(app)
  serve(port=5002)
