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

export const metadata: Metadata = {
  title: "Okolina",
  description: "Restorani, kafići, pranje veša, parking i plaže u blizini.",
};

export type Place = {
  name: string;
  distance: string;
  note: string;
  phone?: string;
};

export type OkolinaContent = {
  restaurants: Place[];
  parking: Place[];
  laundry: Place[];
  beaches: Place[];
  shops: Place[];
};

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

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