import { getGroup } from './getGroup';
import { getPrefab } from './getPrefab';
import { addTo } from './addTo';
import { getMoving } from './getMoving';
import { getSpinning } from './getSpinning';
import { textures } from '@hiberworld/code-kit';
/**
 * Returns a water plane.
 * @example
 * ```
 * const wp = getWaterPlane();
 * addTo(root, wp);
 * ```
 */
export const getWaterPlane = (opt = {}) => {
    const val = {
        p: [0, 0, 0],
        s: [1, 1, 1],
        r: [0, 0, 0],
        animate: textures,
        children: [],
        width: 50,
        repeatX: 20,
        repeatZ: 20,
        ...opt,
    };
    let wrapper = getGroup({ p: val.p, s: val.s, r: val.r });
    const scale = 1;
    const yPos = -2;
    const width = val.width;
    const depth = width;
    const offsetX = width * (val.repeatX - 1) * 0.5;
    const offsetZ = depth * (val.repeatZ - 1) * 0.5;
    const waterScale = (6.25 * val.width) / 50;
    const waterY = yPos + 0.1;
    for (let indexX = 0; indexX < val.repeatX; indexX++) {
        for (let indexZ = 0; indexZ < val.repeatZ; indexZ++) {
            const water = getPrefab({
                id: 'water_plane_01',
                p: [indexX * width - offsetX, waterY, indexZ * depth - offsetZ],
                s: [waterScale, scale, waterScale],
            });
            addTo(wrapper, water);
        }
    }
    if (val.animate) {
        wrapper = getMoving(wrapper, { to: [0, 0.1, 0], duration: 8 });
        wrapper = getSpinning(wrapper, { duration: 400 });
    }
    return wrapper;
};
//# sourceMappingURL=getWaterPlane.js.map