 defmodule JumubaseWeb.PerformanceLive.New do
   use Phoenix.LiveView
   alias Jumubase.Foundation
+  alias Jumubase.Foundation.{Contest, ContestCategory}
   alias Jumubase.Showtime
   alias Jumubase.Showtime.{Appearance, Performance}
 

    {:noreply, assign(socket, changeset: changeset)}
  end

  defp append_appearance(changeset) do
    existing_appearances = Map.get(changeset.changes, :appearances, [])

    appearances =
      existing_appearances
      |> Enum.concat([%Appearance{}])

    changeset
    |> Ecto.Changeset.put_assoc(:appearances, appearances)

     )}
  end

  def handle_event("change", %{"performance" => attrs, "_target" => target}, socket) do
    contest = socket.assigns.contest

    changeset =
      Performance.changeset(%Performance{}, attrs, contest.round)
      |> Map.put(:action, :insert)
      |> populate_appearances(target, contest)

    {:noreply, assign(socket, changeset: changeset)}
  end
