"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/circular-option-picker/circular-option-picker.tsx
var circular_option_picker_exports = {};
__export(circular_option_picker_exports, {
  default: () => circular_option_picker_default
});
module.exports = __toCommonJS(circular_option_picker_exports);
var import_clsx = __toESM(require("clsx"), 1);
var import_compose = require("@wordpress/compose");
var import_i18n = require("@wordpress/i18n");
var import_element = require("@wordpress/element");
var import_circular_option_picker_context = require("./circular-option-picker-context.cjs");
var import_composite = require("../composite/index.cjs");
var import_circular_option_picker_option = require("./circular-option-picker-option.cjs");
var import_circular_option_picker_option_group = require("./circular-option-picker-option-group.cjs");
var import_circular_option_picker_actions = require("./circular-option-picker-actions.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
function ListboxCircularOptionPicker(props) {
  const {
    actions,
    options,
    baseId,
    className,
    loop = true,
    children,
    ...additionalProps
  } = props;
  const [activeId, setActiveId] = (0, import_element.useState)(void 0);
  const contextValue = (0, import_element.useMemo)(() => ({
    baseId,
    activeId,
    setActiveId
  }), [baseId, activeId, setActiveId]);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
    className,
    children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_circular_option_picker_context.CircularOptionPickerContext.Provider, {
      value: contextValue,
      children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_composite.Composite, {
        ...additionalProps,
        id: baseId,
        focusLoop: loop,
        rtl: (0, import_i18n.isRTL)(),
        role: "listbox",
        activeId,
        setActiveId,
        children: options
      }), children, actions]
    })
  });
}
function ButtonsCircularOptionPicker(props) {
  const {
    actions,
    options,
    children,
    baseId,
    ...additionalProps
  } = props;
  const contextValue = (0, import_element.useMemo)(() => ({
    baseId
  }), [baseId]);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
    ...additionalProps,
    role: "group",
    id: baseId,
    children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_circular_option_picker_context.CircularOptionPickerContext.Provider, {
      value: contextValue,
      children: [options, children, actions]
    })
  });
}
function CircularOptionPicker(props) {
  const {
    asButtons,
    actions: actionsProp,
    options: optionsProp,
    children,
    className,
    ...additionalProps
  } = props;
  const baseId = (0, import_compose.useInstanceId)(CircularOptionPicker, "components-circular-option-picker", additionalProps.id);
  const OptionPickerImplementation = asButtons ? ButtonsCircularOptionPicker : ListboxCircularOptionPicker;
  const actions = actionsProp ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
    className: "components-circular-option-picker__custom-clear-wrapper",
    children: actionsProp
  }) : void 0;
  const options = /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
    className: "components-circular-option-picker__swatches",
    children: optionsProp
  });
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(OptionPickerImplementation, {
    ...additionalProps,
    baseId,
    className: (0, import_clsx.default)("components-circular-option-picker", className),
    actions,
    options,
    children
  });
}
CircularOptionPicker.Option = import_circular_option_picker_option.Option;
CircularOptionPicker.OptionGroup = import_circular_option_picker_option_group.OptionGroup;
CircularOptionPicker.ButtonAction = import_circular_option_picker_actions.ButtonAction;
CircularOptionPicker.DropdownLinkAction = import_circular_option_picker_actions.DropdownLinkAction;
var circular_option_picker_default = CircularOptionPicker;
//# sourceMappingURL=circular-option-picker.cjs.map
