import { jsx, jsxs } from 'react/jsx-runtime';
import { Field, FieldLabel, FieldContent, FieldError, FieldDescription } from './primitives/Field.js';
import { c as cn } from './utils-BJnb9o5c.js';

function SelectFieldWrapper({
  id,
  label,
  error,
  helpText,
  errorId,
  helpTextId,
  isDisabled,
  required,
  testIdPrefix,
  labelProps,
  className,
  children
}) {
  const hasField = !!(label || error || helpText);
  if (!hasField) {
    return (
      // relative contains Radix Select's visually-hidden form input (an
      // absolutely positioned sibling of the trigger); without a positioned
      // ancestor it resolves against the document and can inflate the page's
      // scroll height. The labeled path below is covered by Field (relative).
      /* @__PURE__ */ jsx(
        "div",
        {
          className: cn("relative", className),
          ...testIdPrefix ? { "data-testid": `${testIdPrefix}-select-container-wrapper` } : {},
          children
        }
      )
    );
  }
  return /* @__PURE__ */ jsxs(
    Field,
    {
      "data-disabled": isDisabled || void 0,
      "data-invalid": !!error || void 0,
      className,
      ...testIdPrefix ? { "data-testid": `${testIdPrefix}-select-container-wrapper` } : {},
      children: [
        label && /* @__PURE__ */ jsxs(
          FieldLabel,
          {
            htmlFor: id,
            ...labelProps,
            ...testIdPrefix ? { "data-testid": `${testIdPrefix}-input-label` } : {},
            children: [
              label,
              required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "text-destructive", children: "*" })
            ]
          }
        ),
        /* @__PURE__ */ jsxs(FieldContent, { children: [
          children,
          !!error && /* @__PURE__ */ jsx(
            FieldError,
            {
              id: errorId,
              ...testIdPrefix ? { "data-testid": `${testIdPrefix}-select-error` } : {},
              children: error
            }
          ),
          helpText && /* @__PURE__ */ jsx(
            FieldDescription,
            {
              id: helpTextId,
              ...testIdPrefix ? { "data-testid": `${testIdPrefix}-select-help-text` } : {},
              children: helpText
            }
          )
        ] })
      ]
    }
  );
}

export { SelectFieldWrapper as S };
//# sourceMappingURL=SelectFieldWrapper-D98IWsW5.js.map
