import { isMeasurable, measure } from "../../state/modules/box-models";
import {
  isPropControllersHandle
} from "../../state/modules/prop-controller-handles";
class ElementImperativeHandle {
  getCurrent = () => null;
  lastPropControllers = null;
  callback(getCurrent) {
    const current = this.getCurrent();
    if (current === null)
      this.setPropControllers(null);
    this.getCurrent = getCurrent;
    if (this.lastPropControllers !== null)
      this.setPropControllers(this.lastPropControllers);
  }
  getBoxModel() {
    const current = this.getCurrent();
    return isMeasurable(current) ? measure(current) : null;
  }
  setPropControllers(propControllers) {
    const current = this.getCurrent();
    if (isPropControllersHandle(current))
      current.setPropControllers(propControllers);
    this.lastPropControllers = propControllers;
  }
  getDomNode() {
    const current = this.getCurrent();
    if (isDomNodeHandle(current))
      return current.getDomNode();
    return current instanceof Element ? current : null;
  }
}
function isDomNodeHandle(value) {
  if (typeof value === "object" && value !== null && "getDomNode" in value && typeof value.getDomNode === "function") {
    return true;
  }
  return false;
}
export {
  ElementImperativeHandle,
  isDomNodeHandle
};
//# sourceMappingURL=element-imperative-handle.js.map