"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/components/src/tree-select/index.tsx
var tree_select_exports = {};
__export(tree_select_exports, {
  TreeSelect: () => TreeSelect,
  default: () => tree_select_default
});
module.exports = __toCommonJS(tree_select_exports);
var import_element = require("@wordpress/element");
var import_html_entities = require("@wordpress/html-entities");
var import_select_control = require("../select-control/index.cjs");
var import_use_deprecated_props = require("../utils/use-deprecated-props.cjs");
var import_deprecated_36px_size = require("../utils/deprecated-36px-size.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
function getSelectOptions(tree, level = 0) {
  return tree.flatMap((treeNode) => [{
    value: treeNode.id,
    label: "\xA0".repeat(level * 3) + (0, import_html_entities.decodeEntities)(treeNode.name)
  }, ...getSelectOptions(treeNode.children || [], level + 1)]);
}
function TreeSelect(props) {
  const {
    __nextHasNoMarginBottom: _,
    // Prevent passing to internal component
    label,
    noOptionLabel,
    onChange,
    selectedId,
    tree = [],
    ...restProps
  } = (0, import_use_deprecated_props.useDeprecated36pxDefaultSizeProp)(props);
  const options = (0, import_element.useMemo)(() => {
    return [noOptionLabel && {
      value: "",
      label: noOptionLabel
    }, ...getSelectOptions(tree)].filter((option) => !!option);
  }, [noOptionLabel, tree]);
  (0, import_deprecated_36px_size.maybeWarnDeprecated36pxSize)({
    componentName: "TreeSelect",
    size: restProps.size,
    __next40pxDefaultSize: restProps.__next40pxDefaultSize
  });
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_select_control.SelectControl, {
    __shouldNotWarnDeprecated36pxSize: true,
    label,
    options,
    onChange,
    value: selectedId,
    ...restProps
  });
}
var tree_select_default = TreeSelect;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  TreeSelect
});
//# sourceMappingURL=index.cjs.map
