"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/input-control/input-base.tsx
var input_base_exports = {};
__export(input_base_exports, {
  default: () => input_base_default
});
module.exports = __toCommonJS(input_base_exports);
var import_compose = require("@wordpress/compose");
var import_element = require("@wordpress/element");
var import_backdrop = __toESM(require("./backdrop.cjs"), 1);
var import_label = __toESM(require("./label.cjs"), 1);
var import_input_control_styles = require("./styles/input-control-styles.cjs");
var import_context = require("../context/index.cjs");
var import_use_deprecated_props = require("../utils/use-deprecated-props.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
function useUniqueId(idProp) {
  const instanceId = (0, import_compose.useInstanceId)(InputBase);
  const id = `input-base-control-${instanceId}`;
  return idProp || id;
}
function getUIFlexProps(labelPosition) {
  const props = {};
  switch (labelPosition) {
    case "top":
      props.direction = "column";
      props.expanded = false;
      props.gap = 0;
      break;
    case "bottom":
      props.direction = "column-reverse";
      props.expanded = false;
      props.gap = 0;
      break;
    case "edge":
      props.justify = "space-between";
      break;
  }
  return props;
}
function InputBase(props, ref) {
  const {
    __next40pxDefaultSize,
    __unstableInputWidth,
    children,
    className,
    disabled = false,
    hideLabelFromVision = false,
    labelPosition,
    id: idProp,
    isBorderless = false,
    label,
    prefix,
    size = "default",
    suffix,
    ...restProps
  } = (0, import_use_deprecated_props.useDeprecated36pxDefaultSizeProp)((0, import_context.useContextSystem)(props, "InputBase"));
  const id = useUniqueId(idProp);
  const hideLabel = hideLabelFromVision || !label;
  const prefixSuffixContextValue = (0, import_element.useMemo)(() => {
    return {
      InputControlPrefixWrapper: {
        __next40pxDefaultSize,
        size
      },
      InputControlSuffixWrapper: {
        __next40pxDefaultSize,
        size
      }
    };
  }, [__next40pxDefaultSize, size]);
  return (
    // @ts-expect-error The `direction` prop from Flex (FlexDirection) conflicts with legacy SVGAttributes `direction` (string) that come from React intrinsic prop definitions.
    /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_input_control_styles.Root, {
      ...restProps,
      ...getUIFlexProps(labelPosition),
      className,
      gap: 2,
      ref,
      children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_label.default, {
        className: "components-input-control__label",
        hideLabelFromVision,
        labelPosition,
        htmlFor: id,
        children: label
      }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_input_control_styles.Container, {
        __unstableInputWidth,
        className: "components-input-control__container",
        disabled,
        hideLabel,
        labelPosition,
        children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_context.ContextSystemProvider, {
          value: prefixSuffixContextValue,
          children: [prefix && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_input_control_styles.Prefix, {
            className: "components-input-control__prefix",
            children: prefix
          }), children, suffix && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_input_control_styles.Suffix, {
            className: "components-input-control__suffix",
            children: suffix
          })]
        }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_backdrop.default, {
          disabled,
          isBorderless
        })]
      })]
    })
  );
}
var input_base_default = (0, import_context.contextConnect)(InputBase, "InputBase");
//# sourceMappingURL=input-base.cjs.map
