"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/block-editor/src/components/image-size-control/use-dimension-handler.js
var use_dimension_handler_exports = {};
__export(use_dimension_handler_exports, {
  default: () => useDimensionHandler
});
module.exports = __toCommonJS(use_dimension_handler_exports);
var import_element = require("@wordpress/element");
function useDimensionHandler(customHeight, customWidth, defaultHeight, defaultWidth, onChange) {
  const [currentWidth, setCurrentWidth] = (0, import_element.useState)(
    customWidth ?? defaultWidth ?? ""
  );
  const [currentHeight, setCurrentHeight] = (0, import_element.useState)(
    customHeight ?? defaultHeight ?? ""
  );
  (0, import_element.useEffect)(() => {
    if (customWidth === void 0 && defaultWidth !== void 0) {
      setCurrentWidth(defaultWidth);
    }
    if (customHeight === void 0 && defaultHeight !== void 0) {
      setCurrentHeight(defaultHeight);
    }
  }, [defaultWidth, defaultHeight]);
  (0, import_element.useEffect)(() => {
    if (customWidth !== void 0 && Number.parseInt(customWidth) !== Number.parseInt(currentWidth)) {
      setCurrentWidth(customWidth);
    }
    if (customHeight !== void 0 && Number.parseInt(customHeight) !== Number.parseInt(currentHeight)) {
      setCurrentHeight(customHeight);
    }
  }, [customWidth, customHeight]);
  const updateDimension = (dimension, value) => {
    const parsedValue = value === "" ? void 0 : parseInt(value, 10);
    if (dimension === "width") {
      setCurrentWidth(parsedValue);
    } else {
      setCurrentHeight(parsedValue);
    }
    onChange({
      [dimension]: parsedValue
    });
  };
  const updateDimensions = (nextHeight, nextWidth) => {
    setCurrentHeight(nextHeight ?? defaultHeight);
    setCurrentWidth(nextWidth ?? defaultWidth);
    onChange({ height: nextHeight, width: nextWidth });
  };
  return {
    currentHeight,
    currentWidth,
    updateDimension,
    updateDimensions
  };
}
//# sourceMappingURL=use-dimension-handler.js.map
