import type { Metadata } from "next";
import fs from "fs/promises";
import path from "path";
import { auth } from "../../../auth";
import { VodicClient } from "./VodicClient";

export const metadata: Metadata = {
  title: "Vodič kroz kuću",
  description: "Sve informacije o kući — oprema, pravila i savjeti.",
};

export type VodicContent = {
  sections: { icon: string; title: string; items: string[] }[];
  contactsTitle: string;
  contacts: { label: string; value: string }[];
};

export default async function VodicPage() {
  const raw = await fs.readFile(
    path.join(process.cwd(), "content", "pages", "vodic.json"),
    "utf-8"
  );
  const content: VodicContent = JSON.parse(raw);
  const session = await auth();
  const isAdmin = (session?.user as { role?: string })?.role === "admin";

  return <VodicClient initialContent={content} isAdmin={isAdmin} />;
}
