import { animations } from '@hiberworld/code-kit';
import { addTo, getGroup, getPrefab, getExternalAvatar, getStack, pop3, getVideoPlayer, distributeHorizontally, EXTERNAL_AVATARS, } from '.';
import { getWrapper } from './getWrapper';
/**
 * A customizable helper for creating a Dj Booth.
 * @example
 * ```ts
  let dj = getDjBooth({ p: [0, 0, 10] });
  addTo(world, dj);
 * ```
 */
export const getDjBooth = (opt = {}) => {
    const djAvatar = EXTERNAL_AVATARS.DJ;
    const val = {
        height: 2,
        width: 7,
        podiumMaterial: 't_metal_01',
        podiumDecoration: true,
        boothMaterial: undefined,
        rigMaterial: undefined,
        rigDecoration: true,
        speakers: true,
        video: true,
        videoUrl: 'https://cdn.hibervr.com/video/dj.mp4',
        dj: true,
        djAvatar,
        djScale: 1.5,
        p: [0, 0, 0],
        r: [0, 0, 0],
        s: [1, 1, 1],
        ...opt,
    };
    const wrapper = getWrapper(val);
    const podium = getPrefab({
        id: 'rounded_cube_02',
        p: [0, 0, 0],
        s: [3, val.height * 0.5, 3],
        material: val.podiumMaterial,
    });
    addTo(wrapper, podium);
    const podiumBase = getPrefab({
        id: 'rounded_cube_02',
        p: [0, val.height * -0.25, 0],
        s: [3.3, val.height * 0.2, 3.3],
        material: val.podiumMaterial,
    });
    addTo(wrapper, podiumBase);
    const tron_p1_blue = getPrefab({
        id: 'tron_p1_blue',
        p: [0, val.height, -2.25],
        r: [90, 0, 0],
        s: [0.75, 0.75, 0.65],
        material: val.boothMaterial,
    });
    addTo(wrapper, tron_p1_blue);
    if (val.podiumDecoration) {
        const decoWrapper = getGroup();
        addTo(tron_p1_blue, decoWrapper);
        for (let index = 0; index < 8; index++) {
            addTo(decoWrapper, getPrefab({ id: 'tron_q1_blue', p: [index, -1.05, 0.75], r: [90, 0, 0], s: [1, 0.6, 1] }));
        }
        if (decoWrapper.children)
            distributeHorizontally(decoWrapper.children, 3.2);
    }
    if (val.dj && val.djAvatar) {
        const rpmAvatar = getExternalAvatar({
            avatar: djAvatar,
            p: [0, val.height - (val.djScale - 1) * 0.5, -1 + (val.djScale - 1)],
            r: [0, 180, 0],
            s: val.djScale,
            speed: 1.2,
            emot: animations.an_default_emote_listening_to_music_01,
        });
        addTo(wrapper, rpmAvatar);
    }
    const en_p_dj_pioneer_01 = getPrefab({
        id: 'en_p_dj_pioneer_01',
        p: [0, val.height + 0.65, -2],
        s: pop3(val.djScale),
    });
    addTo(wrapper, en_p_dj_pioneer_01);
    const sCube = getPrefab({ id: 'scaffoldingcube_01', material: val.rigMaterial });
    const stacksOnTRop = Math.round(val.height * 0.5) + 4;
    const rig = getStack(sCube, {
        p: [val.width, 0, 1],
        repeats: [
            {
                repeats: stacksOnTRop,
                direction: 'UP',
            },
            {
                repeats: val.width,
                direction: 'RIGHT',
            },
            {
                repeats: stacksOnTRop,
                direction: 'DOWN',
            },
        ],
    });
    addTo(wrapper, rig);
    if (val.rigDecoration && rig.children) {
        for (let index = 0; index < rig.children.length; index++) {
            const child = rig.children[index];
            addTo(child, getPrefab({ id: 'tron_q1_blue', p: [0, 0, -1], r: [0, 0, 0], s: [1, 0.5, 1] }));
        }
    }
    let numberOfSpeakers = Math.ceil(val.height * 0.4);
    if (val.speakers) {
        numberOfSpeakers = numberOfSpeakers <= 1 ? 2 : numberOfSpeakers;
        let speakerYOffset = 2;
        if (numberOfSpeakers % 2 === 0 && numberOfSpeakers < 5) {
            speakerYOffset = 3;
        }
        for (let index = 0; index < numberOfSpeakers; index++) {
            const progress = index / numberOfSpeakers;
            // const progressiveScaleK = 1 * progress + 1;
            addTo(wrapper, getPrefab({
                id: 'en_p_speaker_02',
                p: [val.width, index * 4.3 + speakerYOffset, -1],
                s: pop3(10),
                r: [10, 180, 0],
            }));
            addTo(wrapper, getPrefab({
                id: 'en_p_speaker_02',
                p: [val.width * -1, index * 4.3 + speakerYOffset, -1],
                s: pop3(10),
                r: [10, 180, 0],
            }));
        }
    }
    if (val.video) {
        let videoYOffset = val.width * 0.17;
        if (numberOfSpeakers < 3) {
            videoYOffset *= 1.5;
        }
        addTo(wrapper, getVideoPlayer({
            src: val.videoUrl,
            p: [0, val.height + videoYOffset, 1.9 + val.djScale - 1],
            width: val.width * 0.7,
        }));
    }
    return wrapper;
};
//# sourceMappingURL=getDjBooth.js.map