"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/components/src/radio-control/index.tsx
var radio_control_exports = {};
__export(radio_control_exports, {
  RadioControl: () => RadioControl,
  default: () => radio_control_default
});
module.exports = __toCommonJS(radio_control_exports);
var import_clsx = __toESM(require("clsx"), 1);
var import_compose = require("@wordpress/compose");
var import_base_control = __toESM(require("../base-control/index.cjs"), 1);
var import_v_stack = require("../v-stack/index.cjs");
var import_base_control_styles = require("../base-control/styles/base-control-styles.cjs");
var import_visually_hidden = require("../visually-hidden/index.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
function generateOptionDescriptionId(radioGroupId, index) {
  return `${radioGroupId}-${index}-option-description`;
}
function generateOptionId(radioGroupId, index) {
  return `${radioGroupId}-${index}`;
}
function generateHelpId(radioGroupId) {
  return `${radioGroupId}__help`;
}
function RadioControl(props) {
  const {
    label,
    className,
    selected,
    help,
    onChange,
    onClick,
    hideLabelFromVision,
    options = [],
    id: preferredId,
    ...additionalProps
  } = props;
  const id = (0, import_compose.useInstanceId)(RadioControl, "inspector-radio-control", preferredId);
  const onChangeValue = (event) => onChange(event.target.value);
  if (!options?.length) {
    return null;
  }
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", {
    id,
    className: (0, import_clsx.default)(className, "components-radio-control"),
    "aria-describedby": !!help ? generateHelpId(id) : void 0,
    children: [hideLabelFromVision ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_visually_hidden.VisuallyHidden, {
      as: "legend",
      children: label
    }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_base_control.default.VisualLabel, {
      as: "legend",
      children: label
    }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_v_stack.VStack, {
      spacing: 3,
      className: (0, import_clsx.default)("components-radio-control__group-wrapper", {
        "has-help": !!help
      }),
      children: options.map((option, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
        className: "components-radio-control__option",
        children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
          id: generateOptionId(id, index),
          className: "components-radio-control__input",
          type: "radio",
          name: id,
          value: option.value,
          onChange: onChangeValue,
          checked: option.value === selected,
          "aria-describedby": !!option.description ? generateOptionDescriptionId(id, index) : void 0,
          onClick: (event) => {
            event.currentTarget.focus();
            onClick?.(event);
          },
          ...additionalProps
        }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
          className: "components-radio-control__label",
          htmlFor: generateOptionId(id, index),
          children: option.label
        }), !!option.description ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_base_control_styles.StyledHelp, {
          id: generateOptionDescriptionId(id, index),
          className: "components-radio-control__option-description",
          children: option.description
        }) : null]
      }, generateOptionId(id, index)))
    }), !!help && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_base_control_styles.StyledHelp, {
      id: generateHelpId(id),
      className: "components-base-control__help",
      children: help
    })]
  });
}
var radio_control_default = RadioControl;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  RadioControl
});
//# sourceMappingURL=index.cjs.map
