type Model =
    | Counter(Int)

fn getCount(m: Model): Int =
    match m {
    Counter(n) => n,
}

fn init(): Model = Counter(0)

type Msg =
    | Increment
    | Decrement
    | Reset

fn update(model: Model, msg: Msg): Model =
    match msg {
    Increment => Counter(getCount(model) + 1),
    Decrement => Counter(getCount(model) - 1),
    Reset => Counter(0),
}

fn view(model: Model): String = {
    let count = getCount(model)
    "<div class=\"counter\">" + "<h1>Lux Counter</h1>" + "<div class=\"display\">" + toString(count) + "</div>" + "<div class=\"buttons\">" + "<button onclick=\"dispatch('Decrement')\">-</button>" + "<button onclick=\"dispatch('Reset')\">Reset</button>" + "<button onclick=\"dispatch('Increment')\">+</button>" + "</div>" + "</div>"
}

fn luxInit(): Model = init()

fn luxUpdate(model: Model, msgName: String): Model =
    match msgName {
    "Increment" => update(model, Increment),
    "Decrement" => update(model, Decrement),
    "Reset" => update(model, Reset),
    _ => model,
}

fn luxView(model: Model): String = view(model)
