import { jsx, jsxs } from "react/jsx-runtime";
import { cx } from "@emotion/css";
import {
  forwardRef,
  useRef,
  useImperativeHandle
} from "react";
import { useStyle } from "../../../../../../../../../runtimes/react/use-style";
import Label from "../../../Label";
import RadioButton from "../../../RadioButton";
function StyledLabel({ className, ...restOfProps }) {
  return /* @__PURE__ */ jsx(
    Label,
    {
      ...restOfProps,
      className: cx(
        useStyle({
          display: "flex",
          alignItems: "center",
          margin: "8px 0",
          "&:last-of-type": {
            marginBottom: 0
          }
        }),
        className
      )
    }
  );
}
function RadioButtonContainer({ className, ...restOfProps }) {
  return /* @__PURE__ */ jsx("span", { ...restOfProps, className: cx(useStyle({ marginRight: 8 }), className) });
}
var TableColumnRadioButtonGroup_default = forwardRef(function TableColumnRadioButtonGroup({
  tableColumn,
  label = "",
  value = "",
  required = false,
  hideLabel = false,
  onChange,
  ...restOfProps
}, ref) {
  const handle = useRef({
    validity: { valueMissing: required === true && value === "", typeMismatch: false }
  });
  useImperativeHandle(ref, () => handle.current, []);
  function handleChange(event) {
    handle.current.validity.valueMissing = required === true && !event.currentTarget.checked;
    onChange(event);
  }
  return /* @__PURE__ */ jsxs("div", { children: [
    !hideLabel && /* @__PURE__ */ jsx(Label, { as: "p", children: label }),
    tableColumn.options.map((option) => /* @__PURE__ */ jsxs(StyledLabel, { htmlFor: option.id, "aria-label": label, children: [
      /* @__PURE__ */ jsx(RadioButtonContainer, { children: /* @__PURE__ */ jsx(
        RadioButton,
        {
          ...restOfProps,
          onChange: handleChange,
          checked: value === option.name,
          id: option.id,
          value: option.name
        }
      ) }),
      option.name
    ] }, option.id))
  ] });
});
export {
  TableColumnRadioButtonGroup_default as default
};
//# sourceMappingURL=index.js.map