import { addTo } from './addTo';
import { getGroup } from './getGroup';
import { getPrefab } from './getPrefab';
import { rsd } from './utils/randomSeed';
import { placeInCircle } from './utils/placeInCircle';
import { pop3 } from './utils/pop3';
import { getTiles } from '.';
/**
 * Returns as CircularTemple object.
 * This is procedurally circular temples
 * Change seed yo get another version
 * @example
 * ```ts
  const tmp = getCircularTemple({ p: [0, 0, 0], seed: 5 });
  addTo(scene, tmp);
 * ```
 */
export const getCircularTemple = (options = {}) => {
    options = {
        ...options,
    };
    const wrapper = getGroup(options);
    const ellipseXSize = options.ellipseXSize || 1;
    const ellipseZSize = options.ellipseZSize || 1;
    const radius = options.radius || 8;
    const floorRepeat = options.floorRepeat || 1;
    for (let index = 0; index < floorRepeat; index++) {
        const floorPart = getPrefab({ id: 'greek_floor_01' });
        const sk = 0.1;
        const floor = getTiles(floorPart, {
            dim: 4,
            reps: 5,
            p: [0, -1 - index * 2, 0],
            s: [1 * ellipseXSize + index * sk, 2, 1 * ellipseZSize + index * sk],
        });
        addTo(wrapper, floor);
    }
    const pillars = ['greek_pillar_01', 'greek_pillar_02', 'greek_gate_01'];
    const pillar = options.pillarKind ? options.pillarKind : rsd(options.seed).randomFromArray(pillars);
    const no = options.numberOfPillar ? options.numberOfPillar : Math.round(rsd(options.seed).range(4, 7));
    if (pillar === 'greek_gate_01') {
        const laps = Math.ceil(no * 0.5) + 1;
        const degToAdd = 360 / laps;
        for (let index = 0; index < laps; index++) {
            const prefab = getPrefab({
                id: pillar,
                r: [0, degToAdd * index, 0],
                s: [1.65, 1.3, 1.65],
            });
            addTo(wrapper, prefab);
        }
    }
    else {
        placeInCircle({
            radius: radius,
            numberOfItems: no,
            ellipseX: ellipseXSize,
            ellipseZ: ellipseZSize,
            onEach: (data) => {
                const prefab = getPrefab({
                    id: pillar,
                    p: data.p,
                    r: data.r,
                    s: pillar === 'greek_pillar_01' ? pop3(3) : pop3(2.5),
                });
                addTo(wrapper, prefab);
            },
        });
    }
    // Roof
    const doom1 = getGroup({
        children: [
            getPrefab({
                id: 'greek_dome_01',
                s: [1.6 * ellipseXSize, 1.6, 1.6 * ellipseZSize],
                p: [0, 10, 0],
            }),
        ],
    });
    const doom2 = getGroup({
        children: [
            getPrefab({ id: 'greek_dome_01', p: [0, 10, 0], s: [1.6 * ellipseXSize, 4, 1.6 * ellipseZSize] }),
        ],
    });
    const roof1 = getGroup({
        children: [
            getPrefab({ id: 'greek_roof_01', p: [0, 10, 0], s: [2.5 * ellipseXSize, 6, 2.5 * ellipseZSize] }),
        ],
    });
    const roof2 = getGroup({
        p: [0, 10, 0],
        s: [3 * ellipseXSize, 9, 3 * ellipseZSize],
        children: [
            getPrefab({ id: 'greek_roof_facde' }),
            getPrefab({ id: 'greek_roof_facde', r: [0, 180 * 0.25, 0] }),
            getPrefab({ id: 'greek_roof_facde', r: [0, 180 * 0.5, 0] }),
            getPrefab({ id: 'greek_roof_facde', r: [0, 180 * 0.75, 0] }),
        ],
    });
    const roofs = [doom1, doom2, roof1, roof2];
    const roof = options.roofTypeNumber !== undefined
        ? roofs[options.roofTypeNumber]
        : rsd(options.seed).randomFromArray(roofs);
    if (roof) {
        addTo(wrapper, roof);
    }
    return wrapper;
};
//# sourceMappingURL=getCircularTemple.js.map