'use strict';

var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var index = require('../packages/ui/dist/index.js');
var AnimatedPerson = require('./AnimatedPerson.js');
var characterTypes = require('./characterTypes.js');
var choreoDSL = require('./choreoDSL.js');

const rnd = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padStart(6, "0")}`;
function recolor(f, n) {
    const colors = new Array(Math.max(1, Math.min(3, n))).fill(0).map(rnd);
    return { ...f, colors };
}
function makeAudience(n) {
    const arr = [];
    for (let i = 0; i < n; i++) {
        arr.push({
            ...characterTypes.DEFAULT_CHARACTER,
            name: `Fan ${i + 1}`,
            size: 150 + Math.round(Math.random() * 40) - 20,
            outfit: recolor(characterTypes.DEFAULT_CHARACTER.outfit, 3),
            hair: recolor(characterTypes.DEFAULT_CHARACTER.hair, 2),
            headwear: Math.random() < 0.3
                ? recolor(characterTypes.DEFAULT_CHARACTER.headwear, 2)
                : { variant: "none", colors: ["var(--anim-stroke, #111)"] },
            prop: Math.random() < 0.25
                ? { variant: "star", colors: [rnd(), rnd(), "var(--anim-stroke, #111)"] }
                : { variant: "none", colors: ["var(--anim-stroke, #111)"] },
        });
    }
    return arr;
}
/** Grid of animated audience members with wave/cheer actions. */
const NiceAudience = ({ count = 36, columns = 12 }) => {
    const people = React.useMemo(() => makeAudience(count), [count]);
    const refs = React.useRef([]);
    refs.current = [];
    const actors = () => refs.current.filter(Boolean);
    const cheer = async () => {
        const a = actors();
        if (!a.length)
            return;
        await choreoDSL.runRounds(a, [choreoDSL.seq().jump(250).celebrate(500), choreoDSL.seq().waveHand(600), choreoDSL.seq().danceB(450)], 60);
    };
    const wave = async () => {
        const a = actors();
        if (!a.length)
            return;
        await Promise.all(new Array(Math.ceil(a.length / columns)).fill(0).map((_, row) => choreoDSL.runRounds(a.slice(row * columns, row * columns + columns), [choreoDSL.seq().waveHand(500)], 120 * row)));
    };
    return (jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 8 }, children: [jsxRuntime.jsx("div", { style: {
                    display: "grid",
                    gap: 8,
                    gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`,
                }, children: people.map((c, i) => (jsxRuntime.jsx(AnimatedPerson, { character: c, score: 10, startPose: "idle", onReady: (fx) => (refs.current[i] = fx) }, i))) }), jsxRuntime.jsxs("div", { style: { display: "flex", gap: 8 }, children: [jsxRuntime.jsx(index.NiceButton, { variant: "ghost", size: "sm", onClick: wave, children: "Wave" }), jsxRuntime.jsx(index.NiceButton, { variant: "ghost", size: "sm", onClick: cheer, children: "Cheer" })] })] }));
};

module.exports = NiceAudience;
//# sourceMappingURL=Audience.js.map
