import { jsx as r } from "react/jsx-runtime";
import { forwardRef as q } from "react";
import { s as h } from "./search.es-DoFKg2Hr.mjs";
import { T as v } from "./text-field-PKAaXO1N.mjs";
import { c as f } from "./bind-CU-R61T-.mjs";
import { c as _ } from "./button-DBX_tvfJ.mjs";
const N = {
  "purpur-search-field": "_purpur-search-field_uhpkq_1",
  "purpur-search-field--has-clear-button": "_purpur-search-field--has-clear-button_uhpkq_4",
  "purpur-search-field--no-gap": "_purpur-search-field--no-gap_uhpkq_13",
  "purpur-search-field__wrapper": "_purpur-search-field__wrapper_uhpkq_17",
  "purpur-search-field__wrapper--gap": "_purpur-search-field__wrapper--gap_uhpkq_20",
  "purpur-search-field__search-icon": "_purpur-search-field__search-icon_uhpkq_24",
  "purpur-search-field__close-icon": "_purpur-search-field__close-icon_uhpkq_24"
}, w = {
  "purpur-search-field-button": "_purpur-search-field-button_c16yo_1",
  "purpur-search-field-button--icon-only": "_purpur-search-field-button--icon-only_c16yo_1"
}, F = f.bind(w), d = "purpur-search-field-button", z = ({
  ["data-testid"]: a,
  disabled: p,
  iconOnly: c,
  label: e
}) => {
  const s = {
    className: F(d, {
      [`${d}--icon-only`]: c
    }),
    disabled: p,
    "data-testid": a
  };
  return c ? /* @__PURE__ */ r(_, { ...s, "aria-label": e, iconOnly: !0, size: "sm", type: "submit", variant: "primary", children: /* @__PURE__ */ r(h, { size: "xs" }) }) : /* @__PURE__ */ r(_, { ...s, size: "sm", type: "submit", variant: "primary", children: e });
}, R = ["button-attached", "no-button"], i = f.bind(N), u = "purpur-search-field", S = q(
  ({
    ["data-testid"]: a,
    className: p,
    clearButtonAriaLabel: c,
    disabled: e,
    iconOnlySearchButton: s,
    onClear: m,
    onSearch: b,
    searchButtonLabel: y,
    variant: n,
    formRef: $,
    ...t
  }, g) => {
    const l = (o) => a ? `${a}-${o}` : void 0, x = (typeof t.value == "number" ? t.value !== void 0 : t.value?.length) && !e && !t.readOnly && !t.loading, k = i(p, u, {
      [`${u}--no-gap`]: n === "button-attached",
      [`${u}--has-clear-button`]: x
    });
    return /* @__PURE__ */ r(
      "form",
      {
        ref: $,
        className: i(`${u}__wrapper`),
        "data-testid": a,
        onSubmit: (o) => {
          o.preventDefault(), b?.(o);
        },
        children: /* @__PURE__ */ r(
          v,
          {
            ref: g,
            className: k,
            clearButtonAriaLabel: c,
            disabled: e,
            onClear: m,
            startAdornment: s ? null : /* @__PURE__ */ r(h, { size: "xs", className: i(`${u}__search-icon`) }, "1"),
            afterField: n !== "no-button" ? /* @__PURE__ */ r(
              z,
              {
                disabled: e,
                iconOnly: s,
                label: y,
                "data-testid": l("button")
              }
            ) : null,
            "data-testid": l("text-field"),
            type: "search",
            ...t
          }
        )
      }
    );
  }
);
S.displayName = "SearchField";
export {
  S,
  R as s
};
//# sourceMappingURL=search-field-DH0xeW_J.mjs.map
