"use client";
import { jsx, jsxs } from "react/jsx-runtime";
import { JsonBuilder } from "@open-mercato/ui/backend/JsonBuilder";
import { Input } from "@open-mercato/ui/primitives/input";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue
} from "@open-mercato/ui/primitives/select";
import { useT } from "@open-mercato/shared/lib/i18n/context";
import { booleanOverrideSelectValue } from "./overrideFormConfig.js";
function DefaultValueField(props) {
  const t = useT();
  const selectedType = props.values?.type;
  switch (selectedType) {
    case "boolean":
      return /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium mb-2", children: t("feature_toggles.form.fields.defaultValue.boolean.label", "Default Value (Boolean)") }),
        /* @__PURE__ */ jsxs(
          Select,
          {
            value: booleanOverrideSelectValue(props.value),
            onValueChange: (value) => props.setValue(value === "true"),
            disabled: props.disabled,
            children: [
              /* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, {}) }),
              /* @__PURE__ */ jsxs(SelectContent, { children: [
                /* @__PURE__ */ jsx(SelectItem, { value: "true", children: t("feature_toggles.values.true", "True") }),
                /* @__PURE__ */ jsx(SelectItem, { value: "false", children: t("feature_toggles.values.false", "False") })
              ] })
            ]
          }
        )
      ] });
    case "string":
      return /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium mb-2", children: t("feature_toggles.form.fields.defaultValue.string.label", "Default Value (String)") }),
        /* @__PURE__ */ jsx(
          Input,
          {
            type: "text",
            value: props.value || "",
            onChange: (e) => props.setValue(e.target.value),
            placeholder: t("feature_toggles.form.fields.defaultValue.string.placeholder", "Enter default string value"),
            disabled: props.disabled,
            autoFocus: props.autoFocus
          }
        )
      ] });
    case "number":
      return /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium mb-2", children: t("feature_toggles.form.fields.defaultValue.number.label", "Default Value (Number)") }),
        /* @__PURE__ */ jsx(
          Input,
          {
            type: "number",
            value: props.value || 0,
            onChange: (e) => props.setValue(Number(e.target.value) || 0),
            disabled: props.disabled,
            autoFocus: props.autoFocus
          }
        )
      ] });
    case "json":
      return /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium mb-2", children: t("feature_toggles.form.fields.defaultValue.json.label", "Default Value (JSON)") }),
        /* @__PURE__ */ jsx(
          JsonBuilder,
          {
            value: props.value,
            onChange: props.setValue,
            disabled: props.disabled
          }
        )
      ] });
    default:
      return /* @__PURE__ */ jsx("div", { className: "text-sm text-muted-foreground p-4 text-center bg-muted/30 rounded border border-dashed", children: t("feature_toggles.form.fields.defaultValue.selectType", "Please select a type above to configure the default value") });
  }
}
function createFieldDefinitions(t) {
  return [
    {
      id: "identifier",
      label: t("feature_toggles.form.fields.identifier.label"),
      type: "text",
      required: true
    },
    {
      id: "name",
      label: t("feature_toggles.form.fields.name.label"),
      type: "text",
      required: true
    },
    {
      id: "description",
      label: t("feature_toggles.form.fields.description.label"),
      type: "textarea",
      required: false
    },
    {
      id: "category",
      label: t("feature_toggles.form.fields.category.label"),
      type: "text",
      required: false
    },
    {
      id: "type",
      label: t("feature_toggles.form.fields.type.label"),
      type: "select",
      required: true,
      options: [
        { label: t("feature_toggles.types.boolean"), value: "boolean" },
        { label: t("feature_toggles.types.string"), value: "string" },
        { label: t("feature_toggles.types.number"), value: "number" },
        { label: t("feature_toggles.types.json"), value: "json" }
      ]
    },
    {
      id: "defaultValue",
      label: "",
      type: "custom",
      component: (props) => /* @__PURE__ */ jsx(DefaultValueField, { ...props }),
      description: t("feature_toggles.form.fields.defaultValue.description")
    }
  ];
}
function createFormGroups(t) {
  return [
    {
      id: "basic",
      title: t("feature_toggles.form.groups.basic"),
      column: 1,
      fields: [
        "identifier",
        "name",
        "description",
        "category"
      ]
    },
    {
      id: "type",
      title: t("feature_toggles.form.groups.type"),
      column: 1,
      fields: ["type"]
    },
    {
      id: "defaultValue",
      title: t("feature_toggles.form.groups.defaultValue"),
      column: 1,
      fields: ["defaultValue"]
    }
  ];
}
export {
  DefaultValueField,
  createFieldDefinitions,
  createFormGroups
};
//# sourceMappingURL=formConfig.js.map
