import * as feedDefs from "@/lib/lexicons/app/bsky/feed/defs";

export type BlueskyPost = feedDefs.ThreadViewPost;

export function blueskyUrlToAtUri(url: string): string | null {
  try {
    const urlObj = new URL(url);
    const pathParts = urlObj.pathname.split("/").filter(Boolean);
    if (pathParts[0] === "profile" && pathParts[2] === "post" && pathParts.length >= 4) {
      return `at://${pathParts[1]}/app.bsky.feed.post/${pathParts[3]}`;
    }
    return null;
  } catch {
    return null;
  }
}
