"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/context/use-context-system.js
var use_context_system_exports = {};
__export(use_context_system_exports, {
  useContextSystem: () => useContextSystem
});
module.exports = __toCommonJS(use_context_system_exports);
var import_warning = __toESM(require("@wordpress/warning"), 1);
var import_context_system_provider = require("./context-system-provider.cjs");
var import_utils = require("./utils.cjs");
var import_get_styled_class_name_from_key = require("./get-styled-class-name-from-key.cjs");
var import_use_cx = require("../utils/hooks/use-cx.cjs");
function useContextSystem(props, namespace) {
  const contextSystemProps = (0, import_context_system_provider.useComponentsContext)();
  if (typeof namespace === "undefined") {
    globalThis.SCRIPT_DEBUG === true ? (0, import_warning.default)("useContextSystem: Please provide a namespace") : void 0;
  }
  const contextProps = contextSystemProps?.[namespace] || {};
  const finalComponentProps = {
    ...(0, import_utils.getConnectedNamespace)(),
    ...(0, import_utils.getNamespace)(namespace)
  };
  const {
    _overrides: overrideProps,
    ...otherContextProps
  } = contextProps;
  const initialMergedProps = Object.entries(otherContextProps).length ? Object.assign({}, otherContextProps, props) : props;
  const cx = (0, import_use_cx.useCx)();
  const classes = cx((0, import_get_styled_class_name_from_key.getStyledClassNameFromKey)(namespace), props.className);
  const rendered = typeof initialMergedProps.renderChildren === "function" ? initialMergedProps.renderChildren(initialMergedProps) : initialMergedProps.children;
  for (const key in initialMergedProps) {
    finalComponentProps[key] = initialMergedProps[key];
  }
  for (const key in overrideProps) {
    finalComponentProps[key] = overrideProps[key];
  }
  if (rendered !== void 0) {
    finalComponentProps.children = rendered;
  }
  finalComponentProps.className = classes;
  return finalComponentProps;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useContextSystem
});
//# sourceMappingURL=use-context-system.cjs.map
