import { Post } from "@/types/types";

const KEY_PREFIX = "reels-seed-post-";

export function cacheReelsSeedPost(post: Post): void {
  if (typeof window === "undefined") return;
  try {
    sessionStorage.setItem(`${KEY_PREFIX}${post._id}`, JSON.stringify(post));
  } catch {
    /* ignore quota errors */
  }
}

export function readReelsSeedPost(id: string): Post | null {
  if (typeof window === "undefined") return null;
  try {
    const raw = sessionStorage.getItem(`${KEY_PREFIX}${id}`);
    if (!raw) return null;
    return JSON.parse(raw) as Post;
  } catch {
    return null;
  }
}
