import { jsx, jsxs } from "react/jsx-runtime";
import { Input } from "@open-mercato/ui/primitives/input";
import { PasswordInput } from "@open-mercato/ui/primitives/password-input";
import {
  Select,
  SelectContent,
  SelectItem,
  SelectTrigger,
  SelectValue
} from "@open-mercato/ui/primitives/select";
import { SwitchField } from "@open-mercato/ui/primitives/switch-field";
import { Textarea } from "@open-mercato/ui/primitives/textarea";
function renderProviderFieldInput(opts) {
  const { field, value, onChange } = opts;
  const common = { id: field.key, "data-provider-setting": field.key };
  switch (field.type) {
    case "textarea":
      return /* @__PURE__ */ jsx(
        Textarea,
        {
          ...common,
          value: typeof value === "string" ? value : "",
          onChange: (evt) => onChange(evt.target.value),
          placeholder: field.placeholder
        }
      );
    case "number":
      return /* @__PURE__ */ jsx(
        Input,
        {
          ...common,
          type: "number",
          value: typeof value === "number" || typeof value === "string" ? String(value) : "",
          onChange: (evt) => onChange(evt.target.value === "" ? "" : Number(evt.target.value)),
          placeholder: field.placeholder
        }
      );
    case "boolean":
      return /* @__PURE__ */ jsx("div", { className: "py-1", children: /* @__PURE__ */ jsx(
        SwitchField,
        {
          id: field.key,
          label: field.placeholder ?? "",
          flip: true,
          checked: Boolean(value),
          onCheckedChange: (checked) => onChange(checked)
        }
      ) });
    case "select":
      return /* @__PURE__ */ jsxs(
        Select,
        {
          value: typeof value === "string" && value ? value : void 0,
          onValueChange: (next) => onChange(next ?? ""),
          children: [
            /* @__PURE__ */ jsx(SelectTrigger, { ...common, children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "\u2014" }) }),
            /* @__PURE__ */ jsx(SelectContent, { children: (field.options ?? []).map((opt) => /* @__PURE__ */ jsx(SelectItem, { value: opt.value, children: opt.label }, opt.value)) })
          ]
        }
      );
    case "secret":
      return /* @__PURE__ */ jsx(
        PasswordInput,
        {
          ...common,
          value: typeof value === "string" ? value : "",
          onChange: (evt) => onChange(evt.target.value),
          placeholder: field.placeholder
        }
      );
    case "url":
    case "text":
    default:
      return /* @__PURE__ */ jsx(
        Input,
        {
          ...common,
          type: field.type === "url" ? "url" : "text",
          value: typeof value === "string" ? value : "",
          onChange: (evt) => onChange(evt.target.value),
          placeholder: field.placeholder
        }
      );
  }
}
export {
  renderProviderFieldInput
};
//# sourceMappingURL=ProviderFieldInput.js.map
