"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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);
var MockTransition_exports = {};
__export(MockTransition_exports, {
  getTransitionCurrentValue: () => getTransitionCurrentValue,
  getTransitionRemainingDuration: () => getTransitionRemainingDuration,
  startTransition: () => startTransition,
  stopTransition: () => stopTransition
});
module.exports = __toCommonJS(MockTransition_exports);
var import_core = require("@zwave-js/core");
var import_shared = require("@zwave-js/shared");
function getTransitionCurrentValue(transition) {
  const elapsed = Date.now() - transition.startTime;
  const progress = Math.min(elapsed / transition.durationMs, 1);
  return Math.round(transition.startValue + (transition.targetValue - transition.startValue) * progress);
}
__name(getTransitionCurrentValue, "getTransitionCurrentValue");
function getTransitionRemainingDuration(transition) {
  const remaining = Math.max(0, transition.durationMs - (Date.now() - transition.startTime));
  return new import_core.Duration(Math.ceil(remaining / 1e3), "seconds");
}
__name(getTransitionRemainingDuration, "getTransitionRemainingDuration");
function stopTransition(transition) {
  transition.timer.clear();
  const value = getTransitionCurrentValue(transition);
  void transition.onAbort?.();
  return value;
}
__name(stopTransition, "stopTransition");
function startTransition(options) {
  const { currentValue, targetValue, duration, supervised, onComplete, onAbort } = options;
  if (currentValue === targetValue || duration === 0) {
    return void 0;
  }
  const durationMs = Math.round(duration * (Math.abs(targetValue - currentValue) / 99));
  return {
    startValue: currentValue,
    targetValue,
    startTime: Date.now(),
    durationMs,
    supervised,
    onAbort,
    timer: (0, import_shared.setTimer)(onComplete, durationMs).unref()
  };
}
__name(startTransition, "startTransition");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getTransitionCurrentValue,
  getTransitionRemainingDuration,
  startTransition,
  stopTransition
});
//# sourceMappingURL=MockTransition.js.map
