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

export const metadata: Metadata = {
  title: "Lokacija",
  description: "Gdje se nalazi naša kuća na moru i kako doći.",
};

export type LokacijaContent = {
  titles: { address: string; directions: string; parking: string };
  address: string;
  directions: string;
  parking: string;
  gps: Array<{ label: string; lat: string; lng: string }>;
  mapsEmbed: string;
};

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

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