"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";
function booleanOverrideSelectValue(value) {
  return value === true || value === "true" ? "true" : "false";
}
function OverrideValueField(props) {
  const t = useT();
  const toggleType = props.values?.toggleType;
  const isOverride = props.values?.isOverride;
  if (!isOverride) {
    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.override.disabled", "Override is disabled. Values will be inherited from the default configuration.") });
  }
  switch (toggleType) {
    case "boolean":
      return /* @__PURE__ */ jsxs("div", { children: [
        /* @__PURE__ */ jsx("label", { className: "block text-sm font-medium mb-2", children: t("feature_toggles.override.fields.value.boolean.label", "Override 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.override.fields.value.string.label", "Override Value (String)") }),
        /* @__PURE__ */ jsx(
          Input,
          {
            type: "text",
            value: props.value || "",
            onChange: (e) => props.setValue(e.target.value),
            placeholder: t("feature_toggles.override.fields.value.string.placeholder", "Enter override 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.override.fields.value.number.label", "Override 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.override.fields.value.json.label", "Override 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.override.unknownType", "Unknown toggle type. Cannot configure override value.") });
  }
}
function createOverrideFieldDefinitions(t) {
  return [
    {
      id: "isOverride",
      label: t("feature_toggles.override.fields.isOverride.label"),
      type: "checkbox",
      required: false,
      description: t("feature_toggles.override.fields.isOverride.description")
    },
    {
      id: "overrideValue",
      label: "",
      type: "custom",
      component: (props) => /* @__PURE__ */ jsx(OverrideValueField, { ...props }),
      description: t("feature_toggles.override.fields.overrideValue.description")
    }
  ];
}
function createOverrideFormGroups(t) {
  return [
    {
      id: "overrideMode",
      title: t("feature_toggles.override.groups.mode"),
      column: 1,
      fields: ["isOverride"]
    },
    {
      id: "overrideValue",
      title: t("feature_toggles.override.groups.value"),
      column: 1,
      fields: ["overrideValue"]
    }
  ];
}
export {
  OverrideValueField,
  booleanOverrideSelectValue,
  createOverrideFieldDefinitions,
  createOverrideFormGroups
};
//# sourceMappingURL=overrideFormConfig.js.map
