import { addTo } from './addTo';
import { getGroup } from './getGroup';
import { getPrefab } from './getPrefab';
import { placeInCircle } from './utils/placeInCircle';
import { rsd } from './utils/randomSeed';
import { getGround } from './getGround';
import { getWrapper } from './getWrapper';
/**
 * Returns a islands
 * @example
 * ```ts
  // Basic
  addTo(world, getIsland({ p: [10, 0, 0] }));

  // Archipelago
  const container = getGroup({ p: [0, -10, 0] });
  addTo(world, container);

  addTo(container, getIsland({ p: [10, 0, 0] }));
  addTo(container, getIsland({ p: [-150, 0, 0], heightValue: 1.5 }));

  //Add the sand ground
  addTo(
    container,
    getGround({
      p: [0, 0, 0],
      hilly: 0,
      material: 't_sand_01',
      repeatX: 10,
      repeatZ: 10,
    })
  );

  // // Add the water plane
  addTo(
    container,
    getWaterPlane({
      p: [0, 0, 0],
    })
  );

 * ```
 */
export const getIsland = (options = {}) => {
    const { widthValue = 1, heightValue = 1, seed = undefined, rockMaterial = undefined, sandMaterial = undefined, beach = true, numberOfRockFormations = rsd(options.seed).randomFromArray([2, 3, 4, 5]), } = options;
    const wrapper = getWrapper(options);
    const bedRock = getGroup({ p: [0, -2, 0], r: [0, rsd(options.seed).range(0, 360), 0] });
    addTo(wrapper, bedRock);
    const peak = getPrefab({
        id: 'mountain_01',
        material: rockMaterial,
        p: [0, -1, 0],
        r: [0, rsd(seed).range(-90, 90), 0],
        s: [0.8 * widthValue, rsd(seed).range(0.15, 0.3) * heightValue, 0.8 * widthValue],
    });
    addTo(bedRock, peak);
    placeInCircle({
        radius: 20 * widthValue,
        numberOfItems: numberOfRockFormations,
        onEach: (data) => {
            addTo(bedRock, getPrefab({
                id: 'mountain_01',
                material: rockMaterial,
                p: [data.p[0] + rsd(seed).range(-2, 5), data.p[1], data.p[2] + rsd(seed).range(-5, 10)],
                r: [data.r[0], data.r[1] + rsd(seed).range(-90, 90), data.r[2]],
                s: [1 * widthValue, rsd(seed).range(0.1, 0.2) * heightValue, 1 * widthValue],
            }));
        },
    });
    // addTo(
    //   bedRock,
    //   getScape({ ...SCAPE_PRESETS.sparseDist, ...{ prefabId: 'rock_01_t3' as PrefabId, itemScale: pop3(0.5) } })
    // );
    // Add the beach around the island
    const beachWidthValue = widthValue > 0.3 ? widthValue : 0.3;
    if (beach) {
        addTo(wrapper, getGround({
            p: [0, 1, 0],
            r: [0, rsd(seed).randomFromArray([0, 180]), 0],
            hilly: 0.6,
            material: sandMaterial ? sandMaterial : 't_sand_01',
            repeatX: 2,
            repeatZ: 2,
            s: [1.5 * beachWidthValue, rsd(seed).range(0.8, 1.2), 1.5 * beachWidthValue],
        }));
    }
    return wrapper;
};
//# sourceMappingURL=getIsland.js.map