import { resolveHandleToDid, loadCurrentUser, loadWalks } from "@/data/queries";
import { EmptyState } from "../../../EmptyState";
import { HomeWalkingList } from "../../../(home)/walking/HomeWalkingList";

export default async function ProfileWalkingPage({
  params,
}: {
  params: Promise<{ handle: string }>;
}) {
  const { handle: rawHandle } = await params;
  const handle = decodeURIComponent(rawHandle).replace(/^@/, "");
  const [userDid, currentUser] = await Promise.all([resolveHandleToDid(handle), loadCurrentUser()]);

  const walks = await loadWalks(userDid);

  if (walks.length === 0) {
    const isOwnProfile = currentUser?.did === userDid;
    const message = isOwnProfile
      ? "you're not walking any trails right now"
      : `@${handle} is not walking any trails right now`;
    return <EmptyState message={message} />;
  }

  const isOwnProfile = currentUser?.did === userDid;

  return <HomeWalkingList walks={walks} canDelete={isOwnProfile} />;
}
