// packages/block-editor/src/components/line-height-control/index.js
import { __ } from "@wordpress/i18n";
import { __experimentalNumberControl as NumberControl } from "@wordpress/components";
import deprecated from "@wordpress/deprecated";
import {
  BASE_DEFAULT_VALUE,
  RESET_VALUE,
  STEP,
  SPIN_FACTOR,
  isLineHeightDefined
} from "./utils";
import { jsx } from "react/jsx-runtime";
var LineHeightControl = ({
  /** Start opting into the larger default height that will become the default size in a future version. */
  __next40pxDefaultSize = false,
  value: lineHeight,
  onChange,
  __unstableInputWidth = "60px",
  ...otherProps
}) => {
  const isDefined = isLineHeightDefined(lineHeight);
  const adjustNextValue = (nextValue, wasTypedOrPasted) => {
    if (isDefined) {
      return nextValue;
    }
    const spin = STEP * SPIN_FACTOR;
    switch (`${nextValue}`) {
      case `${spin}`:
        return BASE_DEFAULT_VALUE + spin;
      case "0": {
        if (wasTypedOrPasted) {
          return nextValue;
        }
        return BASE_DEFAULT_VALUE - spin;
      }
      case "":
        return BASE_DEFAULT_VALUE;
      default:
        return nextValue;
    }
  };
  const stateReducer = (state, action) => {
    const wasTypedOrPasted = ["insertText", "insertFromPaste"].includes(
      action.payload.event.nativeEvent?.inputType
    );
    const value2 = adjustNextValue(state.value, wasTypedOrPasted);
    return { ...state, value: value2 };
  };
  const value = isDefined ? lineHeight : RESET_VALUE;
  const handleOnChange = (nextValue, { event }) => {
    if (nextValue === "") {
      onChange();
      return;
    }
    if (event.type === "click") {
      onChange(adjustNextValue(`${nextValue}`, false));
      return;
    }
    onChange(`${nextValue}`);
  };
  if (!__next40pxDefaultSize && (otherProps.size === void 0 || otherProps.size === "default")) {
    deprecated(`36px default size for wp.blockEditor.LineHeightControl`, {
      since: "6.8",
      version: "7.1",
      hint: "Set the `__next40pxDefaultSize` prop to true to start opting into the new default size, which will become the default in a future version."
    });
  }
  return /* @__PURE__ */ jsx("div", { className: "block-editor-line-height-control", children: /* @__PURE__ */ jsx(
    NumberControl,
    {
      ...otherProps,
      __shouldNotWarnDeprecated36pxSize: true,
      __next40pxDefaultSize,
      __unstableInputWidth,
      __unstableStateReducer: stateReducer,
      onChange: handleOnChange,
      label: __("Line height"),
      placeholder: BASE_DEFAULT_VALUE,
      step: STEP,
      spinFactor: SPIN_FACTOR,
      value,
      min: 0,
      spinControls: "custom"
    }
  ) });
};
var line_height_control_default = LineHeightControl;
export {
  line_height_control_default as default
};
//# sourceMappingURL=index.js.map
