"use client";

import type { CommunityPostRecord } from "@/features/community/communityRecord";
import React from "react";

import { useInnerPost } from "./useInnerPost";
import InnerPostModals from "./InnerPostModals";
import InnerPostCard from "./InnerPostCard";

/**
 * `InnerPost`'s props: one community post plus the list's refetch.
 *
 * `data` is `CommunityPostRecord` — the transcription of
 * `WebsitePostResource` — rather than the inline shape this used to declare,
 * which disagreed with the resource on five points. Three of them were
 * primitive-level: `id`, `user.id` and `post_images[].id` were `string` where
 * the resource emits `$post->id` and friends as **numbers**. The rest were
 * nullability: `title_*` / `idea_text_*` / `nickname` / `user.profile_pic` are
 * all nullable columns, and `user` itself is `?array`.
 */
export interface PostData {
  data: CommunityPostRecord;
  refetch: () => void;
}

function InnerPost({ data, refetch }: PostData) {
  const screen = useInnerPost({ data, refetch });

  return (
    <div>
      <InnerPostModals screen={screen} data={data} refetch={refetch} />

      <InnerPostCard screen={screen} data={data} />
    </div>
  );
}

export default InnerPost;
