defmodule WildWeb.BookThoughts do
  use WildWeb, :live_view

  def render(assigns) do
    ~H"""
    <div class="mx-auto">
      <.header class="text-center">
        Write your thoughts for a book or a series of books
        <:subtitle>
        Share your thoughts and suggestion on the book that you just read
        </:subtitle>
      </.header>

      <.simple_form for={@form} id="login_form" action={~p"/account/log_in"} phx-update="ignore">
        <.input field={@form[:email]} type="text" label="Book Title" required />
        <.input field={@form[:password]} type="number" label="Publication Year" required />
        <.input field={@form[:password]} type="range" label="Rating" required />

        <:actions>
          <.input field={@form[:remember_me]} type="checkbox" label="Keep me logged in" />
          <.link href={~p"/account/reset_password"} class="text-sm font-semibold">
            Forgot your password?
          </.link>
        </:actions>
        <:actions>
          <.button phx-disable-with="Logging in..." class="w-full">
            Log in <span aria-hidden="true">→</span>
          </.button>
        </:actions>
      </.simple_form>
    </div>
    """
  end

  def mount(_params, _session, socket) do
    email = Phoenix.Flash.get(socket.assigns.flash, :email)
    form = to_form(%{"email" => email}, as: "user")
    {:ok, assign(socket, form: form), temporary_assigns: [form: form]}
  end

end
