import { router } from 'expo-router'
import type { Status } from 'src/lib/api-types'

/**
 * Open the modal compose surface pre-targeted at a reply to `target`.
 *
 * Every "Reply" affordance in the app routes through this — the post-detail
 * anchor `message-circle` icon, the per-CommentItem text label, the
 * `EventDetailView` / `ArticleDetailView` comments link. One seam, one
 * route, one composer.
 *
 * The signature takes a `Status` rather than a string id so the helper can
 * evolve the route shape (e.g. add `presentation: 'modal'` route group,
 * pre-gate replies on locked Mastodon accounts before the keyboard opens)
 * without hunting through every call site. Today every call site already
 * has the row data in scope.
 *
 * Note: for the FeedPost message-icon on Home / Profile / Search where the
 * comments aren't visible inline, the existing behaviour of pushing
 * `/post/[id]` is preserved upstream of this helper — only call this when
 * the intent is *immediately* to compose a reply, not "I want to see the
 * conversation". P3+ wires this on the detail screen specifically.
 */
export function pushReplyComposer(target: Status | null | undefined): void {
  if (!target?.id) return
  // Match the existing quote-push template-string convention at
  // `FeedPost.tsx:804` (`router.push(\`/camera?quotedStatusId=${post.id}\`)`)
  // so a single `rg '/camera?'` finds every entry point.
  router.push(`/camera?inReplyToId=${target.id}`)
}
