function _instanceof(left, right) {
    if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
        return !!right[Symbol.hasInstance](left);
    } else {
        return left instanceof right;
    }
}
import raf from "rc-util/lib/raf";
import { easeInOutCubic } from "./easings";
import getScroll, { isWindow } from "./getScroll";
export default function scrollTo(y) {
    var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
    var _options_container = options.container, container = _options_container === void 0 ? typeof window !== 'undefined' ? window : undefined : _options_container, callback = options.callback, _options_duration = options.duration, duration = _options_duration === void 0 ? 450 : _options_duration;
    // Early return if running in Node.js environment without proper DOM setup
    if (typeof window === 'undefined') {
        if (typeof callback === 'function') {
            callback();
        }
        return;
    }
    // Early return if container is undefined
    if (!container) {
        if (typeof callback === 'function') {
            callback();
        }
        return;
    }
    var scrollTop = getScroll(container);
    var startTime = Date.now();
    var frameFunc = function frameFunc1() {
        // Check if we're still in a browser environment
        if (typeof window === 'undefined') {
            if (typeof callback === 'function') {
                callback();
            }
            return;
        }
        // Additional check for container (should not happen due to early return above)
        if (!container) {
            if (typeof callback === 'function') {
                callback();
            }
            return;
        }
        var timestamp = Date.now();
        var time = timestamp - startTime;
        var nextScrollTop = easeInOutCubic(time > duration ? duration : time, scrollTop, y, duration);
        if (isWindow(container)) {
            container.scrollTo(window.pageXOffset, nextScrollTop);
        } else if (_instanceof(container, Document) || container.constructor.name === 'HTMLDocument') {
            container.documentElement.scrollTop = nextScrollTop;
        } else {
            container.scrollTop = nextScrollTop;
        }
        if (time < duration) {
            raf(frameFunc);
        } else if (typeof callback === 'function') {
            callback();
        }
    };
    raf(frameFunc);
}
