import { json, LoaderFunctionArgs, MetaFunction } from "@remix-run/node";
import { useLoaderData } from "@remix-run/react";
import ThreadChatPage from "../components/thread/ThreadChatPage";

export const meta: MetaFunction = () => {
  const title = "گفتگو | ویترون";
  const description = "گفتگو با فروشندگان در ویترون";
  const imageUrl =
    "https://vitrownstatics.s3.ir-thr-at1.arvanstorage.ir/SVG-06.svg?versionId=";

  return [
    { title },
    { name: "description", content: description },
    { name: "robots", content: "noindex, nofollow" },

    // Open Graph
    { property: "og:type", content: "website" },
    { property: "og:title", content: title },
    { property: "og:description", content: description },
    { property: "og:image", content: imageUrl },
    { property: "og:site_name", content: "ویترون" },
    { property: "og:locale", content: "fa_IR" },

    // Twitter Card
    { name: "twitter:card", content: "summary_large_image" },
    { name: "twitter:title", content: title },
    { name: "twitter:description", content: description },
    { name: "twitter:image", content: imageUrl },
  ];
};

// Server-side loader
export async function loader({ params }: LoaderFunctionArgs) {
  const { threadId } = params;

  if (!threadId) {
    throw new Response("Thread ID is required", { status: 400 });
  }

  return json({ threadId });
}

export default function StoreChat() {
  const { threadId } = useLoaderData<typeof loader>();
  return <ThreadChatPage threadId={threadId} />;
}
