"use client";
import { jsx } from "react/jsx-runtime";
import { E } from "../../../../../../generated/entities.ids.generated.js";
import { Page, PageBody } from "@open-mercato/ui/backend/Page";
import { CrudForm } from "@open-mercato/ui/backend/CrudForm";
import { collectCustomFieldValues } from "@open-mercato/ui/backend/utils/customFieldValues";
import { createCrud } from "@open-mercato/ui/backend/utils/crud";
const fields = [
  { id: "name", label: "Name", type: "text", required: true, placeholder: "Tenant name" },
  { id: "isActive", label: "Active", type: "checkbox" }
];
const groups = [
  { id: "details", title: "Details", column: 1, fields: ["name", "isActive"] },
  { id: "custom", title: "Custom Data", column: 2, kind: "customFields" }
];
function CreateTenantPage() {
  return /* @__PURE__ */ jsx(Page, { children: /* @__PURE__ */ jsx(PageBody, { children: /* @__PURE__ */ jsx(
    CrudForm,
    {
      title: "Create Tenant",
      backHref: "/backend/directory/tenants",
      fields,
      groups,
      entityId: E.directory.tenant,
      initialValues: { name: "", isActive: true },
      submitLabel: "Create",
      cancelHref: "/backend/directory/tenants",
      successRedirect: "/backend/directory/tenants?flash=Tenant%20created&type=success",
      onSubmit: async (values) => {
        const customFields = collectCustomFieldValues(values);
        const payload = {
          name: values.name,
          isActive: values.isActive !== false
        };
        if (Object.keys(customFields).length > 0) {
          payload.customFields = customFields;
        }
        await createCrud("directory/tenants", payload);
      }
    }
  ) }) });
}
export {
  CreateTenantPage as default
};
//# sourceMappingURL=page.js.map
