"use client";

import { notFound, useParams, useRouter } from "next/navigation";
import ClientWorkspaceLayout from "@/features/client/client-workspace-layout";
import PropertyEditorForm from "@/features/client/property-editor/property-editor-form";

export default function ClientPropertyNewPage() {
  const { app } = useParams() as { app: string };
  const router = useRouter();
  if (app !== "client" && app !== "property") {
    notFound();
  }
  const listHref = `/${app}/properties`;

  return (
    <ClientWorkspaceLayout
      title="Add property"
      barDescription="Add basic property information; use the list for more details and maintenance charges."
    >
      {(ctx) => {
        if (ctx.moduleBlockedProperty) {
          return (
            <p className="rounded-md border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900">
              The Property module is not enabled for this organization.
            </p>
          );
        }
        return (
          <PropertyEditorForm
            ctx={ctx}
            editing={null}
            listHref={listHref}
            onCancel={() => router.push(listHref)}
            onSaved={() => router.push(listHref)}
          />
        );
      }}
    </ClientWorkspaceLayout>
  );
}
