import {
  Combobox
} from "./chunk-VBRTC2VU.js";
import {
  require_dist
} from "./chunk-52KJSIHS.js";
import {
  __toESM
} from "./chunk-NBMM2TZK.js";

// src/components/inputs/attribute-value-input/attribute-value-input.tsx
var import_types = __toESM(require_dist(), 1);
import { Input, Select, Textarea } from "@medusajs/ui";
import { useTranslation } from "react-i18next";
import { jsx, jsxs } from "react/jsx-runtime";
var AttributeValueInput = ({
  type,
  value,
  onChange,
  availableValues = [],
  placeholder
}) => {
  const { t } = useTranslation();
  const ph = placeholder ?? t("products.create.attributes.valuePlaceholder");
  switch (type) {
    case import_types.AttributeType.MULTI_SELECT:
      return /* @__PURE__ */ jsx(
        Combobox,
        {
          value: Array.isArray(value) ? value : [],
          onChange: (val) => onChange(val ?? []),
          options: availableValues.map((v) => ({
            value: v.name,
            label: v.name
          })),
          placeholder: t("products.create.attributes.selectValues")
        }
      );
    case import_types.AttributeType.SINGLE_SELECT:
      return /* @__PURE__ */ jsxs(
        Select,
        {
          value: typeof value === "string" ? value : value?.[0] ?? "",
          onValueChange: onChange,
          children: [
            /* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(
              Select.Value,
              {
                placeholder: t("products.create.attributes.selectValuePlaceholder")
              }
            ) }),
            /* @__PURE__ */ jsx(Select.Content, { children: availableValues.map((v) => /* @__PURE__ */ jsx(Select.Item, { value: v.name, children: v.name }, v.id)) })
          ]
        }
      );
    case import_types.AttributeType.TOGGLE:
      return /* @__PURE__ */ jsxs(
        Select,
        {
          value: typeof value === "string" ? value : value?.[0] ?? "",
          onValueChange: onChange,
          children: [
            /* @__PURE__ */ jsx(Select.Trigger, { children: /* @__PURE__ */ jsx(
              Select.Value,
              {
                placeholder: t("products.create.attributes.selectValuePlaceholder")
              }
            ) }),
            /* @__PURE__ */ jsxs(Select.Content, { children: [
              /* @__PURE__ */ jsx(Select.Item, { value: "true", children: t("filters.radio.yes") }),
              /* @__PURE__ */ jsx(Select.Item, { value: "false", children: t("filters.radio.no") })
            ] })
          ]
        }
      );
    case import_types.AttributeType.TEXT:
      return /* @__PURE__ */ jsx(
        Textarea,
        {
          className: "bg-ui-bg-field-component hover:bg-ui-bg-field-component-hover",
          value: typeof value === "string" ? value : value?.[0] ?? "",
          onChange: (e) => onChange(e.target.value),
          placeholder: ph
        }
      );
    default:
      return /* @__PURE__ */ jsx(
        Input,
        {
          className: "bg-ui-bg-field-component hover:bg-ui-bg-field-component-hover",
          value: typeof value === "string" ? value : value?.[0] ?? "",
          onChange: (e) => onChange(e.target.value),
          placeholder: ph
        }
      );
  }
};

export {
  AttributeValueInput
};
