import { addTo } from './addTo';
import { getGroup } from './getGroup';
import { getPrefab } from './getPrefab';
import { rsd, pop3, placeInCircle } from './utils';
/**
 * Returns as ArchRoom object.
 * @example
 * ```ts
  addTo(
    root,
    getArchRoom({
      p: [35, 2, -4.5],
      r: [0, 10, 0],
      decoFreq: 0.25,
      archRoomType: "MIXED",
      floors: 2,
    });
  );
 * ```
 */
export const getArchRoom = (options = {}) => {
    const { dim = 15, material = 't_plaster_01', archRoomType = 'MIXED', floors = 1, decoFreq = 0, bottomFloorDefinition = undefined, } = options;
    const wrapper = getGroup(options);
    const base = getPrefab({
        id: 'rounded_cylinder_01',
        s: [dim, 2, dim],
        material: material,
    });
    addTo(wrapper, base);
    const archWrapper = getGroup({ p: [0, 3.8, 0] });
    addTo(wrapper, archWrapper);
    const archTypes = {
        SOFT: {
            id: 'en_m_primitive_soft_arch_01',
            radius: 12,
            numberOfItems: 12,
            scale: 2.2,
            height: 6.0,
            material: 't_plaster_01',
        },
        CIRCULAR: {
            id: 'en_m_primitive_wall_02',
            radius: 9,
            numberOfItems: 10,
            scale: 1.8,
            height: 7,
            material: 't_plaster_01',
        },
        SQUARED: {
            id: 'en_m_primitive_wall_03',
            radius: 9,
            numberOfItems: 10,
            scale: 1.8,
            height: 7,
            material: 't_plaster_01',
        },
        LOW: {
            id: 'en_m_primitive_arch_01',
            radius: 9,
            numberOfItems: 10,
            scale: 2.15,
            height: 8.5,
            material: 't_plaster_01',
        },
        HIGH: {
            id: 'en_m_primitive_arch_02',
            radius: 9,
            numberOfItems: 10,
            scale: 2.15,
            height: 12,
            material: 't_plaster_01',
        },
        MIXED: {
            id: undefined,
            radius: 9,
            numberOfItems: 10,
            scale: 1.8,
            height: 7,
            material: 't_plaster_01',
        },
    };
    // en_m_primitive_wall_02
    // en_m_primitive_wall_03
    const addDeco = (arch, archRoomType) => {
        if (decoFreq < rsd(options.seed).getValue())
            return;
        const archType = archTypes[archRoomType];
        // console.log(archType.radius);
        const p = [0, 1.2, 0];
        let s = pop3(0.33);
        if (archRoomType === 'MIXED' || archRoomType === 'CIRCULAR') {
            p[1] = 0.35;
            p[2] = -1.5;
            s = pop3(0.5);
        }
        else if (archRoomType === 'LOW') {
            p[1] = 0;
            p[2] = -1.5;
            s = pop3(0.5);
        }
        else if (archRoomType === 'HIGH') {
            p[1] = 2.4;
            p[2] = -1.5;
            s = pop3(0.5);
        }
        addTo(arch, getPrefab({
            id: 'sphere_01',
            s,
            p,
            material: 't_plaster_01_blue',
        }));
    };
    const archType = archTypes[archRoomType];
    placeInCircle({
        radius: archType.radius,
        numberOfItems: archType.numberOfItems,
        itemOffset: 90,
        onEach: (data) => {
            if (archType.id) {
                for (let i = 0; i < floors; i++) {
                    const arch = getPrefab({
                        id: archType.id,
                        p: [data.p[0], data.p[1] + i * archType.height, data.p[2]],
                        r: data.r,
                        s: pop3(archType.scale),
                        material: material,
                    });
                    if (i > 0) {
                        addDeco(arch, archRoomType);
                    }
                    addTo(archWrapper, arch);
                }
            }
            else {
                // MIXED
                const useHighArch = rsd(options.seed).getValue() < 0.6 ? true : false;
                const sectionWrapper = getGroup({ p: data.p, r: data.r });
                if (useHighArch) {
                    addTo(sectionWrapper, getPrefab({
                        id: 'en_m_primitive_arch_02',
                        s: pop3(archType.scale),
                        material: material,
                    }));
                }
                else {
                    const useArchAsBase = rsd(options.seed).getValue() < 0.7 ? true : false;
                    if (useArchAsBase) {
                        addTo(sectionWrapper, getPrefab({
                            id: 'en_m_primitive_arch_01',
                            s: pop3(archType.scale),
                            material: material,
                        }));
                        const arch = getPrefab({
                            id: 'en_m_primitive_wall_02',
                            s: pop3(archType.scale),
                            p: [0, 7.2, 0],
                            material: material,
                        });
                        addTo(sectionWrapper, arch);
                        addDeco(arch, archRoomType);
                    }
                    else {
                        addTo(sectionWrapper, getPrefab({
                            id: 'en_m_primitive_wall_01',
                            s: pop3(archType.scale),
                            material: material,
                        }));
                        const arch = getPrefab({
                            id: 'en_m_primitive_wall_02',
                            s: pop3(archType.scale),
                            p: [0, 7.2, 0],
                            material: material,
                        });
                        addDeco(arch, archRoomType);
                        addTo(sectionWrapper, arch);
                    }
                }
                for (let i = 2; i < floors; i++) {
                    const arch = getPrefab({
                        id: 'en_m_primitive_wall_02',
                        s: pop3(archType.scale),
                        p: [0, i * 7, 0],
                        material: material,
                    });
                    addDeco(arch, archRoomType);
                    addTo(sectionWrapper, arch);
                }
                addTo(archWrapper, sectionWrapper);
            }
        },
    });
    return wrapper;
};
//# sourceMappingURL=getArchRoom.js.map