import { getMoving, getTween, rsd } from '.';
import { getWrapper } from './getWrapper';
import { getOffset } from './getOffset';
/**
 * Adds a hovering-like animation to an object.
 * @example
 * ```ts
    addTo(root, getHovering(getPrefab({ id: 'large_rock_01_t1' }), { p: [0, 2, 5] }));
 * ```
 */
let durationK = 1;
const spin = (target, r, duration) => {
    const kf = [
        { ts: 0, r },
        { ts: 1, r: [r[0] * -1, r[1] * -1, r[2] * -1] },
    ];
    target = getTween(target, kf, {
        loopBehaviour: 'REVERSE',
        duration: (duration * durationK),
        progress: rsd().getValue(),
    });
    return target;
};
export const getHovering = (target, options = {}) => {
    const { speedMultiplier = 1, magnitude = 1, bigWiggle = true, bigWiggleDuration = 128, offset = [0, -1, 0], seed = undefined, } = options;
    durationK = 1 / speedMultiplier;
    target = getOffset(target, { offset });
    target = getMoving(target, {
        to: [0, rsd(options.seed).range(-0.5, 0.5) * magnitude, 0],
        duration: (4 * durationK),
        progress: rsd(options.seed).getValue(),
    });
    target = spin(target, [rsd(options.seed).range(-5, 5) * magnitude, 0, rsd(options.seed).range(-1, 1) * magnitude], 4);
    target = spin(target, [rsd(options.seed).range(-1, 1) * magnitude, 0, rsd(options.seed).range(-5, 5) * magnitude], 6);
    if (bigWiggle) {
        target = spin(target, [0, rsd(seed).randomFromArray([-100, -50, 50, 100]) * magnitude, 0], (bigWiggleDuration * durationK));
    }
    const wrapper = getWrapper(target, { ...options, autoWrap: true });
    return wrapper;
};
//# sourceMappingURL=getHovering.js.map