import { getGroup } from './getGroup';
/**
 * Returns a wrapper for the target node.
 * @example
 * ```ts
  const spr = getPrefab({ id: 'sphere_01', p: [0, 1, 10] });
  const wrapper = getWrapper(spr);
  addTo(world, wrapper);
 * ```
 **/
export const getWrapper = (input, options = {}) => {
    if (!('transform' in input)) {
        const wrapper = getGroup(input);
        return wrapper;
    }
    else {
        const target = input;
        let { autoWrap = true, p = undefined, r = undefined, s = undefined, offset = [0, 0, 0] } = options;
        // If p, r, or s is defined use it, otherwise check if the target has a transform and use that, otherwise use [0, 0, 0] or [1, 1, 1].
        if (!p)
            p = target.transform && target.transform.pos ? target.transform.pos : [0, 0, 0];
        if (!r)
            r = target.transform && target.transform.rot ? target.transform.rot : [0, 0, 0];
        if (!s)
            s = target.transform && target.transform.scale ? target.transform.scale : [1, 1, 1];
        let wrapper;
        // If autoWrap is true, wrap the target in a group and reset the transform of the target.
        if (autoWrap) {
            wrapper = getGroup({ children: [target], p, r: r, s });
            // Reset the transform of the target
            if (!target.transform)
                target.transform = {};
            target.transform.pos = offset;
            target.transform.rot = [0, 0, 0];
            target.transform.scale = [1, 1, 1];
        }
        else {
            // If autoWrap is false, just wrap the target in a group.
            wrapper = getGroup({ children: [target] });
        }
        return wrapper;
    }
};
//# sourceMappingURL=getWrapper.js.map