"use server";
import { Suspense } from "react";
import { retrieveHeadersAndValidationByEndpoint } from "@/apicalls/validations/validations";
import { createBuild } from "@/apicalls/building/build";
import CreatePageComponent from "@/components/commons/CreatePage";

export default async function BuildingCreatePage() {
  const endpointUrl = "/building/build/create";
  const validateAndHeaders = await retrieveHeadersAndValidationByEndpoint({
    endpoint: endpointUrl,
  });
  const validator = validateAndHeaders?.validated || {};
  const headers = validateAndHeaders?.headers || {};
  return (
    <div>
      <Suspense fallback={<div>Loading Create Page...</div>}>
        <h1>Create Building</h1>
        <CreatePageComponent
          validator={validator}
          headers={headers}
          saveFunction={createBuild}
          pageToReturn="/building"
        />
      </Suspense>
    </div>
  );
}
