<h1>Listing Boards</h1>

<%= if @live_action in [:new, :edit] do %>
  <.modal return_to={Routes.board_index_path(@socket, :index)}>
    <.live_component
      module={CakeWeb.BoardLive.FormComponent}
      id={@board.id || :new}
      title={@page_title}
      action={@live_action}
      board={@board}
      return_to={Routes.board_index_path(@socket, :index)}
    />
  </.modal>
<% end %>

<table>
  <thead>
    <tr>
      <th>Name</th>
      <th>Stories</th>

      <th></th>
    </tr>
  </thead>
  <tbody id="boards">
    <%= for board <- @boards do %>
      <tr id={"board-#{board.id}"}>
        <td><%= board.name %></td>
        <td><%= board.stories %></td>

        <td>
          <span><%= live_redirect "Show", to: Routes.board_show_path(@socket, :show, board) %></span>
          <span><%= live_patch "Edit", to: Routes.board_index_path(@socket, :edit, board) %></span>
          <span><%= link "Delete", to: "#", phx_click: "delete", phx_value_id: board.id, data: [confirm: "Are you sure?"] %></span>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>

<span><%= live_patch "New Board", to: Routes.board_index_path(@socket, :new) %></span>