"use client";
import { jsx } from "react/jsx-runtime";
import { z } from "zod";
import {
  refineEffectiveDateRange,
  EFFECTIVE_DATE_RANGE_DEFAULT_MESSAGE,
  ruleTypeSchema
} from "../data/validators.js";
import {
  getEntityTypeSuggestions,
  getEventTypeSuggestions
} from "./utils/formHelpers.js";
const businessRuleFormSchema = z.object({
  ruleId: z.string().min(1, "Rule ID is required").max(50, "Rule ID must be 50 characters or less"),
  ruleName: z.string().min(1, "Rule name is required").max(200, "Rule name must be 200 characters or less"),
  description: z.string().max(5e3, "Description must be 5000 characters or less").optional().nullable(),
  ruleType: ruleTypeSchema,
  ruleCategory: z.string().max(50, "Category must be 50 characters or less").optional().nullable(),
  entityType: z.string().min(1, "Entity type is required").max(50, "Entity type must be 50 characters or less"),
  eventType: z.string().max(50, "Event type must be 50 characters or less").optional().nullable(),
  conditionExpression: z.any(),
  // Validated by custom validator
  successActions: z.array(z.any()).optional().nullable(),
  failureActions: z.array(z.any()).optional().nullable(),
  enabled: z.boolean(),
  priority: z.number().int().min(0).max(9999),
  version: z.number().int().min(1),
  effectiveFrom: z.string().optional().nullable(),
  effectiveTo: z.string().optional().nullable()
}).superRefine((data, ctx) => refineEffectiveDateRange(data, ctx, EFFECTIVE_DATE_RANGE_DEFAULT_MESSAGE));
function getRuleTypeOptions(t) {
  return [
    { label: t("business_rules.types.guard"), value: "GUARD" },
    { label: t("business_rules.types.validation"), value: "VALIDATION" },
    { label: t("business_rules.types.calculation"), value: "CALCULATION" },
    { label: t("business_rules.types.action"), value: "ACTION" },
    { label: t("business_rules.types.assignment"), value: "ASSIGNMENT" }
  ];
}
function createFieldDefinitions(t) {
  return [
    {
      id: "ruleId",
      label: t("business_rules.rules.form.ruleId"),
      type: "text",
      required: true,
      placeholder: t("business_rules.rules.form.placeholders.ruleId"),
      description: t("business_rules.rules.form.descriptions.ruleId")
    },
    {
      id: "ruleName",
      label: t("business_rules.rules.form.ruleName"),
      type: "text",
      required: true,
      placeholder: t("business_rules.rules.form.placeholders.ruleName")
    },
    {
      id: "description",
      label: t("business_rules.rules.form.description"),
      type: "textarea",
      placeholder: t("business_rules.rules.form.placeholders.description")
    },
    {
      id: "ruleType",
      label: t("business_rules.rules.form.ruleType"),
      type: "select",
      required: true,
      options: getRuleTypeOptions(t)
    },
    {
      id: "ruleCategory",
      label: t("business_rules.rules.form.ruleCategory"),
      type: "text",
      placeholder: t("business_rules.rules.form.placeholders.ruleCategory")
    },
    {
      id: "entityType",
      label: t("business_rules.rules.form.entityType"),
      type: "combobox",
      required: true,
      placeholder: t("business_rules.rules.form.placeholders.entityType"),
      suggestions: getEntityTypeSuggestions(),
      description: t("business_rules.rules.form.descriptions.entityType"),
      allowCustomValues: true
    },
    {
      id: "eventType",
      label: t("business_rules.rules.form.eventType"),
      type: "combobox",
      placeholder: t("business_rules.rules.form.placeholders.eventType"),
      suggestions: getEventTypeSuggestions(),
      description: t("business_rules.rules.form.descriptions.eventType"),
      allowCustomValues: true
    },
    {
      id: "priority",
      label: t("business_rules.rules.form.priority"),
      type: "number",
      required: true,
      placeholder: "100",
      description: t("business_rules.rules.form.descriptions.priority")
    },
    {
      id: "enabled",
      label: t("business_rules.rules.form.enabled"),
      type: "checkbox",
      description: t("business_rules.rules.form.descriptions.enabled")
    },
    {
      id: "version",
      label: t("business_rules.rules.form.version"),
      type: "number",
      required: true
    },
    {
      id: "effectiveFrom",
      label: t("business_rules.rules.form.effectiveFrom"),
      type: "date",
      description: t("business_rules.rules.form.descriptions.effectiveFrom")
    },
    {
      id: "effectiveTo",
      label: t("business_rules.rules.form.effectiveTo"),
      type: "date",
      description: t("business_rules.rules.form.descriptions.effectiveTo")
    }
  ];
}
function createFormGroups(t, ConditionBuilderComponent, ActionBuilderComponent) {
  const ConditionBuilderWrapper = (props) => {
    return /* @__PURE__ */ jsx(ConditionBuilderComponent, { value: props.value, onChangeAction: props.setValue, error: props.error, showJsonPreview: true });
  };
  const ActionBuilderWrapper = (props) => {
    return /* @__PURE__ */ jsx(ActionBuilderComponent, { value: props.value, onChange: props.setValue, error: props.error, showJsonPreview: true });
  };
  return [
    {
      id: "basic",
      title: t("business_rules.rules.form.basic.title"),
      column: 1,
      fields: [
        "ruleId",
        "ruleName",
        "description",
        "ruleType",
        "ruleCategory",
        "entityType",
        "eventType"
      ]
    },
    {
      id: "conditions",
      title: t("business_rules.rules.form.conditions.title"),
      column: 1,
      fields: [
        {
          id: "conditionExpression",
          label: "",
          type: "custom",
          component: ConditionBuilderWrapper,
          description: t("business_rules.rules.form.conditions.description")
        }
      ]
    },
    {
      id: "successActions",
      title: t("business_rules.rules.form.actions.title") + " - " + t("business_rules.rules.form.actions.success"),
      column: 1,
      fields: [
        {
          id: "successActions",
          label: "",
          type: "custom",
          component: ActionBuilderWrapper
        }
      ]
    },
    {
      id: "failureActions",
      title: t("business_rules.rules.form.actions.title") + " - " + t("business_rules.rules.form.actions.failure"),
      column: 1,
      fields: [
        {
          id: "failureActions",
          label: "",
          type: "custom",
          component: ActionBuilderWrapper
        }
      ]
    },
    {
      id: "metadata",
      title: t("business_rules.rules.form.metadata.title"),
      column: 2,
      fields: ["priority", "enabled", "version", "effectiveFrom", "effectiveTo"]
    }
  ];
}
const defaultFormValues = {
  enabled: true,
  priority: 100,
  version: 1,
  conditionExpression: null,
  successActions: null,
  failureActions: null
};
export {
  businessRuleFormSchema,
  createFieldDefinitions,
  createFormGroups,
  defaultFormValues,
  getRuleTypeOptions
};
//# sourceMappingURL=formConfig.js.map
