defmodule BerrypodWeb.Auth.Settings do
  use BerrypodWeb, :live_view

  alias Berrypod.Accounts

  # Confirm-email token: process it and redirect to admin settings
  @impl true
  def mount(%{"token" => token}, _session, socket) do
    socket =
      case Accounts.update_user_email(socket.assigns.current_scope.user, token) do
        {:ok, _user} ->
          put_flash(socket, :info, "Email changed successfully.")

        {:error, _} ->
          put_flash(socket, :error, "Email change link is invalid or it has expired.")
      end

    {:ok, redirect(socket, to: ~p"/admin/settings")}
  end

  # Main mount: just redirect — account settings live in admin now
  def mount(_params, _session, socket) do
    {:ok, redirect(socket, to: ~p"/admin/settings")}
  end

  @impl true
  def render(assigns) do
    ~H""
  end
end
