// src/hooks/useLabel/useLabel.tsx
import { useId, useRef } from "react";
function useLabel({
  id: providedId,
  label,
  "aria-label": ariaLabel,
  "aria-labelledby": ariaLabelledby,
  labelElementType = "label"
}) {
  let labelProps = {};
  let fieldProps = {};
  const hasWarnedAboutMissingLabels = useRef(false);
  const fallbackId = useId();
  const id = providedId || fallbackId;
  const labelId = useId();
  if (label) {
    ariaLabelledby = ariaLabelledby ? `${labelId} ${ariaLabelledby}` : labelId;
    labelProps = {
      id: labelId,
      htmlFor: labelElementType === "label" ? id : void 0
    };
  } else if (!ariaLabelledby && !ariaLabel && !hasWarnedAboutMissingLabels.current) {
    hasWarnedAboutMissingLabels.current = true;
    console.warn(
      "If you do not provide a visible label, you must specify an aria-label or aria-labelledby attribute for accessibility"
    );
  }
  fieldProps = {
    id,
    "aria-label": ariaLabel,
    "aria-labelledby": ariaLabelledby
  };
  return {
    labelProps,
    fieldProps
  };
}

export {
  useLabel
};
//# sourceMappingURL=chunk-YLEFK7S2.js.map
